Thursday, February 28, 2008

Sudden Death Challenge: Event 3

 

$presidents= cat C:\Scripts\presidents.txt | foreach {
    $tmp = $_.split(",")
    $p=New-Object psobject
    Add-Member -inp $p noteproperty firstName $tmp[1].trim()
    Add-Member -inp $p noteproperty lastName  $tmp[0].trim()
    Add-Member -inp $p noteproperty firstLength $p.firstName.length
    Add-Member -inp $p noteproperty vowels @(("{0}{1}" -f $p.firstName,$p.lastName).toCharArray() -match '[aeiou]').count
    $p
}


$longest = $presidents | sort firstLength -desc | select -first 1
"Longest first name: {0} {1}" -f $longest.firstName,$longest.lastName

"Total vowels used: {0}" -f ($presidents | measure-object vowels -sum).sum


$initials = ""
$alphabet = ([string](65..90 | foreach {[char]$_})).replace(" ","")

$presidents  | foreach {
    $initials+="{0}{1}" -f $_.firstName[0],$_.lastName[0]
}

$alphabet = $alphabet -replace "[$initials]"
"The following letters are not used as Presidential initials:"
$alphabet.ToCharArray()

 

 

# results

Longest first name: Rutherford Hayes
Total vowels used: 192
The following letters are not used as Presidential initials:
I
O
Q
S
X
Y

No comments: