99 bottles of beer

There is a famous kid's song in the USA:

99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.
...
1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no more bottles of beer on the wall.

No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.

This song is sometimes used in computer science to compare languages wikipedia.

And even more, there is a dedicated website, that collected 1500+ variations of this program in different languages.

Let's look how this program can be written in Argentum:

using sys {String, log}
using utils {forRange}
using string;

bottles = `c `n {
    c == 0
        ? "{n}o more bottles"
        : "{c} bottle${c != 1 ? "s"}"
};

forRange(0, 100) `count {
    log("{}\
        { bottles(99-count, "N") } of beer on the wall, { bottles(99-count, "n") } of beer.
        { count == 99
            ? "Go to the store and buy some more"
            : "Take one down and pass it around"
        }, { bottles((198 - count) % 100, "n") } of beer on the wall.
    ");
}

Unlike code in Wikipedia, this solution is correct:

  • it correctly adds the ending (s) in the second line,
  • it adds the "Go to the store" statement,
  • it adds "No more" to the beginning of the verse where needed,
  • it uses the correct case for "N" letter,
  • it doesn't have copy-paste both in code and in string literals.

All in all, despite its young age Argentum succeeded in solving this question in straightforward and effective way.

Leave a Reply

Your email address will not be published. Required fields are marked *