I invented/discovered/came-upon "Inverse Fizzbuzz" while mucking about with Scala & Partial Functions.

While Fizzbuzz answers the question "Can Shipper code ? ", Inverse Fizzbuzz tells you "How well does Shipper code ?"After posting the Hacker News piece, Inverse Fizzbuzz was featured on a codegolf.There were a dozen participants - with solutions in Ruby, Perl, Python, Scheme, PHP, Javascript, Groovy, and yes , Scala. After the golf ended, the results were somewhat bizarre. The Perl solution by tybalt89 won, with a score of 10,000.Here's the winning entry - practically a one-liner.

Now guess the solution that came in dead last ? Scala !That bothered me a little bit. But what bothered me the most was the cheating :)

Cheating! What do I mean by that ? Take a look at the test caseHere's what the outputs look like: look at the item in red.9 723 33 123 45

6 105 63 9612 102

12 155 53 9315 1773 275 339 1159 489 8715 189 30

9 1806 915 159 13512 1812 9610 153 55-----

So if somebody told you that the largest fizzbuzz string mapped to 180, then you can cheat by simply generating all possibles upto/beyond 180, use memoization & simply compare the test input to what you've precomputed. That's what most of the entries had done.

So for example, the Perl solution has " F BF FB F E"x22 ie. 15 times 22 > 180In the Python solution : see the number 182In the Haskell solution : the number 171In the Scala solution: Seq.tabulate(181)In the Javascript solution : the number 182I decided I wouldn't cheat. Instead I will solve Inverse Fizzbuzz from first principles, using a Finite State Machine => Regex approach.Note: I'm not interested so much in the numbers on the RHS as much as making sure if a sequence of strings actually corresponds to a valid "Inverse Fizzbuzz" . So the goal is to test language memberships. Number gymnastics can come later. Inverse FizzBuzz - Given a list of strings , what's the shortest contiguous sequence of numbers that produces that list when you run fizbuzz ( over those numbers ) ?( or in pictures, how do you go from stuff on the left to stuff on the right ? )

Say fizz = f, buzz = b, fizzbuzz = gThe finite state machine that produces the language of "Inverse Fizzbuzz" must have 8 states and must look like belowIts not too hard to see why."Fizz" qualifies - ergo, go from start state q0 via arc "f" to terminal state q1"Buzz" qualifies - go from start state q0 via arc "b" to terminal state q2"Fizz Buzz" qualifies - go from start state q0 via arc "f" to q1, then via arc "b" to terminal state q2."Fizz Buzz Fizz" qualifies - go from start state q0 via arc "f" to q1, then via arc "b" to q2, then via "f" to terminal state q3.Clearly "Buzz Buzz" does not qualify, so there's no way to produce "bb" via the machine below.And so on and so forth... ( If you have a simpler FSM, please do email me )

Getting rid of the multiple terminal nodes will introduce lambda-transitions ( NFA-epsilons ) and you get the machine below:

Now you reform transitions - ie. put lambda-transitions between states with no transitions. That produces the monster below:

Finally, the Collapse mode: get rid of the non-final and non-initial states systematically, and JFLAP leaves you with :

Postscript: The "Regular Expression Exploration" Tool produced by Microsoft Research consumes a RegEx and produces an automaton. When fed the Inverse Fizzbuzz Regex, it produced the alongside automaton with 81 states !!! ( Thanks to sureshv at HN )

That was a pretty good demonstration of the solution. But if I am not mistaken, I would guess your solution is incomplete. Your solution only points out if a given sequence is valid or not i.e. only prints boolean true or false, but doesn't actually gives out the sequence of numbers, as asked in the question.

So even if you are not cheating, your solution is also not giving the result expected.

Before current technology came to the forefront, we had about seven basic modes of communication: telephone, telegraph wire, television, radio, mail, fax machines, eventually the pager (or beeper) and the grapevine---over the fence

The inverse fizz buzz logic is great. I really liked the logic behind your work. The article is very interesting and the description given is very clear and elaborate. The graphical and pictorial explanations given are helpful in understanding the logic. Thanks a lot for sharing this post

Creating a list of the first hundred Fizz buzz numbers is a trivial problem for any would-be computer programmer, so interviewers can easily sort out those with insufficient programming ability. Thanks for information.