How to resolve the algorithm 99 bottles of beer step by step in the CLU programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm 99 bottles of beer step by step in the CLU 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 CLU programming language

Source code in the clu programming language

bottles = proc (n: int) returns (string)
    if n<0 then return("99 bottles")
    elseif n=0 then return("No more bottles")
    elseif n=1 then return("1 bottle")
    else return(int$unparse(n) || " bottles")
    end
end bottles

thirdline = proc (n: int) returns (string)
    if n=0 then
        return("Go to the store and buy some more,\n")
    else
        s: string
        if n=1 then s := "it"
        else s := "one"
        end
        return("Take " || s || " down and pass it around,\n");
    end
end thirdline

verse = proc (n: int) returns (string)
    v: string := bottles(n) || " bottles of beer on the wall,\n"
    v := v || bottles(n) || " bottles of beer,\n"
    v := v || thirdline(n)
    v := v || bottles(n-1) || " bottles of beer on the wall.\n\n"
    return(v)
end verse

start_up = proc ()
    po: stream := stream$primary_output()
    
    for n: int in int$from_to_by(99, 0, -1) do
        stream$puts(po, verse(n))
    end
end start_up

  

You may also check:How to resolve the algorithm Stable marriage problem step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Anagrams/Deranged anagrams step by step in the Erlang programming language
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the Limbo programming language
You may also check:How to resolve the algorithm Vigenère cipher/Cryptanalysis step by step in the 11l programming language
You may also check:How to resolve the algorithm Longest common subsequence step by step in the C# programming language