Imran on Tech recently wrote about using FizzBuzz to Find Developers who Grok Coding. The post basically talks about asking job interviewees to write a simple piece of code based on the following:
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
The point of the exercise being that there are a surprising number of people which fail this simple task, however what follows in the comments is a flurry of hastily coded FizzBuzz samples and amusing discussion (actually similar to a Slashdot comments thread), to the point where Jeff Atwood of Coding Horror declares that FizzBuzz is the programmer's stairway to heaven.
There are now examples out there for pretty much every language.. Well, almost every language. I was trying to think about my least favourite language to code in (of the languages which I do regularly or semi-regularly code in, not something like Assembly or IL), and found that there is no Notes @Function FizzBuzz code - until now!
The first quick as you please attempt, which took a couple of minutes as I woke my brain up. This was sitting as the default value formula for a text field on a Notes form. I also added @NewLine to the end of each iteration of the loop to add readability.
@For(n := 1; n <= 100; n := n + 1;output := output + @If(@Modulo( n ; 3 ) = 0 & @Modulo( n ; 5 ) = 0; "FizzBuzz";@Modulo( n ; 3 ) = 0; "Fizz"; @Modulo( n ; 5 ) = 0; "Buzz" ; @Text(n) ));output;
I don't like this solution due to it needing 3 checks in the @If block. It seems clunky and slightly inelegant, even though it works. So the next version took a 30 second re-write, to come up with this uglier variant:
@For(n := 1; n <= 100; n := n + 1; tmp := @If(@Modulo( n ; 3 ) = 0; "Fizz"; ""); tmp := tmp + @If(@Modulo( n ; 5 ) = 0; "Buzz"; ""); output := output + @If(@Length(tmp) =0; @Text(n); tmp ));output;
This works, but it's even uglier. I'm sure there must be a simpler and more convoluted way to do it, but it'd past midnight and I can't really concentrate. I realise that this is perverting the point of the exercise, and that I'm now trying to create the worst and ugliest FizzBuzz code, but I'm sure that there must be an @Function example out there which works AND makes me wince at the same time. Come on people, help me out..