Skip to content

Instantly share code, notes, and snippets.

@julsfelic
Created December 1, 2015 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julsfelic/bd7b711d56a79e2b584e to your computer and use it in GitHub Desktop.
Save julsfelic/bd7b711d56a79e2b584e to your computer and use it in GitHub Desktop.
# Clearest way possible
0.upto(1000) do |n|
if n.zero?
puts n
elsif (n % 3 == 0) && (n % 5 == 0) && (n % 7 == 0)
puts "SuperFizzBuzz"
elsif (n % 3 == 0) && (n % 7 == 0)
puts "SuperFizz"
elsif (n % 5 == 0) && (n % 7 == 0)
puts "SuperBuzz"
elsif (n % 3 == 0)
puts "Fizz"
elsif (n % 5 == 0)
puts "Buzz"
elsif (n % 7 == 0)
puts "Super"
else
puts n
end
end
# Fewest instructions / lines possible
0.upto(1000) do |n|
next puts n if n.zero?
next puts "SuperFizzBuzz" if n % 3 == 0 && n % 5 == 0 && n % 7 == 0
next puts "SuperFizz" if n % 3 == 0 && n % 7 == 0
next puts "SuperBuzz" if n % 5 == 0 && n % 7 == 0
next puts "Fizz" if n % 3 == 0
next puts "Buzz" if n % 5 == 0
next puts "Super" if n % 7 == 0
puts n
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment