πΎ Archived View for blitter.com βΊ apl-examples βΊ beer-song βΊ beer-song-example.apl.txt captured on 2023-11-14 at 07:45:56.
β¬ οΈ Previous capture (2023-05-24)
-=-=-=-=-=-=-
#!/usr/local/bin/apl --script β The famous '99 Bottles of Beer' road song in APL β β This solution uses a straightforward recursive solution. β There are iterative and tail-recursive ways to do it, why β not try it those ways afterwards? ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ βs beers n;next ββ This function does the real work; note that it takes ββ two arguments: s is the original count at the start of ββ the song, so that it can be printed at the end. ββββ nextβn-1 β(n=0)/none β(n=1)/last ββn,'Bottles of beer on the wall,',n,'bottles of beer.' ββ'Take one down and pass it around,',next,'bottles of beer on the wall.' s beers next β0 last: ββn,'Bottle of beer on the wall,',n,'bottle of beer.' ββ'Take it down and pass it around, no more bottles of beer on the wall.' s beers next β0 none: ββ'No more bottles of beer on the wall, no more bottles of beer.' ββ'Go to the store and buy some more,',s,'bottles of beer on the wall.' β0 β βbeerSong n ββ This is the main entry function. ββ Note we avoid counting down from 0 bottles of beer! ββββ β(nβ₯0)/viableSong nonsense: ββ'Negative beer? Madness!' β0 viableSong: n beers n β