How to resolve the algorithm Old lady swallowed a fly step by step in the PowerShell 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 PowerShell 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 PowerShell programming language
Source code in the powershell programming language
$lines = @(
'fly/'
'spider/That wiggled and jiggled and tickled inside her,'
'bird/How absurd, to swallow a bird,'
'cat/Imagine that. She swallowed a cat,'
'dog/What a hog to swallow a dog,'
'goat/She just opened her throat and swallowed that goat,'
'cow/I don''t know how she swallowed that cow,'
'horse/She''s dead of course!'
)
$eatenThings = @()
for($i=0; $i -lt $lines.Count; $i++)
{
$creature, $comment = $lines[$i].Split("/")
$eatenThings += $creature
"I know an old lady who swallowed a $creature,"
if ($comment) {$comment}
if ($i -eq ($lines.Count - 1)) {continue}
for($j=$i; $j -ge 1; $j--)
{
"She swallowed the {0} to catch the {1}," -f $eatenThings[$j, ($j-1)]
}
"I don't know why she swallowed the fly."
"Perhaps she'll die."
""
}
You may also check:How to resolve the algorithm Determine if only one instance is running step by step in the Sidef programming language
You may also check:How to resolve the algorithm Check that file exists step by step in the RLaB programming language
You may also check:How to resolve the algorithm Associative array/Creation step by step in the zkl programming language
You may also check:How to resolve the algorithm Fibonacci word/fractal step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Non-decimal radices/Convert step by step in the Standard ML programming language