How to resolve the algorithm Old lady swallowed a fly step by step in the Wren programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Old lady swallowed a fly step by step in the Wren programming language

Table of Contents

Problem Statement

Present a program which emits the lyrics to the song   I Knew an Old Lady Who Swallowed a Fly,   taking advantage of the repetitive structure of the song's lyrics. This song has multiple versions with slightly different lyrics, so all these programs might not emit identical output.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Old lady swallowed a fly step by step in the Wren programming language

Source code in the wren programming language

var animals = ["fly", "spider", "bird", "cat","dog", "goat", "cow", "horse"]

var phrases = [
    "",
    "That wriggled and jiggled and tickled inside her",
    "How absurd to swallow a bird",
    "Fancy that to swallow a cat",
    "What a hog, to swallow a dog",
    "She just opened her throat and swallowed a goat",
    "I don't know how she swallowed a cow",
    "\n  ...She's dead of course"
]

var sing = Fn.new {
     for (i in 0..7) {
       System.print("There was an old lady who swallowed a %(animals[i]);")
       if (i > 0) System.print("%(phrases[i])!")
       if (i == 7) return
       System.print()
       if (i > 0) {
           for (j in i..1) {
               System.write("  She swallowed the %(animals[j]) to catch the %(animals[j - 1])")
               System.print((j < 3) ? ";" :",")
               if (j == 2) System.print("  %(phrases[1])!")
           }
       }
       System.print("  I don't know why she swallowed a fly - Perhaps she'll die!\n")
    }
}

sing.call()

  

You may also check:How to resolve the algorithm Number names step by step in the Inform 7 programming language
You may also check:How to resolve the algorithm Delegates step by step in the TXR programming language
You may also check:How to resolve the algorithm Zero to the zero power step by step in the Symsyn programming language
You may also check:How to resolve the algorithm Anti-primes step by step in the Transd programming language
You may also check:How to resolve the algorithm ABC problem step by step in the SenseTalk programming language