/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Scripting Games week 2 "," Monad Links "," MSH Concentration (scripting games part 4) "," scripting games part 3 "," 2006 Winter Scripting Games (part 2) "," Monad hosting "," Get current user in Monad "," Different ways to do things in Monad, and some links "," 2006 Winter Scripting Games "," Check spelling with MSN Search from MSH (Part 3) "," ")

Wednesday, February 22, 2006


The Scripting Games Event 6 in MSH

And up for the answer to Event 6 but then in MSH

Event 6 is the Word Search Slalom ,
I liked this one, thas solves a Word Square.

I did skip event 6 for here as it's excel and not much different,

I will do the 15 points option, finding the words horizontal and vertical in the wordsquare.

The script looks like this :


# Get Text

$text = gc C:\scripts\event_6b.txt

# reverse the text

$textR = $text | foreach {$a = $_.ToCharArray();[array]::reverse($a);[string]::join("",$a)}

# Get Vertical Text 

$textV = [string]::join("",(0..($text[0].length - 1) | foreach {$i=$_;$text | foreach {$_[$i]}}))

# reverse the vertical text

$VR = $V | foreach {$a = $_.ToCharArray();[array]::reverse($a);[string]::join("",$a)}

# find the words 

$found = @()
$words | foreach {if ($VR -match $_){$found += $_}}
$words | foreach {if ($text -match $_){$found += $_}}
$words | foreach {if ($textR -match $_){$found += $_}}
$words | foreach {if ($textV -match $_){$found += $_}}

# output results

$words | foreach {"$_ = $($found -contains $_)"}


after a comment from DontBotherMeWithSpam (thanks),
I came up with this replacement for the Find words section :

# find the words  

foreach ($word in $words){$Text,$textR,$textV,$vr | foreach {if($_ -match $word){$found += $word}}}

Fixed a naming typo in the origional script and the textV line is cleaned up.

$found = @()

# Arrange text 

$text = gc C:\scripts\event_6b.txt
$textR = $text | foreach {$a = $_.ToCharArray();[array]::reverse($a);[string]::join("",$a)}
$textV = [string]::join("",(0..($text[0].length - 1) | foreach {Foreach ($line in $text){$Line[$_]}}))
$textVR = $textV | foreach {$a = $_.ToCharArray();[array]::reverse($a);[string]::join("",$a)}

# find the words 

foreach ($word in $words){$Text,$textR,$textV,$textVR | foreach {if($_ -match $word){$found += $word}}}

# output results

$words | foreach {"$_ = $($found -contains $_)"}


Greetings /\/\o\/\/
Tags :

PS In 2 day's with Event 7's solution I will post I nice replacement for the last line.

Blogger /\/\o\/\/
by Importing the VisualBasic namespace you can use the VB string functions as StrReverse


[microsoft.visualbasic.strings] | gm -static


But I prefered the array trick above importing the namespace.

but if you are really attached to your VB string functions,
you can find them there

gr /\/\o\/\/
Blogger Sung Meister
Well I did try to do a different way of doing "# find the words" section using "measure-object" but failed miserably.

Here is what I worked on partially.
( $words | where {$_ -match "ADSI"} | measure-object -words) | & { foreach ($i in $input) { if ($i.words -ge 1) { "found" } else { "not found" } } }

I guess it's just a bit more obfuscated and pointless and stupid :)

Would you try to come up with an answer using "measure-object"? I would like to know how it can be done :)
Blogger /\/\o\/\/
No good Idea,

try this ;-)

foreach ($word in $words){$word;($Text,$textR,$textV,$vr | where {$_ -match $word} | measure-object -words).words}

you can go on from that to make it a one-liner

gr /\/\o\/\/
Blogger Sung Meister
I see that my approach on using "measure-object" was way off compared to your revised one-liners :)
Anonymous Anonymous
You should be able to use [string]::concat($a) in place of [string]::join("",$a). It's a tiny bit more self documenting. :-) --Keith Hill
Blogger /\/\o\/\/
thanks I missed that one,
I also removed an other small mistake, I have to add a LineFeed, to the end of each line, to prevent words found, across lines, so the line will look like this :

$textV = [string]::concat((0..($text[0].length - 1) | foreach {Foreach ($line in $text){$Line[$_]};"`n"}))

gr /\/\o\/\/
Post a Comment

<< Home


October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?