Here’s a fun little challenge for your Friday afternoon. You can do it at home, in a bar, or hopefully even at work. Best of all, it’s technical and creative. Your task, should you choose to accept it, is to produce the lyrics to 99 Bottles of Beer in your favorite programming language. I chose to do the solution below in FileMaker. See 99-bottles-of-beer.net for the official challenge details.
The Joy of Diversity
The diversity of what you can do given the same constraints is fascinating. Variations within the same language can be very
revealing. In fact, some people use basic problems like this to evaluate the proficiency of programming candidates. But there’s much more discovery to be had! Studying other languages is a great way to expand your perspective and capabilities. There are 1436 different programming languages and variations represented on the challenge site, including solutions in AppleScript, Ruby, Malbolge (give me an aspirin!) and even Piet (what!?). My personal favorite is this solution in Perl (believe it or not, it works!).
99 Bottles of Beer, the FileMaker Version
Jon Rosen submitted a solution using FileMaker 3 back in 1996. FileMaker has come a long way since then, although text handling is a fairly static feature set. I couldn’t help but throw together my own version (see below). This attempt strives for a standard balance between reliability, extandability, conciseness and readability.
So how would you do it? We’d love to see more examples. The guys at 99-bottles-of-beer.net sound pretty backlogged, but hopefully you can post a link below in the comments. I’ve also attached a demo file for you to play with.
# PURPOSE: Generates lyrics to 99 Bottles of Beer. See http://99-bottles-of-beer.net. # HISTORY: Created 2011-Dec-08 by Donovan Chandler # NOTES: # Displays how FileMaker is relatively intuitive and foolproof # This is actually a textual approximation of a graphical-based UI # Original number of bottles can easily be adjusted in $_total # Set Variable [ $_total; Value: 99 ] Set Variable [ $_rep; Value: $_total ] Loop Exit Loop If [ $_rep < 1 ] Set Variable [ $_status; Value: Let ( [ status = $_rep & " bottle" & If ( $_rep ≠ 1 ; "s" ) ]; status & " of beer on the wall, " & status & " of beer." ) ] Set Variable [ $_action; Value: Let ( [ num = $_rep - 1 ; status = If ( num = 0 ; "no more bottles" ; num & " bottle" & If ( num ≠ 1 ; "s" ) ) ]; "Take one down and pass it around, " & status & " of beer on the wall." ) ] Set Variable [ $_lyric; Value: List ( $_lyric ; $_status ; $_action & ¶ ) ] Set Variable [ $_rep; Value: $_rep - 1 ] End Loop Set Variable [ $_lyric; Value: List ( $_lyric ; "No more bottles of beer on the wall, no more bottles of beer." ; "Go to the store and buy some more, " & $_total & " bottles of beer on the wall." ) ] # Set Field [ Table::lyrics; $_lyric ]