Skip to content

Instantly share code, notes, and snippets.

@gjones
Last active January 9, 2017 17:23
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 gjones/186066df8d25da35642b1a2018fa62cc to your computer and use it in GitHub Desktop.
Save gjones/186066df8d25da35642b1a2018fa62cc to your computer and use it in GitHub Desktop.
Attempt at FizzBuzz solution in Ruby
# Write a program that prints the numbers from 1 to 100.
# For multiples of three print "Fizz" instead of the number
# For multiples of five print "Buzz". For numbers which
# For multiples of both three and five print "FizzBuzz".
1.step(100,1) do |input|
if (input % 5) == 0 && (input % 3) == 0
puts 'FizzBuzz'
elsif (input % 5) == 0
puts 'Buzz'
elsif (input % 3) == 0
puts 'Fizz'
else
puts input
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment