Created
September 25, 2013 22:50
-
-
Save samtalks/6707289 to your computer and use it in GitHub Desktop.
HW given on 9/25
This file contains 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
FizzBuzz part 1 | |
def fizzbuzz(until_num) | |
i = 1 | |
while i <= until_num do | |
if i % 3 == 0 && i % 5 == 0 | |
puts "FizzBuzz" | |
elsif i % 3 == 0 | |
puts "Fizz" | |
elsif i % 5 == 0 | |
puts "Buzz" | |
else | |
puts i | |
end | |
i += 1 | |
end | |
end | |
fizzbuzz(50) | |
# FizzBuzz part 2 | |
def fizzbuzz2(until_num) | |
i = 1 | |
puts "FizzBuzz numbers: " | |
while i <= until_num do | |
puts i if i % 3 == 0 && i % 5 == 0 | |
i += 1 | |
end | |
i = 1 | |
puts "Fizz numbers: " | |
while i <= until_num do | |
puts i if i % 3 == 0 | |
i += 1 | |
end | |
i = 1 | |
puts "Buzz numbers: " | |
while i <= until_num do | |
puts i if i % 5 == 0 | |
i += 1 | |
end | |
end | |
fizzbuzz2(50) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment