(02-20-2010, 10:39 PM)uber1337 Wrote: You can multiply using "*" in Ruby
Good, thank you for pointing that out.
(02-23-2010, 03:16 AM)Wolskie Wrote: We can do it like that too, by packing everything together.Oh yeah I forgot that ruby was the optimal language for ugly one liners forgot who I was messing with . As someone over at HF put it:
Code:x=0;(0..1000).each{|f|(f%3==0||f%5==0)?x+=f : nil}
or we could do this:
Code:#!/usr/bin/env ruby
def calculate()
tmp = 0
(0..1000).each do |number|
if (number % 3 == 0 || number % 5 == 0) then
tmp += number
end
end
puts number
end
calculate()
Python is SO readable. A lot of Rubyists are obsessed with the 'Ruby Way', which usually consists of single-line, multi-layered functional code, making it unmaintainable.
Don't get me wrong I love one liners, but
Code:
x=0;(0..1000).each{|f|(f%3==0||f%5==0)?x+=f : nil}
Looks very hard to digest.