Actually I'm not going to write about it. I wrote three drafts, and all were squelched by my better judgement.
But here is a 4 line fizzbuzz program instead! Yay!
#!/usr/bin/ruby
for i in 1..100
fb = {0 => i, 2 => "fizz", 4 => "buzz", 6 => "fizzbuzz"}
puts fb[ (i%3).zero?.object_id + (i%5).zero?.object_id*2 ]
end
This problem is seductive because the requirement to not print the number when you are printing fizz/buzz means that a simple, clean IF statement won't work, and you'll have to use an ugly IF structure that bothers people like me. So I spent ten minutes researching the innards of ruby until I was able to remove the IF statement completely.
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment