Last active
December 23, 2015 23:19
-
-
Save andersr/6708795 to your computer and use it in GitHub Desktop.
FizzBuzz
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
| fizz, buzz, fizz_buzz, no_buzz = [], [], [], [] | |
| (1..50).each do |n| | |
| if (n % 3 == 0) && (n % 5 == 0) | |
| fizz_buzz.push(n) | |
| elsif n % 3 == 0 | |
| fizz.push(n) | |
| elsif n % 5 == 0 | |
| buzz.push(n) | |
| else | |
| no_buzz.push(n) | |
| end | |
| end | |
| def puts_buzzes(name,number) | |
| print "#{name}:" | |
| number.each do |n| | |
| print "#{n}, " | |
| end | |
| puts | |
| end | |
| puts_buzzes("FizzBuzzes",fizz_buzz) | |
| puts_buzzes("Fizzes",fizz) | |
| puts_buzzes("Buzzes",buzz) | |
| puts_buzzes("Neither",no_buzz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment