Skip to content

Instantly share code, notes, and snippets.

@nestorsalceda
Created February 24, 2015 16:53
Show Gist options
  • Save nestorsalceda/3f6306133fd195a9ed64 to your computer and use it in GitHub Desktop.
Save nestorsalceda/3f6306133fd195a9ed64 to your computer and use it in GitHub Desktop.
Basic Fizzbuzz
def is_fizz(number)
number % 3 == 0 and number.to_s[-1] == "3"
end
def is_buzz(number)
number % 5 == 0 and number.to_s[-1] == "5"
end
def fizzbuzz(number)
return 'FizzBuzz' if is_fizz(number) and is_buzz(number)
return 'Fizz' if is_fizz(number)
return 'Buzz' if is_buzz(number)
number
end
1.upto(20) do |number|
puts fizzbuzz(number)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment