P
Prasanth Ravi
hi i'm a newbie in ruby and was test out some interesting problems in
ruby,
i came across a small one to print the sum of positive numbers from a
list of n numbers... with the shortest code possible..
well the best i could do was,
puts gets.split(' ').inject(0){|sum,x| x.to_i>0?sum+x.to_i : sum}
is there a shorter version?
ruby,
i came across a small one to print the sum of positive numbers from a
list of n numbers... with the shortest code possible..
well the best i could do was,
puts gets.split(' ').inject(0){|sum,x| x.to_i>0?sum+x.to_i : sum}
is there a shorter version?