How to resolve the algorithm The Twelve Days of Christmas step by step in the PowerShell programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm The Twelve Days of Christmas step by step in the PowerShell programming language
Table of Contents
Problem Statement
Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas.
The lyrics can be found here.
(You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.)
Let's start with the solution:
Step by Step solution about How to resolve the algorithm The Twelve Days of Christmas step by step in the PowerShell programming language
Source code in the powershell programming language
$days = @{
1 = "first";
2 = "second";
3 = "third";
4 = "fourth";
5 = "fifth";
6 = "sixth";
7 = "seventh";
8 = "eight";
9 = "ninth";
10 = "tenth";
11 = "eleventh";
12 = "twelfth";
}
$gifts = @{
1 = 'A partridge in a pear tree';
2 = 'Two turtle doves';
3 = 'Three french hens';
4 = 'Four calling birds';
5 = 'Five golden rings';
6 = 'Six geese a-laying';
7 = 'Seven swans a-swimming';
8 = 'Eight maids a-milking';
9 = 'Nine ladies dancing';
10 = 'Ten lords a-leaping';
11 = 'Eleven pipers piping';
12 = 'Twelve drummers drumming';
}
1 .. 12 | % {
"On the $($days[$_]) day of Christmas`nMy true love gave to me"
$_ .. 1 | % {
$gift = $gifts[$_]
if ($_ -eq 2) { $gift += " and" }
$gift
}
""
}
You may also check:How to resolve the algorithm Ordered partitions step by step in the Python programming language
You may also check:How to resolve the algorithm Radical of an integer step by step in the Perl programming language
You may also check:How to resolve the algorithm Gotchas step by step in the jq programming language
You may also check:How to resolve the algorithm Sexy primes step by step in the Python programming language
You may also check:How to resolve the algorithm Pointers and references step by step in the Nim programming language