blog.sorah.jp

FizzBuzz seems be deprecated... How about FibBuzz? #fibbuzz

日本語版

@lchin: "FizzBuzz、4年前に飽きたわー"って誰かまだ言っていないか?あくまで省力化のための足切りとしてのものだけど、出まわりすぎた時点でかなり効果が低下しているはずだ。まぁ、採用基準よりも「不採用基準」として使うだろう

(Are there any person still saying "FizzBuzz, I've lost interest in that 4 years ago..."? We use FizzBuzz for cutoff of a test of employment, but FizzBuzz's effect is getting low because it's too popular. If I needs to use it, I'll use FizzBuzz as "Not Adopting standard", not "Adopting standard.")

http://twitter.com/#!/lchin/status/124138347819053058

I've seen this tweet, and agreed. Because I remembered a FizzBuzz code, so I thought it's deprecated. I thought about a game that is more more complicated than FizzBuzz but still it can write easily.

FizzBuzz... Fizz... Fib... FibBuzz... ... FibBuzz!

Fib is used often for a method name that get Fibonacci number. Fib is __Fib__onacci.

The following is a rule of FibBuzz:

FibBuzz

FibBuzz: Enumerate fibonacci numbers starting from 1, but replace multiples of 3 with "Fizz" and multiples of 5 with "Buzz" and multiples of both with "FizzBuzz"

Using as a real question, you have to set a limitation, like "100 fibonacci numbers."

Golf

I've created a problem on golf.shinh.org

http://golf.shinh.org/p.rb?FibBuzz

See Also: http://en.wikipedia.org/wiki/Code_golf

FibBuzz sample code (Ruby)

puts (1..100).inject([1,1]){|s| s<<s[-1]+s[-2] }.map{|i| i%15==0 ? "FizzBuzz" : i%3==0 ? "Fizz" : i%5==0 ? "Buzz" : i }

BuzzFib

First I declared FibBuzz as shown below:

BuzzFib: Enumerate the natural numbers. but replace the fibonacci numbers with "Fib" and multiples of 5 with "Buzz" and the fibonacci numbers which divisible by 5 with "BuzzFib"

As same as above, if you use this as a real question, you have to set a limitation like this: "Enumerate the natural numbers from 1 to 100."

But I decided this is not FibBuzz because of reasons shown later. I declared this as BuzzFib.

BuzzFib sample code (Ruby)

puts (1..100).inject([[1,1],[]]){|(s,r),n|[s<<s[-1]+s[-2],r<<((_="#{s.include?(n)?:Fib:""}#{n%5==0?:Buzz:""}").empty?? n:_)]}[-1]

Golf

I've also created a BuzzFib problem on golf.shinh.org.

http://golf.shinh.org/p.rb?BuzzFib

Why I declared as BuzzFib?

I've thought about fibonacci numbers + FizzBuzz because it seems interesting. and I thought a BuzzFib. (It was a FibBuzz then. now It's BuzzFib)

But it's complex and... see the result shown here:

["Fib", "Fib", "Fib", 4, "FibBuzz", 6, 7, "Fib", 9, "Buzz", 11, 12, "Fib", 14, "Buzz", 16, 17, 18, 19, "Buzz", "Fib", 22, 23, 24, "Buzz", 26, 27, 28, 29, "Buzz", 31, 32, 33, "Fib", "Buzz", 36, 37, 38, 39, "Buzz", 41, 42, 43, 44, "Buzz", 46, 47, 48, 49, "Buzz", 51, 52, 53, 54, "FibBuzz", 56, 57, 58, 59, "Buzz", 61, 62, 63, 64, "Buzz", 66, 67, 68, 69, "Buzz", 71, 72, 73, 74, "Buzz", 76, 77, 78, 79, "Buzz", 81, 82, 83, 84, "Buzz", 86, 87, 88, "Fib", "Buzz", 91, 92, 93, 94, "Buzz", 96, 97, 98, 99, "Buzz"] Like this.

You know, no many "Fib"s.

Because fib(12) > 100 is true. it means fibonacci number gets higher number in short times.

I thought this is not beautiful result, and BuzzFib seems complex problem, so I declared this rule as BuzzFib and I declared FibBuzz as another rule.

Backfilled at , Published at