-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathtwelve_days.ps1
66 lines (52 loc) · 1.43 KB
/
twelve_days.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<#
Author: Doug Finke
Email: [email protected]
Blog: https://dfinke.github.io/
Twitter: https://twitter.com/dfinke
GitHub: https://github.com/dfinke
YouTube: https://www.youtube.com/dougfinke
PowerShell Meetup: https://www.meetup.com/NycPowershellMeetup/
LinkedIn: https://www.linkedin.com/in/douglasfinke/
#>
param(
[ValidateRange(1, 12)]
[int]$num = 12,
$outFile
)
function verse {
param($day)
$ordinal = 'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh',
'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth'
$gifts = 'A partridge in a pear tree.',
'Two turtle doves,',
'Three French hens,',
'Four calling birds,',
'Five gold rings,',
'Six geese a laying,',
'Seven swans a swimming,',
'Eight maids a milking,',
'Nine ladies dancing,',
'Ten lords a leaping,',
'Eleven pipers piping,',
'Twelve drummers drumming,'
$lines = @(
"On the $($ordinal[$day]) day of Christmas,",
'My true love gave to me,'
)
$reversedGifts = $gifts[0..$day]
[array]::Reverse($reversedGifts)
$lines += $reversedGifts
if ($day -ge 1) {
$lines[-1] = 'And ' + $lines[-1].ToLower()
}
$lines
}
$result = 0..($num - 1) | ForEach-Object {
verse $_
}
if ($outFile) {
$result | Set-Content $outFile
}
else {
$result -join "`r`n"
}