M
Michael Glaesemann
My first Ruby Quiz submission.
# Straightforward solution
(1..100).each do |n|
print "Fizz" if 0 == n % 3
print "Buzz" if 0 == n % 5
print n if 0 != n % 3 and 0 != n % 5
print "\n"
end
# Peter Seebach "extra fun" solution
class Fixnum
alias old_to_s to_s
def to_s
value = ""
value += "Fizz" if 0 == self % 3
value += "Buzz" if 0 == self % 5
value += self.old_to_s if "" == value
value
end
end
(0..100).each { |x| p x }
# make things right again
class Fixnum
alias to_fizz_buzz to_s
alias to_s old_to_s
end
# golf solution (67 chars)
1.upto(?d){|n|puts 0<n%3&&0<n%5?n1>n%3?"Fizz":'')+(1>n%5?"Buzz":'')}
Cheers,
Michael Glaesemann
grzm seespotcode net
# Straightforward solution
(1..100).each do |n|
print "Fizz" if 0 == n % 3
print "Buzz" if 0 == n % 5
print n if 0 != n % 3 and 0 != n % 5
print "\n"
end
# Peter Seebach "extra fun" solution
class Fixnum
alias old_to_s to_s
def to_s
value = ""
value += "Fizz" if 0 == self % 3
value += "Buzz" if 0 == self % 5
value += self.old_to_s if "" == value
value
end
end
(0..100).each { |x| p x }
# make things right again
class Fixnum
alias to_fizz_buzz to_s
alias to_s old_to_s
end
# golf solution (67 chars)
1.upto(?d){|n|puts 0<n%3&&0<n%5?n1>n%3?"Fizz":'')+(1>n%5?"Buzz":'')}
Cheers,
Michael Glaesemann
grzm seespotcode net