Scripting Games 2007 Advanced PowerShell Event 9
As the Answers to the events 9 and 10 in the Scripting Games 2007, Are Posted,
I will again post my solutions here on my blog:
PS Answer: Get Me the Operator, Please
My answer to Event 9 is a bit shorter as the answer given by the Scripting Guys, but it basically does the same, using 4 nested loops to enumerate all Possibilities
$op = '+','-','*','/'
Foreach ($1 in $op) {
Foreach ($2 in $op) {
Foreach ($3 in $op) {
Foreach ($4 in $op) {
if (Invoke-Expression "12 $1 8 $2 4 $3 2 $4 9 -eq 23") {
"12 $1 8 $2 4 $3 2 $4 9 = 23"
}
}
}
}
}
And the Answer is :
PoSH> C:\scripts\Event9.ps1
12 + 8 - 4 - 2 + 9 = 23
Enjoy,
Greetings /\/\o\/\/