2008 Winter Scripting Games Event 9
If you aren't already in the know, these ten problems are from the 2008 Winter Scripting games.
For each problem, I'm going to quickly sum up the interesting (interesting TO ME) bits of each problem, then I'm going to post the full source.
Event 9: You're Twisting My Words
Simple: reverse letters in each word, WITHOUT reversing the order of the words. It's a simple case of breaking down the huge string into tokens, then reversing the contents of the tokens, then re-combining the tokens. Actually it's even simpler than I described. Moving on.
Source
#PROBLEM #9
function Reverse-LettersInWord ($word)
{
$reversedChars = @()
for ($i = $word.Length - 1; $i -ge 0; $i--)
{
$reversedChars += $word[$i]
}
[string]::Join("", $reversedChars)
}
function Solve-Problem9
{
[string]::Join(" ", ( ( (cat "C:\Scripts\alice.txt").Split(" ") ) | % { Reverse-LettersInWord -word $_ } ) )
}
Solve-Problem9
function Reverse-LettersInWord ($word)
{
$reversedChars = @()
for ($i = $word.Length - 1; $i -ge 0; $i--)
{
$reversedChars += $word[$i]
}
[string]::Join("", $reversedChars)
}
function Solve-Problem9
{
[string]::Join(" ", ( ( (cat "C:\Scripts\alice.txt").Split(" ") ) | % { Reverse-LettersInWord -word $_ } ) )
}
Solve-Problem9
2008 Winter Scripting Game Events: Index
- Introduction: TOTAL DOMINATION!
- Event 1: Could I Get Your Phone Number?
- Event 2: Skating on Thin Ice
- Event 3: Instant (Runoff) Winner
- Event 4: Image is Everything
- Event 5: You Call That a Password?
- Event 6: Prime Time
- Event 7: Play Ball!
- Event 8: Making Beautiful Music
- Event 9: You're Twisting My Words
- Event 10: Blackjack!
- Recap