Skip to content

Instantly share code, notes, and snippets.

@parrot-studio
Created August 8, 2012 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parrot-studio/3292084 to your computer and use it in GitHub Desktop.
Save parrot-studio/3292084 to your computer and use it in GitHub Desktop.
FizzBuzzを書いたことがないとまずいらしいので・・・
# coding: utf-8
(1..100).each do |n|
puts case
when n % 15 == 0
'FizzBuzz'
when n % 3 == 0
'Fizz'
when n % 5 == 0
'Buzz'
else
n
end
end
# coding: utf-8
(1..100).each do |n|
fb = ''
fb << 'Fizz' if n % 3 == 0
fb << 'Buzz' if n % 5 == 0
puts (fb.empty? ? n : fb)
end
# coding: utf-8
class Numeric
def divided_by?(n)
self.modulo(n).zero?
end
end
def fizzbuzz(n)
fb = ''
fb << 'Fizz' if n.divided_by?(3)
fb << 'Buzz' if n.divided_by?(5)
fb.empty? ? n : fb
end
(1..100).each{|n| puts fizzbuzz(n)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment