R
Ryan Leavengood
My first, obvious solution:
(1..100).each do |i|
if (i % 3 == 0) and (i % 5 == 0)
puts "FizzBuzz"
elsif (i % 3 == 0)
puts "Fizz"
elsif (i % 5 == 0)
puts "Buzz"
else
puts i
end
end
Trying to reduce the redundant ifs:
(1..100).each do |i|
s = ''
s << "Fizz" if (i % 3 == 0)
s << "Buzz" if (i % 5 == 0)
puts(s == '' ? i : s)
end
The above seems unique among the solutions I've read so far.
Ryan
(1..100).each do |i|
if (i % 3 == 0) and (i % 5 == 0)
puts "FizzBuzz"
elsif (i % 3 == 0)
puts "Fizz"
elsif (i % 5 == 0)
puts "Buzz"
else
puts i
end
end
Trying to reduce the redundant ifs:
(1..100).each do |i|
s = ''
s << "Fizz" if (i % 3 == 0)
s << "Buzz" if (i % 5 == 0)
puts(s == '' ? i : s)
end
The above seems unique among the solutions I've read so far.
Ryan