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

Published on 12 May 2024 09:40 PM
#E

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

Source code in the e programming language

def bottles(n) {
  return switch (n) {
    match ==0 { "No bottles" }
    match ==1 { "1 bottle" }
    match _   { `$n bottles` }
  }
}
for n in (1..99).descending() {
  println(`${bottles(n)} of beer on the wall,
${bottles(n)} of beer.
Take one down, pass it around,
${bottles(n.previous())} of beer on the wall.
`)
}

  

You may also check:How to resolve the algorithm Greatest element of a list step by step in the E programming language
You may also check:How to resolve the algorithm Window creation step by step in the E programming language
You may also check:How to resolve the algorithm Doubly-linked list/Element definition step by step in the E programming language
You may also check:How to resolve the algorithm Singly-linked list/Element definition step by step in the E programming language
You may also check:How to resolve the algorithm Nth root step by step in the E programming language