PoSH Challenge part 2 (Level 1-4 )
In former post PoSH Challenge part 1 I started this series, following the the python challenge site using PowerShell.
Looks like I got Xaegr started :PowerShell Challenge ( Translated )
and Doug Finke got challenged : The Python (PowerShell?) Challenge
For the readers who got Challenged also here are my answers for Level 1 to 4 :
* Spoiler warning for Level 1-4 * to spoil as less as possible I only provide the PowerShell code used, you can find the URL's to the Levels and Questions by following the Challenge from the first link to level one I provided by my Level 0 answer PowerShell script. I will not provide the URL's to the levels anymore for not spoiling the Original Python challenge site,
Level 1,
was not much of a problem after this :
$str = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj. "
[string]::join('',([char[]]$str |% {$c = ([int]$_ + 2);if($c -gt 122){$c -= 26}if($c -lt 97){$c-=2};[char]$c}))
Only problem is doing it completely right, if you go to Level 2 you can get access to the WIKI for former levels, you can see Python has a "string.maketrans" for this.
* User challenge * Make this also possible in PoSH like this :
PS > ("halr9000" ).maketrans(1)
ibms9000
and make sure this one also works ;-) :
PS > ("Eqmrb,`n Guhhwlqjv /\/\r\/\/" ).maketrans(-3)
Enjoy,
Greetings /\/\o\/\/
for a hint see : Code formatting test for how to add a script as a method to a type but of course a task like this asks for a more robust implementation (and sharing with community after ;-) )
Level 2
I made a record time on this one ;-) , I used the following command to figure out the "RARE" part of the question after I used a "Here String" to copy the text into the $str variable :
[char[]]$str | group
The output was enough to define RARE and give me the key to the next level ;-)
(Seeing the comments in the WIKI on the the python challenge site the PoSH version I found already there !, and Xaegr 's post. this saved me the "Alphabet solution";-) )
Level 3
Have a Problem ? ... Use a [RegEx] to Solve it ? ..... Now you have two problems !
[regex]::Matches($str,"[a-z][A-Z]{3}([a-z]{1})[A-Z]{3}[a-z]") |% {$_.groups[1].value}
As you might know I use regular expressions a lot, this one was not that hard for me
Level 4
I liked this one , after the series about TextScraping web sites from PowerShell I did on my blog, when I figured out what I needed to do it was not that hard anymore, I copied an example from that series and adapted it.
Fortunate I was smart enough to echo the source also to the console and could adapt my script to this version :
$nothing = "12345"
$wc = New-Object System.Net.WebClient
1..400 |% {
$r = $wc.DownloadString("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=$nothing")
if ($r -match 'divide') {
$nothing = $nothing /2
} else {
$nothing = $r.Replace("and the next nothing is ","")
}
$r
if ($r -match "html") {break}
}
I agreed that there is a Human factor in this script, As I changed it for this purpose, in reaction to the former output so the script could not solve it on it's own.But in this case I think it is mandated by the Question, and also the way I did build the TextScraping examples,
In this I go much further and convert the input data from the HTML pages into complete custom objects with properties that I can use in PowerShell, download the raw data of a web page that has information you need, look at the structure and start building the Regex by trail and error.
If you liked this level, be sure to check the TextScraping series for more advanced examples.
After a quick look at level 5, (and not knowing where to start ) I called it a day and stopped, when I find some time to resume the Challenge, I will post my results for the level again here on my blog.
It was nice to see that I got more people started on this Challenge by my first post, and sharing the experiences and solutions they came up with (Feel free to beat me to them ).
And of course I hope to see many of you at the "real" Winter Scripting Games 2008 , and that we will have a large PowerShell division (aiming to be Larger as the VbScript division this year, would be to early ? ;-) )
Enjoy,
Greetings /\/\o\/\/