Mark Minasi's Reader Forum
Mark Minasi's Reader Forum
Home | Profile | Register | Active Topics | Active Polls | Members | Search | FAQ | Minasi Forum RSS Feed
 All Forums
 HALP! Questions on Windows and Windows Server
 PowerShell
 Powershell Golf Contests

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Note: please do not cross-post.
Cross-postings will be deleted and ignored.
Thanks for helping to keep this forum junk-free!
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
sixdoubleo Posted - 11/09/2011 : 3:32:51 PM
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?
12   L A T E S T    R E P L I E S    (Newest First)
sixdoubleo Posted - 11/11/2011 : 1:36:45 PM
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



Xenophane Posted - 11/11/2011 : 04:13:19 AM

$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
sixdoubleo Posted - 11/10/2011 : 1:10:59 PM
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.
lady_mcse Posted - 11/10/2011 : 12:36:03 PM
Shucks, and I thought it meant get colossal amounts of cash, and embrace it. Period. End quote.
jhicks Posted - 11/10/2011 : 08:42:23 AM
I'm glad you clarified because I spent a few minutes trying to determine if this was something real.
JSCLMEDAVE Posted - 11/10/2011 : 08:19:47 AM
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...

jhicks Posted - 11/10/2011 : 08:15:09 AM
Absolutely. A cryptic one liner has no value unless you explain it.
JSCLMEDAVE Posted - 11/10/2011 : 07:59:06 AM
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...
jhicks Posted - 11/10/2011 : 06:59:07 AM
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.
Xenophane Posted - 11/10/2011 : 04:00:02 AM
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 :)
jhicks Posted - 11/09/2011 : 4:49:35 PM
Why not post periodic challenges right here?
sixdoubleo Posted - 11/09/2011 : 4:09:06 PM
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.

Mark Minasi's Reader Forum © 2002-2011 Mark Minasi Go To Top Of Page
This page was generated in 0.08 seconds. Snitz Forums 2000