/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" 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 lin... "," 2006 Winter Scripting Games "," Check spelling with MSN Search from MSH (Part 3) "," Search with MSNSearch Web API from MSH (Part 2) "," ")

Monday, February 20, 2006


Scripting Games week 2

and the solutions or another 2 events of the The 2006 Winter Scripting Games are in :
and again, I did the answers in MSH also,.... and Yes one-liners ;-)

Event 3 The Quadratic Quest

Origial answer :

a = Wscript.Arguments.Item(0)
b = Wscript.Arguments.Item(1)
c = Wscript.Arguments.Item(2)

numAnswer1 = ((-1 * b) + (Sqr((b^2) - 4 * a * c))) / (2 * a)
Wscript.Echo numAnswer1

numAnswer2 = ((-1 * b) - (Sqr((b^2) - 4 * a * c))) / (2 * a)
Wscript.Echo numAnswer2

and the MSH answer is :

function QQ ($a,$b,$c) {$d = [math]::Sqrt([math]::Pow($b,2) - 4 * $a * $c);(-$b + $d) / (2*$a);(-$b - $d) / (2*$a)}

MSH>qq 2 -4 -6

and this one I like even more,

Event 4: Text File Tug-of-War

Original answer :

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Event_4.txt", ForReading)

strContents = objFile.ReadAll

strContents = Replace(strContents, "Gusy""Guys")
strContents = Replace(strContents, vbCrLf, " ")
strContents = UCase(strContents)

Set objFile = objFSO.OpenTextFile("C:\Scripts\Event_4.txt", ForWriting)
objFile.Write strContents

and the MSH answer is:

"$(gc C:\Scripts\Event_4.txt)".toUpper().replace('GUSY','GUYS') | out-file C:\Scripts\Event_4.txt

Cool or not ?,
we just cast the get-content of the file to a string, and just call his methods.

the result is like this :

MSH>type C:\Scripts\Event_4.txt

The Scripting Gusy are pleased
to announce the 2006 Winter
Scripting Games to be held
February 13-24 at the TechNet
Script Center. This event is
sponsored by the Microsoft
Scripting Gusy.

MSH>"$(gc C:\Scripts\Event_4.txt)".toUpper().replace('GUSY','GUYS') | out-file C:\Scripts\Event_4.txt

MSH>type C:\Scripts\Event_4.txt


the next events will be bit harder to put one one line (at reast readable ;-), as we have the ";" )
but still I think they will be to do on MSH also.

keep you posted ;-)

gr /\/\o\/\/
Tags :

Blogger DontBotherMeWithSpam
Lol. it's just great to see that it's easier and shorter to do the samething in MSH. :)

Anyways, for "Event 4",
I think you have missed out something in MSH version.

"strContents = Replace(strContents, vbCrLf, " ")
" was not in MSH version

so i think the answer should be
MSH>"$(gc C:\Scripts\Event_4.txt)".toUpper().replace('GUSY','GUYS').replace([Environment]::NewLine, " ") | out-file C:\Scripts\Event_4.txt
Blogger /\/\o\/\/

alreay happens when you cast it in the string with "$()"


gr /\/\o\/\/
Blogger DontBotherMeWithSpam
Hey, that's pretty weird... I never knew that "$()" would actually remove newline characters... :)

That's certainly uncalled for.
Is it supposed to be an expected behavior? or is it mentioned on any docmentation?
Anonymous Anonymous
I'm also following the scripting games and did ask (but recieved no reply) if we could submit answers in Monad (the rules did not say what script language you had to use when I down loaded them.) I would be interested to you Monad answer to Event 7. Please do post it.

Jeremy Pack
Blogger /\/\o\/\/

I got event 7 on one line in MSH, as well unsorted as sorted ;-)

my VB one was a bit longer ;-)

gr /\/\o\/\/
Anonymous hayate
It seems that every Cr/Lf pair Will be translated to two SPACEs when using $()
Blogger /\/\o\/\/
Not with the original text file,
of you copy it from my blog there is already a space behind.

gr /\/\o\/\/

PS that's also the reaon that I do not use the backtick on the end of te line as it will fail as pasted from the blog
Post a Comment

Links to this post:

Create a Link

<< 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?