Testing FizzBuzz in Parrot
A recent discussion on interviewing programmers (in hopes of finding clueful ones) brought up the FizzBuzz challenge. Can you write a program to print the numbers from one to one hundred, printing also "Fizz" for multiples of three, "Buzz" for multiples of five, and "FizzBuzz" for multiples of three and five?
This ought to take no more than a few minutes for a developer with any proficiency in a language. I decided it would be fun to write it in Parrot's PIR. There's the straightforward procedural way, the array overloading way, an object-oriented way, the coroutine approach, and the generator technique.
I chose the first two, but I also decided to work entirely with test-driven development, even though this is normally the realm of a SpikeSolution--I thought that might be more interesting for everyone.
|The link to Parrotcode is .com where it should be .org|
|Thanks, Tyxod. I just fixed that and clarified a piece of code!|
In PHP, fast as I can make it (and without formatting because of the way comments are handled):