Scripting Games 2008 Sudden Death Challenge 3
My solution for Sudden Death Challenge 3 :
$p = gc c:\scripts\Presidents.txt
"Longest first name: " + (($p | select @{n='Length';e={($_ -split ", ")[1].length}},@{n='Name';e={$_}} | sort length)[-1]).name
"Letters not used as initials"
65..90 |? {($p |% {$_.tochararray() -cmatch '[A-Z]'}) -notcontains [char]$_ } |% {[char]$_}
"Total vowels used: " + ($p |% {$_.tochararray() -match '[aeiou]'}).count
and the result :
PoSH> .\SDEvent3.ps1
Longest first name: Hayes, Rutherford
Letters not used as initials
I
O
Q
S
X
Y
Total vowels used: 192
PoSH>
*Note* The -split operator is a CTP2 feature, for PowerShell V2 you will need :
[regex]::split($_,', ')
*Update*
- I posted my solution to early, sorry for that
- I Posted the wrong solution
- Still some time to deadline, to send in correction but already got the points
- Thanks to jturnage for pointing out my mistake
"Longest first name: " + (($p | select @{n='Length';e={($_ -split ", ")[1].length}},@{n='Name';e={($_ -split ", ")[1] + " " + ($_ -split ", ")[0]}} | sort length)[-1]).name
Enjoy,
Greetings /\/\o\/\/