18
3
In traditional FizzBuzz, you are asked to print the numbers from 1 to 100, but replacing every multiple of 3 with "Fizz", every multiple of 5 with "Buzz", and every multiple of both 3 and 5 (i.e. 15) with "FizzBuzz".
However, as an evil interviewer, I've invented my own twisted version of FizzBuzz, which I've decided to name BizzFuzz and give to you in a coding interview.
The rules of the game are:
Print each number from 1 to 100, except if the number meets one of the conditions below.
- If the number is divisible by 4, print "Fizz".
If the number is divisible by 5, print "Buzz".
If the number is divisible by 4, but the number immediately after it is divisible by 5, print "FizzBuzz" instead of "Fizz", and print the next number regularly.
If the number is divisible by 5, but the number immediately after it is divisible by 4, print "BuzzFizz" instead of "Buzz", and print the next number regularly.
If the number is immediately before a number divisible by both 4 and 5, print "Bizz".
If the number is immediately after a number divisible by both 4 and 5, print "Fuzz".
If the number is divisible by both 4 and 5, print "BizzFuzz".
The shortest code to implement all these rules in any language wins.
@minitech, typo introduced by not copy-pasting because reindenting everything is a pain in the neck. Fixed. – Peter Taylor – 2013-08-16T20:26:39.700
2reindenting everything = CTRL+K – John Dvorak – 2013-08-16T20:27:46.937
Can you explain this? – Johannes Kuhn – 2013-08-16T20:55:48.813
"Not a very interesting problem." Yeah, I had a hunch that was the case when I posted it. Still, it is a variation. – Joe Z. – 2013-08-17T00:10:47.007
It also gets more interesting as a parlour game with friends, rather than a programming challenge. Take turns trying to say the numbers in order. It's basically FizzBuzz Hardcore Edition if you don't memorize the sequence beforehand.
– Joe Z. – 2013-08-17T00:26:54.660@PeterTaylor You can remove a few characters if you remove all
z
s but add a space after each string. Reinsertingzz
can then be done via2/'zz'*
– Howard – 2013-08-17T08:07:39.937@Howard, I considered using
2/
but your way of doing it creates trailing spaces, and stripping those is costly. However, I see an alternative way of using it. – Peter Taylor – 2013-08-17T08:57:53.400