Monday, February 25, 2008

2008 Scripting Games - Advanced Event 1

 

Event 1: Could I Get Your Phone Number?

It seems I've taken the long path on this event, brute forcing every possible combination, padding all 3 letters to four chars.

 

$phone=Read-Host "Enter 7 digit phone number"
$letters = @{"2"="abc";"3"="def";"4"="ghi";"5"="jkl";"6"="mno";"7"="pqrs";"8"="tuv";"9"="wxyz"}
$numbers = 0..($phone.length-1) | foreach { "{0,-4}" -f $letters["$($phone[$_])"]}

"Computing word from Number, this may take a while..."

$wordList = cat c:\scripts\wordList.txt | where {($_.length -eq 7) -and ($_.substring(0,1) -match "[$($numbers[0])]")}


for($a=0; $a -lt 4; $a++){
    for($b=0; $b -lt 4; $b++){
        for($c=0; $c -lt 4; $c++){
            for($d=0; $d -lt 4; $d++){
                for($e=0; $e -lt 4; $e++){
                    for($f=0; $f -lt 4; $f++){
                        for($g=0; $g -lt 4; $g++){
                                    $word = "{0}{1}{2}{3}{4}{5}{6}" -f $numbers[0][$a],$numbers[1][$b],$numbers[2][$c],$numbers[3][$d],$numbers[4][$e],$numbers[5][$f],$numbers[6][$g]
                                    if($wordList -contains $word) {$wordList | where {$_ -eq $word}; return}
                        }
                    }
                }
            }
        }
    }
}

"Scan completed"

No comments: