Wednesday, April 23, 2008 3:46:56 AM UTC #

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

2008 Winter Scripting Game Events: Index

Categories: PowerShell
Technorati:
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Syndication

Search
Posts on this page
Categories
Sites I visit regularly
About

Powered by: newtelligence dasBlog 2.2.8279.16125

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008, Peter Seale

Send mail to the author(s) E-mail



Sign In