Last active
December 18, 2015 05:59
-
-
Save joegiralt/5737148 to your computer and use it in GitHub Desktop.
homework Fizz Buzz
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(count_up_to) | |
| number = 1 | |
| for number in 1..count_up_to | |
| print "FizZ" if number%3 == 0 | |
| print "BuzZ" if number%5 == 0 | |
| puts "\n" | |
| puts number unless (number%3 == 0) || (number%5 == 0) | |
| puts "\n" | |
| end | |
| end | |
| end | |
| fizzbuzz(50) | |
| def fizzbuzz_arrays(count_up_to) | |
| number = 1 | |
| fizz, buzz, fizz_buzz = [], [], [] | |
| for number in 1..count_up_to | |
| fizz << number if number%3 == 0 | |
| buzz << number if number%5 == 0 | |
| fizz_buzz << number if number%15 == 0 | |
| end | |
| puts "buzz = " + buzz.to_s + "\nfizz = " + fizz.to_s + "\nfizzbuzz = " + fizz_buzz.to_s | |
| end | |
| fizzbuzz_arrays(50) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment