Created
December 14, 2015 13:58
-
-
Save jbuenting/cfab1272ece134f8283f to your computer and use it in GitHub Desktop.
Powershell.org DEC 2015 Powershell Games
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$list = @" | |
1 Partridge in a pear tree | |
2 Turtle Doves | |
3 French Hens | |
4 Calling Birds | |
5 Golden Rings | |
6 Geese a laying | |
7 Swans a swimming | |
8 Maids a milking | |
9 Ladies dancing | |
10 Lords a leaping | |
11 Pipers piping | |
12 Drummers drumming | |
"@ | |
Write-Output "Solution 1:`n`n" | |
$List -Split "`n" | sort length | |
"`n-----------`n" | |
Write-Output "Solution 1 Bonus: `n`n" | |
(($List -Split "`n") -Replace '\d*','').trim() | sort length | |
"`n------------`n" | |
Write-Output "Solution 2:`n`n" | |
$Gifts = $List -Split "`n" | Select-Object @{Name='Item';Expression={($_ -Replace '\d*','').trim()}}, @{Name='Count';Expression={$_ -Replace '\D',''}} | |
$Gifts | |
"`n-----------`n" | |
Write-Output "Solution 3:`n`n" | |
$Birds = 'Partridge','Doves','Hens','Birds','Geese','Swans' | |
$BirdCount = 0 | |
$Gifts | Foreach { | |
$Gift = $_ | |
$Birds | Foreach { if ( $Gift -Match $_ ) { $BirdCount += $Gift.Count } } | |
} | |
"Total of BirdRelated Items = $BirdCount" | |
"`n-----------`n" | |
Write-Output "Solution 4:`n`n" | |
$NumGifts = ($Gifts | Select -ExpandProperty count | measure-object -sum).sum | |
Write-Output "Total Number of Gifts = $NumGifts" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment