There is a famous song:
/*
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.
...
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;
forRange(-99, 1, (count) {
bottles = (c, n) {
c == 0 ? "{}
{n}o more bottles
" : "{}
{c} bottle{c != 1 ? "s"}
"
};
log("{}/
{bottles(-count, "N")} of beer on the wall, {bottles(-count, "n")} of beer.
{count == 0
? "Go to the store and buy some more"
: "Take one down and pass it around"
}, {bottles((99 - count) % 100, "n")} of beer on the wall.
");
})
Unlike code in Wikipedia, this solution does the thing:
- it correctly adds the ending (s) to the second line,
- it adds the "Go to the store" statement,
- it adds "No more" to the beginning of the verse where it's needed,
- it uses the correct case for "N" letter,
- it follows DRY principle.
All in all, despite its young age Argentum succeeded in solving this question in a straightforward and effective way (it compiled to 20k standalone Windows executable).
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.