This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
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 QuestOrigial 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
3
-1
and this one I like even more,
Event 4: Text File Tug-of-WarOriginal 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
objFile.Close
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
objFile.Close
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 SCRIPTING GUYS 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 GUYS.
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 : Monad msh