Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created January 12, 2013 04:24
Show Gist options
  • Save kmandreza/4516081 to your computer and use it in GitHub Desktop.
Save kmandreza/4516081 to your computer and use it in GitHub Desktop.
Write a method called fizzblam that prints the numbers from 1 to 1000. But for multiples of 5 print “Fizz” instead of the number and for the multiples of 7 print “Blam”. For numbers which are multiples of both 5 and 7 print “FizzBlam.”
def fizzblam
1000.times do |n|
if (n+1) %7 == 0 && (n+1) %5 == 0
puts "FizzBlam"
elsif (n+1) %5 == 0
puts "Fizz"
elsif (n+1) %7 == 0
puts "Blam"
else
puts n + 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment