How to resolve the algorithm Old lady swallowed a fly step by step in the Logo 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 Logo 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 Logo programming language
Source code in the logo programming language
make "data [
; animal inc comment
[fly 2 [I don't know why she swallowed that fly]]
[spider 2 [That wriggled and jiggled and tickled inside her]]
[bird 1 [Quite absurd, to swallow a bird]]
[cat 1 [How about that, to swallow a cat]]
[dog 1 [What a hog, to swallow a dog]]
[pig 1 [Her mouth was so big to swallow a pig]]
[goat 1 [She just opened her throat to swallow a goat.]]
[cow 1 [I don't know how she swallowed a cow.]]
[donkey 1 [It was rather wonky to swallow a donkey]]
[horse 0 [She's dead, of course!]]
]
foreach :data [
local "i make "i #
(local "animal "include "comment)
(foreach [animal include comment] ? "make)
print se [There was an old lady who swallowed a] :animal
print :comment
if greater? :include 0 [
if greater? :i 1 [
repeat difference :i 1 [
local "j make "j difference :i repcount
print (se [She swallowed the] (first item sum 1 :j :data)
[to catch the] (first item :j :data))
if greater? item 2 item :j :data 1 [print item 3 item :j :data]
]
]
print [Perhaps she'll die]
print "
]
]
bye
You may also check:How to resolve the algorithm Associative array/Creation step by step in the Scala programming language
You may also check:How to resolve the algorithm Rot-13 step by step in the Burlesque programming language
You may also check:How to resolve the algorithm Sequence of primes by trial division step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Hofstadter Figure-Figure sequences step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Validate International Securities Identification Number step by step in the AWK programming language