Mark Minasi's Reader Forum
Mark Minasi's Reader Forum
Home | Profile | Register | Active Topics | Active Polls | Members | Search | FAQ | Minasi Forum RSS Feed
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 HALP! Questions on Windows and Windows Server
 PowerShell
 Powershell Golf Contests
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sixdoubleo
Major Contributor

USA
859 Posts
Status: offline

Posted - 11/09/2011 :  3:32:51 PM  Show Profile  Click to see sixdoubleo's MSN Messenger address  Send sixdoubleo a Yahoo! Message  Reply with Quote
Anybody know of any Powershell forums where they do regular "golf" contests? (Writing a script to perform a specific task with as few characters as possible). They have this on the Kix forum I go to and I always found it a fun, challenging way to hone your skills.

Furthermore, they would always come up with some really interesting challenges that had application in things like encoding, encryption, string manipulation, etc.

I'm doing more work in Powershell now, and as I try to come up to speed with it, I was wondering if such a forum existed?

sixdoubleo
Major Contributor

USA
859 Posts
Status: offline

Posted - 11/09/2011 :  4:09:06 PM  Show Profile  Click to see sixdoubleo's MSN Messenger address  Send sixdoubleo a Yahoo! Message  Reply with Quote
I see Microsoft has a Scripting Games event that happened in April.

http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/10/2011-scripting-games-all-links-on-one-page.aspx

Might be cool to try out next year, but also would be nice to find something that happens monthly or so.
Go to Top of Page

jhicks
Here To Stay

USA
283 Posts
Status: offline

Posted - 11/09/2011 :  4:49:35 PM  Show Profile  Visit jhicks's Homepage  Reply with Quote
Why not post periodic challenges right here?

Jeffery Hicks
Windows PowerShell MVP

http://jdhitsolutions.com.blog
http://twitter.com/JeffHicks
http://www.ScriptingGeek.com
Now Available: Managing Active Directory with Windows PowerShell: TFM 2nd ed.
Go to Top of Page

Xenophane
Honorable But Hopeless Addict

Denmark
3070 Posts
Status: offline

Posted - 11/10/2011 :  04:00:02 AM  Show Profile  Visit Xenophane's Homepage  Send Xenophane an ICQ Message  Reply with Quote
Having been a judge on the 2011 Scipting Games contest I can tell you "golf" entries didn't get the highest of scores...

We put a lot of emphasis on readability :)

Microsoft Powershell MVP

SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>

You can read my blog at www.xipher.dk
Go to Top of Page

jhicks
Here To Stay

USA
283 Posts
Status: offline

Posted - 11/10/2011 :  06:59:07 AM  Show Profile  Visit jhicks's Homepage  Reply with Quote
Agreed. Brevity is not always a virtue with a script. But when running a command at the prompt, it can be. Granted, it can get pretty arcane but I guess that's where the fun is. As long as people realize that these types of expressions are NOT what you need to know to use PowerShell.

Jeffery Hicks
Windows PowerShell MVP

http://jdhitsolutions.com.blog
http://twitter.com/JeffHicks
http://www.ScriptingGeek.com
Now Available: Managing Active Directory with Windows PowerShell: TFM 2nd ed.
Go to Top of Page

JSCLMEDAVE
Administrator

USA
6116 Posts
Status: online

Posted - 11/10/2011 :  07:59:06 AM  Show Profile  Visit JSCLMEDAVE's Homepage  Click to see JSCLMEDAVE's MSN Messenger address  Reply with Quote
Perhaps make the comments and help entries exempt.

So if your script is -

gc $_.{{$!}}"." but you have three paragraphs to explain it with .Example , that is ok..?

Just a thought...

Tim-

“This too shall pass"
Go to Top of Page

jhicks
Here To Stay

USA
283 Posts
Status: offline

Posted - 11/10/2011 :  08:15:09 AM  Show Profile  Visit jhicks's Homepage  Reply with Quote
Absolutely. A cryptic one liner has no value unless you explain it.

Jeffery Hicks
Windows PowerShell MVP

http://jdhitsolutions.com.blog
http://twitter.com/JeffHicks
http://www.ScriptingGeek.com
Now Available: Managing Active Directory with Windows PowerShell: TFM 2nd ed.
Go to Top of Page

JSCLMEDAVE
Administrator

USA
6116 Posts
Status: online

Posted - 11/10/2011 :  08:19:47 AM  Show Profile  Visit JSCLMEDAVE's Homepage  Click to see JSCLMEDAVE's MSN Messenger address  Reply with Quote
quote:
Originally posted by jhicks

Absolutely. A cryptic one liner has no value unless you explain it.



Just to confirm what may be obvious to many, this gc $_.{{$!}}"." is just random entries...


Tim-

“This too shall pass"
Go to Top of Page

jhicks
Here To Stay

USA
283 Posts
Status: offline

Posted - 11/10/2011 :  08:42:23 AM  Show Profile  Visit jhicks's Homepage  Reply with Quote
I'm glad you clarified because I spent a few minutes trying to determine if this was something real.

Jeffery Hicks
Windows PowerShell MVP

http://jdhitsolutions.com.blog
http://twitter.com/JeffHicks
http://www.ScriptingGeek.com
Now Available: Managing Active Directory with Windows PowerShell: TFM 2nd ed.
Go to Top of Page

lady_mcse
Old Timer

636 Posts
Status: offline

Posted - 11/10/2011 :  12:36:03 PM  Show Profile  Reply with Quote
Shucks, and I thought it meant get colossal amounts of cash, and embrace it. Period. End quote.

Anne O'Day
MCITP: SharePoint 2010
Go to Top of Page

sixdoubleo
Major Contributor

USA
859 Posts
Status: offline

Posted - 11/10/2011 :  1:10:59 PM  Show Profile  Click to see sixdoubleo's MSN Messenger address  Send sixdoubleo a Yahoo! Message  Reply with Quote
Understood Claus...I'm using the term "golf" just as a generic term to describe scripting challenges in general. Many times in the absence of some impartial judge (as in the case of the scripting games) code length is the only measure you have that's fair.

While I write VERY verbose code for my production work, I still do enjoy some of the script golf exercises as they really challenge you to think about how to construct your logic in a more efficient manner. Some of the clever methods people come up with really are amazing. And while I understand that the shortest script isn't always the fastest script, the golfing exercise itself can be a lot of fun and help you improve your skills.

Over on the Kix forums, they're doing this one on Whitespace Obfuscation, which itself is pretty fascinating.

http://kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=203581&fpart=1

For their golf contests they've written a scoring engine in kix that calls your script and feeds it a standard set of test validations and then spits out a score. They do a private round for a week where you only post the results of your test, but nobody posts any code. Then after a week it goes to the public phase where everybody posts their code along with tests. At that point you're free to "steal" each others code and try to golf it down further.

Anyway, I wrote mine and while I was nearly twice as large as the others and not competitive at all, I was happy just to get the thing working and pass the test cases :)

I was going to go ahead and do it in Powershell just as a learning exercise to see how small I could get it.

Edited by - sixdoubleo on 11/10/2011 1:11:49 PM
Go to Top of Page

Xenophane
Honorable But Hopeless Addict

Denmark
3070 Posts
Status: offline

Posted - 11/11/2011 :  04:13:19 AM  Show Profile  Visit Xenophane's Homepage  Send Xenophane an ICQ Message  Reply with Quote

$InStr = "This is my very secure string that I do not want anyone to read :)"
$SecureString = ([string]::Join("", ($InStr.ToCharArray() | % {"$([Convert]::ToString([string][int]$_,2))".Padleft(8,"0")}))) -replace 1," " -replace 0, "`t"

$SecureString 


$UnSecureString = [string]::Join("",([regex]::Split($($SecureString -replace " ",1 -replace "`t",0), "(\d{8})") | % { if ($_){[Char][Convert]::ToInt64($_,2)}}))
$UnSecureString

Microsoft Powershell MVP

SIG> George Bernard Shaw : The power of accurate observation is commonly called cynicism by those who have not got it. </SIG>

You can read my blog at www.xipher.dk
Go to Top of Page

sixdoubleo
Major Contributor

USA
859 Posts
Status: offline

Posted - 11/11/2011 :  1:36:45 PM  Show Profile  Click to see sixdoubleo's MSN Messenger address  Send sixdoubleo a Yahoo! Message  Reply with Quote
quote:
Originally posted by Xenophane


$InStr = "This is my very secure string that I do not want anyone to read :)"
$SecureString = ([string]::Join("", ($InStr.ToCharArray() | % {"$([Convert]::ToString([string][int]$_,2))".Padleft(8,"0")}))) -replace 1," " -replace 0, "`t"

$SecureString 


$UnSecureString = [string]::Join("",([regex]::Split($($SecureString -replace " ",1 -replace "`t",0), "(\d{8})") | % { if ($_){[Char][Convert]::ToInt64($_,2)}}))
$UnSecureString




Nice Claus! Now excuse me while I sit here and figure out what it does :)

I wrote the encrypt part in PS and it looks similar to yours, although I still have a ton to learn. For instance, I see you are going straight from a character to binary, whereas I'm taking the decimal value as a separate step and converting that to binary.

I also didn't think about using replace and instead used a switch statement. I also am obviously a bit old-skool in my concatenation techniques with "$o=$o+=..." :) Good stuff though.

Here's mine (just the encrypt, didn't have time to do the decrypt)


function e{param($t)[int[]][char[]]$t|foreach{[Convert]::ToString($_, 2).PadLeft(8,"0").ToCharArray()|foreach{switch($_){"0"{$o=$o+=[char]32}"1"{$o=$o+=[char]9}}}};return $o}

$x = e "Hello World"
Add-Content "C:\Scripts\WOEncode.txt" $x



Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Mark Minasi's Reader Forum © 2002-2011 Mark Minasi Go To Top Of Page
This page was generated in 0.12 seconds. Snitz Forums 2000