Skip to content

Instantly share code, notes, and snippets.

@haman29
Created December 16, 2012 07:27
Show Gist options
  • Save haman29/4304009 to your computer and use it in GitHub Desktop.
Save haman29/4304009 to your computer and use it in GitHub Desktop.
puts 'case1'
for n in [*1..50]
if n % (3 * 5) == 0
print 'fizzbuzz '
elsif n % 3 == 0
print 'fizz '
elsif n % 5 == 0
print 'buzz '
else
print "#{n} "
end
end
puts
puts 'case2'
50.times { |n|
n += 1
if n % (3 * 5) == 0
print 'fizzbuzz '
elsif n % 3 == 0
print 'fizz '
elsif n % 5 == 0
print 'buzz '
else
print "#{n} "
end
}
puts
puts 'case 3'
puts [*1..50].map {|n|
if n % (3 * 5) == 0
'fizzbuzz'
elsif n % 3 == 0
'fizz'
elsif n % 5 == 0
'buzz'
else
n
end
}.join(' ')
puts 'case 4'
puts [*1..50].map {|n|
n % (3 * 5) == 0 ? 'fizzbuzz' : n % 3 == 0 ? "fizz" : n % 5 == 0 ? 'buzz' : n
}.join(' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment