Ruby: Grid Computing Golf
My first attempt at really playing code golf, that is solving a problem in minimum characters of code and I did not do very well (200 character compared to the best 43 perl or 63 ruby characters).
http://codegolf.com/grid-computing
m = []
r = []
c = Array.new(10, 0)
0.upto(9) {|n|m<<gets.chomp.split.map {|x|x.to_i};r<<m[n].inject(0){|s,e| s += e}}
0.upto(9) {|x|m.each_with_index{|v,z|c[x] += v[x]}}
puts [r.max, c.max].max
Update:
I further squeezed some white-space out of the code and it is starting to look uglier (now it is 184 characters). I am not sure I like the code golf concept although I like to solve coding problems.
m=[]
r=[]
c=Array.new(10,0)
0.upto(9){|n|m<<gets.chomp.split.map{|x|x.to_i};r<<m[n].inject(0){|s,e|s+=e}}
0.upto(9){|x|m.each_with_index{|v,z|c[x]+=v[x]}}
puts [r.max,c.max].max
[...] Posted in 1 by Arsalan on January 8th, 2008 This is a variation to the problem/solution posted on Ali Abbas Rizvi’s blog. I wanted to allow the user to enter matrix size for each run and to get a view of a randomly [...]
Adding rows and columns in a nXn matrix (C# Solution) « Arsalan’s Musings
January 8, 2008 at 7:36 am
Looks to me like you’ve done a good job with that code. But what do I know? I’m a coding newbie!
Ashworth Callaway
January 30, 2008 at 4:59 am