Created
August 6, 2018 19:41
-
-
Save Zorgatone/a8f9c57d0c9645371355e4ff4f0727ed to your computer and use it in GitHub Desktop.
fizzbuzz.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fizzbuzz(n) | |
1.upto(n) do |i| | |
div_by_5 = i % 5 == 0 | |
div_by_3 = i % 3 == 0 | |
if div_by_3 && div_by_5 | |
puts "#{i} Fizzbuzz" | |
elsif div_by_3 | |
puts "#{i} Fizz" | |
elsif div_by_5 | |
puts "#{i} Buzz" | |
else | |
puts i | |
end | |
end | |
end | |
fizzbuzz(16) # run it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment