How to resolve the algorithm Old lady swallowed a fly step by step in the REXX 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 REXX 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 REXX programming language
Source code in the rexx programming language
/*REXX program displays song lyrics for: "I Know an Old Lady who Swallowed a Fly". */
sw= 79 /*the width of the terminal screen, -1.*/
@.=; @.1 = "I don't know why she swallowed a fly,"
@.2 = "That wriggled and jiggled and tickled inside her."; @.2.0=.
@.3 = "How absurd to swallow a bird!"
@.4 = "Imagine that, to swallow a cat!"
@.5 = "My, what a hog, to swallow a dog!"
@.6 = "Just opened her throat and swallowed a goat!"
@.7 = "I wonder how she swallowed a cow?!"
@.8 = "She's dead, of course!!"
$ = 'fly spider bird cat dog goat cow horse'
#= words($) /*#: number of animals to be swallowed*/
do j=1 for #; say
say center('I know an old lady who swallowed a' word($, j)",", sw)
if j\==1 then say center(@.j, sw)
if j ==# then leave /*Is this the last verse? We're done.*/
do k=j to 2 by -1; km= k-1; ??= word($, km)','
say center('She swallowed the' word($,k) "to catch the" ??, sw)
if @.km.0\=='' then say center(@.km, sw)
end /*k*/ /* [↑] display the lyrics of the song.*/
say center(@.1, sw)
say center("I guess she'll die.", sw)
end /*j*/ /*stick a fork in it, we're all done. */
You may also check:How to resolve the algorithm Character codes step by step in the VBScript programming language
You may also check:How to resolve the algorithm Modified random distribution step by step in the Go programming language
You may also check:How to resolve the algorithm Deal cards for FreeCell step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Exceptions step by step in the VBA programming language
You may also check:How to resolve the algorithm Hash join step by step in the Nim programming language