The PowerShell Oneliner Contest 2017 is over and we have a winner. The three tasks ranged from pretty easy to extremely difficult, and many quickly discovered the plethora of barriers that make it difficult to successfully manipulate the pipeline, especially when dealing with math problems. Some though came up with working solutions that are short and imaginative.
Let me announce then the top 5 PowerShell monks in the contest:
1st - Ka-Splam from UK
2nd - Simon Wåhlin (@SimonWahlin) from Sweden
3rd - Brian Scholer (@BrianScholer) from USA
4th - Nathan Ziehnert (@theznerd) from USA
5th - Bartek Bielawski (@bielawb) from Poland
Congratulations to Ka-Splam for becoming the 2017 oneliner champion with the following solutions:
TASK 1: MANIPULATING OUTPUT - 42 chars
gwmi win32_share|%{$_-replace'root.*?"|"'}TASK 2: MANDELBROT JOKE - 53 chars
"The B in$(($b=$question|% s*g 26 21)) stands for$b."TASK 3: TEXT MINING - 179 chars
foreach($w in $t1,$t2-split($x='\W+')|sort -u){$n=,($t+=($a=($t1-split$x-eq$w).count)*($b=($t2-split$x-eq$w).count)),($l+=$a*$a),($m+=$b*$b)}$t/([math]::Sqrt($l)*[math]::Sqrt($m))
Congratulations again to Ka-Splam: the Powershell ebook from Mike F Robbins is yours!
I would like also congratulate Simon Wåhlin for writing the shortest answer to Task 2 - 50 chars:
gv q* -v|% Su* 26 21|%{"The B in$_ stands for$_."}I am also pleased to announce that the top three competitors have accepted to be my guests on this blog, so stay tuned for their posts and, believe me, there is a lot to learn in perspective, from their approach to the tasks to a profusion of tips and tricks to make your PowerShell high caliber!
- Ka-Splam guest post scheduled for 27th Nov
- Simon guest post scheduled for 30th Nov
- Brian guest post scheduled for 5th Dec
I can't close this post without a special thank to Jakub Jares from the Czech Republic (@nohwnd) for his great involvement in the setup of the Pester-based test environment.
Hm, I was messing with replaces for task 1 and just didn't quite get the pattern right (I ultimately went a different direction). Using Ka-Splam's awesome pattern, I'd make a small modification to remove ForEach-Object and do this at 38 characters:
ReplyDelete(gwmi win32_share)-replace'root.*?"|"'
I don't understand expression 'root.*?"|"'
DeleteCould you please explain?
This is a regex, regular expression.
DeleteIt's split in two by the alternator operator '|'.
In the first half, it does matches the string starting with the word 'root', followed by n chars until it matches the double-quote char.
In the second half it just matches the double-quote char"
Both these halves are replaced with nothing, so:
\\DESKTOP\root\cimv2:Win32_Share.Name="ADMIN$"
becomes:
\\DESKTOP\ADMIN$
Hth
Woah! Brilliant spot Brian!
ReplyDelete