99 bottles of Ruby
Sterling Camden
Inspired by a post from Chad Perrin, I became a little bit obsessed with the 99 bottles of beer problem again. Specifically, how to reduce it to the fewest number of characters possible in Ruby. I came up with beer2.rb in the download below, which uses 231 characters to generate the entire song strictly according to the lyrics given at 99-bottles-of-beer.net, including capitalization.
I submitted my version to 99-bottles-of-beer.net. A few days later, I received the following response:
Dear Chip Camden,
we would like to thank your for your contribution to the ’99 bottles of beer’ website. Unfortunately we couldn’t accept your submission for the following reason:
—
Not a minimal code contest.
—The team of http://www.99-bottles-of-beer.net/
But still, I thought my minimal version was an interesting demonstration of the power of Ruby. It can even be combined onto one line. That means that using ‘ruby -e’ you could generate the entire song from the shell prompt.
The flexibility of the Ruby language can be seen by comparing the other Ruby versions that have already been submitted, especially the example from Victor Borja that uses continuations. Wrap your head around that one, and you’ll feel like you drank 99 bottles of beer.
In the download below, I’ve also included what I feel to be the most readable version so far – in beer.rb. It’s simple, concise, and clear. See what you think.
Posted in Ruby |
3 Comments » RSS 2.0 | Sphere it!





Nice work.
Thanks, apotheon!
[...] 99 bottles of Ruby — Chip’s Tips for Developers Beer, golf, and Ruby — what could be better? (tags: ruby minimal 99bottlesofbeer apotheon programming) [...]