Skip to content

Instantly share code, notes, and snippets.

@andersr
Last active August 29, 2015 14:27
Show Gist options
  • Save andersr/026dfe24ead36d81cc9b to your computer and use it in GitHub Desktop.
Save andersr/026dfe24ead36d81cc9b to your computer and use it in GitHub Desktop.
A program that prints out the numbers 1 to 100 (inclusive). If the number is divisible by 3, print Crackle instead of the number. If it's divisible by 5, print Pop. If it's divisible by both 3 and 5, print CracklePop.
(1..100).each do |number|
if (number % 3 == 0) && (number % 5 == 0)
puts "CracklePop"
elsif number % 3 == 0
puts "Crackle"
elsif number % 5 == 0
puts "Pop"
else
puts number
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment