How to resolve the algorithm 99 bottles of beer step by step in the Icon and Unicon programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm 99 bottles of beer step by step in the Icon and Unicon programming language
Table of Contents
Problem Statement
Display the complete lyrics for the song: 99 Bottles of Beer on the Wall.
The lyrics follow this form: ... and so on, until reaching 0 (zero). Grammatical support for 1 bottle of beer is optional. As with any puzzle, try to do it in as creative/concise/comical a way as possible (simple, obvious solutions allowed, too).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm 99 bottles of beer step by step in the Icon and Unicon programming language
Source code in the icon programming language
procedure main(args)
numBeers := integer(args[1]) | 99
drinkUp(numBeers)
end
procedure drinkUp(beerMax)
static beerMap
initial {
beerMap := table(" bottles")
beerMap[1] := " bottle"
}
every beerCount := beerMax to 1 by -1 do {
writes( beerCount,beerMap[beerCount]," of beer on the wall, ")
write( beerCount,beerMap[beerCount]," of beer.")
writes("Take one down and pass it around, ")
write(case x := beerCount-1 of {
0 : "no more bottles"
default : x||beerMap[x]
}," of beer on the wall.\n")
}
write("No more bottles of beer on the wall, no more bottles of beer.")
write("Go to the store and buy some more, ",
beerMax," bottles of beer on the wall.")
end
You may also check:How to resolve the algorithm Hostname step by step in the Tcl programming language
You may also check:How to resolve the algorithm DNS query step by step in the TXR programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the UnixPipes programming language
You may also check:How to resolve the algorithm Bioinformatics/Sequence mutation step by step in the Swift programming language
You may also check:How to resolve the algorithm Tokenize a string step by step in the TUSCRIPT programming language