FizzBuzz with Sather like loop
Posted by Shugo Maeda Fri, 24 Aug 2007 23:06:00 GMT
num = (1..100).each
fizz = ([""] * 2 + ["Fizz"]).cycle
buzz = ([""] * 4 + ["Buzz"]).cycle
loop do
n = num.next
puts (fizz.next + buzz.next).sub(/\A\z/) { n }
end
Other posts about this post.
This post has been discussed on the following web sites / blogs. If you wish to trackback to this post please use the following trackback address: http://blog.shugo.net/articles/trackback/25
Spread the word.
Shugo's Blog supports RSS (Real Simple Syndication), and Trackbacks from other blogs.
Your Comments.
Leave your own response