How to resolve the algorithm 99 bottles of beer step by step in the Picat programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm 99 bottles of beer step by step in the Picat 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 Picat programming language
Source code in the picat programming language
beer1(N) =>
Beer = N,
while (Beer > 0)
printf("%d bottles of beer on the wall,\n", Beer),
printf("%d bottles of beer.\n", Beer),
printf("Take one down, pass it around.\n"),
printf("%d bottles of beer.\n", Beer-1),
Beer := Beer -1
end,
print("0 more bottles of beer on the wall.\n"),
nl.
% With plurals.
beer2(B) = S =>
BS = B.to_string(),
BB = " bottle",
BT = BB,
if B > 1 then BB := BB ++ "s" end,
OB = " of beer",
NL = "\n",
BW = OB ++ " on the wall." ++ NL,
T = "Take one down, pass it around." ++ NL,
S1 = BS ++ BT ++ BW ++ BS ++ BT ++ OB ++ T ++
cond(B > 0, (B-1).to_string() ++ BT ++ BW ++ NL, ""),
S = S1.
You may also check:How to resolve the algorithm Fractran step by step in the D programming language
You may also check:How to resolve the algorithm Empty directory step by step in the 11l programming language
You may also check:How to resolve the algorithm Generate Chess960 starting position step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Best shuffle step by step in the J programming language
You may also check:How to resolve the algorithm Loops/While step by step in the REXX programming language