Wednesday, June 24, 2015

Powershell Oneliner Contest 2015 - Win a Hyper-V book

I have always enjoyed taking part in most of the Powershell contests out there since Powershell is kind of a recreational administration language to me. I am thinking, for example, of the fun I had taking part in the oneliner contest (which I won) organized by fellow MVP Mike F Robbins, or of the Powershell Golf organized in 2013 by Robert Robelo on Twitter.
 
THE IDEAS BEHIND THE CONTEST
 
Being quite proud of my blog, and despite the fact that I am more of a system administrator than a developer, I have unilaterally decided to organize my self-hosted, self-managed Powershell Oneliner Contest.
 

The three ideas behind this game are that:
  1. experienced competitors (and I, of course!) should come away with a lot of tips from the brightest Powershell minds that will hopefully take part in the event
  2. novice Powershell scripters should learn that persistence pays off when looking for a solution to such a contest
  3. this is a fairly good occasion to sharpen your skills for the soon-to-start Powershell Scripting Games held by the Powershell.org community
GENERAL RULES
 
  • The contest is split into three tasks. Each task consists of a simple scenario for which you have to produce a oneliner solution.
  • Submit your solutions via a comment to this blog article by 11AM (PDT) on Wednesday, July 1st, which is the deadline.
  • You MUST submit only one task solution per comment, so that I can easily see who was the first to submit the shortest solution on a per-task basis.
  • Should you find a shorter oneliner to solve a task you are allowed to post additional comments (just remember to sign your comments so that I know who's who).
  • Aliases are of course accepted
  • Backticks accepted for readability
  • No semi-colons
  • UPDATE - No Here-String
  • UPDATE - Please don't sign your comments as Unknown or I won't be able to know who you are.
  • If you use a Powershell version other than v4, I am okay with it, but please mention it in the comment so that I can test it on the same version. Powershell v5 is welcome.
  • Entries (comments) will not be made public until after the submission deadline.

SCORING
  • The shortest solution in terms of chars wins.
  • The first person to produce the shortest working solutions to a task will get 1 point, the second 2 points, the third 3 points and so on.
  • The person with the lowest total score over the three mandatory tasks will be the winner.
  • The winner will be announced on Saturday, July 4th on this blog and the prize will be awarded at that time.
  • I'll be the only judge.

THE PRIZE
 
What? Is there a prize? Yes, of course. The prize will be a printed copy of the excellent book 'Hyper-V Best Practices' (5-Stars on amazon.com) by fellow MVP Benedict Berger  (@Benedict_Berger) offered by Packt Publishing!!!
I was the reviewer of the book as well of the ton of Powershell code it contains. I can tell you this is the book to read in these Hyper-V times!


As a bonus, and if the winner agrees, he/she will intervene as a guest blogger on this blog and will explain how one goes about learning the hidden bits of Windows Powershell. Sounds cool, doesn't it?

Let's now dive into the contest tasks.
 
TASK 1 - Who's taller?
 
This is a rather easy challenge and I hope it will make for a good warm-up session for your Powershell muscles, especially if you are a beginner. Given a $n variable showed below, write the shortest possible oneliner that outputs the absolute value of the largest double-precision floating-point number in the array.
$n = -1,-2,-5,-8.9,'b',-9.11,-6,-3,-2,-9.1,-1,-1.4,'a'

Expected output
Task-specific rules
  • The object in the output can be of any type
  • UPDATE - The one-liner must work also with different values of $n

TASK 2 - Can you count to five?

Time to delve into something harder. Write the shortest possible Powershell oneliner that outputs the number 12345.

Expected output
 
Task-specific rules
  • You are not allowed to use the digits 0 to 9 in your oneliner
  • The object in the output must be of type Int32
  • Your displayed output shouldn't contain any other char

TASK 3 - Powershell is the secret word

I hope that by this time you are enjoying the competition. It's time for the last hard task. Write the shortest possible Powershell oneliner that outputs the word 'PowerShell' starting from a text string composed only of uppercase Xs' and whitespaces.

Expected output
Task-specific rules
  • The string composed of X's and whitespaces must be part of the oneliner (backticks accepted!) and not be a variable defined on a separate line
  • You can use as many X's and empty spaces you like or need
  • P and S in the output must be uppercase
  • UPDATE - No Here-String
  • UPDATE - I consider jokes answers like "X "|%{"Powershell"}
On your marks, set, go! And remember to have fun, it's just a game meant to produce something useful for the growing and growing Powershell community!

UPDATE - Check-Task Function

I have decided to update this blog post with a function that will allow you to check if your proposed solutions are correct in terms of output and respect the task assignments. Kudos for this function go to my friend Joey!

function Check-Task ([int] $Task, [scriptblock] $Command) {
        $n = -1,-2,-5,-8.9,'b',-9.11,-6,-3,-2,-9.1,-1,-1.4,'a'
        $result = & $command
        $check = $false
        switch ($Task) {
            1 { $check = $result -eq '1.4' -or 
                [double]::Parse("$result") -eq 1.4 }
            2 {
                $check = ($result -is [int] -and $result -eq 12345) -and
                    ("$Command" -notmatch '[0-9]')
              }
            3 {
                $check = ($result -is [string] -and $result -ceq 'PowerShell') -and
                    ("$Command" -match '([''"])[X`\s]+\1')
            }
        }
        if (!$check) {
            Write-Host -Fore Yellow "Expected: $((1.4,12345,'PowerShell')[$Task - 1])"
            Write-Host -Fore Red    "Actual:  $result"
        }
        $color = ('Red','Green')[$check]
        Write-Host -Fore $color ('{0,4}: {1}' -f "$Command".Trim().Length,$command)
    }
Sample usage:
Check-Task 1 { $n.gettype() }
Do not hesitate to test your solutions before posting them to my blog! Better safe than sorry.

SPREAD THE WORD

If you want to give some visibility to this contest, feel free to twit about it. You can use the hashtags #poshcontest2015 and #powershell so that other competitors can share their thoughts (not the solutions of course!).

Thanks again to Packt Publishing (and to Mary in particular) for sponsoring this event!

UPDATEClick here to find the winner's name and his solutions!

160 comments:

  1. $n | ? {$_ -is [Double]} | sort | select -L 1

    ReplyDelete
  2. "$([int]$true)$($([int]$true)+$([int]$true))$($([int]$true)+$([int]$true)+$([int]$true))$($([int]$true)+$([int]$true)+$([int]$true)+$([int]$true))$($([int]$true)+$([int]$true)+$([int]$true)+$([int]$true)+$([int]$true))"

    I'm not proud :D

    ReplyDelete
  3. (80,111,119,101,114,83,104,101,108,108 | % {[char]$_}) -join ''

    ReplyDelete
  4. ("X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXX XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -split ' ' | % {[char]$($_.length + 79)}) -join ''

    Please erase my previous attempt, I didn't read the rule :)

    ReplyDelete
  5. "$('a'.length)$('aa'.length)$('aaa'.length)$('aaaa'.length)$('aaaaa'.length)"

    Is far shorter than my previous attempt :)

    ReplyDelete
  6. #1
    -($n | ? {$_ -is [Double]} | sort | select -L 1)

    ReplyDelete
  7. #2
    [int]"$('a'.length)$('aa'.length)$('aaa'.length)$('aaaa'.length)$('aaaaa'.length)"

    ReplyDelete
  8. #3
    ("X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXX XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -split ' ' | % {[char]$($_.length + 79)}) -join ''

    ReplyDelete
  9. Exo2: [int][char]"v" * [int][char]"i" - [int][char]"-"

    C'est moi (notremaison)

    ReplyDelete
  10. Task 3

    ('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' -split ' ' | % {[char]($_.length)}) -join ''

    On v5

    ReplyDelete
  11. Task 3 Amended:
    ('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'-split' '|%{[char]($_.length)})-join''

    on V5

    ReplyDelete
  12. Exo 1: $n -replace "-" | ? {$_ -like "*.*"} | sort | select -First 1

    ReplyDelete
  13. Task 2:

    [int]([String]("b","c","d","e","f"|%{("abcdef").indexof($_)})).Replace(" ","")

    No numbers used in one liner, returns an Int32, and has no other characters. Like me - it is ugly, but it is functional ;)

    ReplyDelete
  14. Dernier Exo
    @"
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXX

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXX

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XX

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXX

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXX

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XX

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXX

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    XXXXXXXXX
    "@ -split " " | % { Write-Host "$([char]$_.split('X').count)" -NoNewline }

    ReplyDelete
  15. Task 1: 43 chars

    [math]::Abs(($n|sort|?{$_-is[double]})[-1])

    ReplyDelete
  16. -join(-split'X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXX XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'|%{[char]($_.Length+79)})

    ReplyDelete
  17. Task 1 (Powershell V5)
    ($n |%{$_.ToString()} | where {$_.contains('.')}|%{[math]::Abs($_)} | Sort-Object)[0]|%{([string]($_)).replace(".",",")}

    ReplyDelete
  18. Task 2 Powershell V5

    [int32]("$([byte][char]'{')"+"$([byte][char]'-')")

    ReplyDelete
  19. Task 3 (Powershell V5)

    ((@"


    XXXXXXX

    XX





    "@)|%{$_ -split "`n"}|%{if($_.contains(' ')){
    "$([char](112-($_.length-1)))"
    }else{
    "$([char](112+($_.length-1)))"
    }}) -join ''

    ReplyDelete
  20. Task 2 bis (Powershell V5)

    [int]("$([byte][char]'{')"+"$([byte][char]'-')")

    ReplyDelete
  21. Task3 bis (Powershell V5)

    ((@"


    XXXXXXX

    XX





    "@)|%{$_ -split "`n"}|%{if($_.contains(' ')){"$([char](112-($_.length-1)))"}else{"$([char](112+($_.length-1)))"}}) -join ''

    ReplyDelete
  22. (($n|?{$_-is[double]})[-1])*-1
    [int]([char[]](49..53)-join"")
    ("X X"|%{$ShellId[10..19]})-join""

    ReplyDelete
  23. Task 2: 78 chars

    icm{param($z)[int]"${z}xdacf"-[int]"${z}xaaa$z"+[int]"${z}xa"}-arg $null.Count

    ReplyDelete
  24. Task 3: 19 chars

    "X"|%{"PowerShell"}

    ReplyDelete
  25. [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("MTIzNDU="))

    ReplyDelete
  26. [int][Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("MTIzNDU="))

    ReplyDelete
  27. Task 2 (shortened): 76 chars

    icm{param($z)[int]"${z}xdacf"-[int]"${z}xaaa$z"+[int]"${z}xa"}-arg ([int]"")

    ReplyDelete
  28. TASK 1 ($n|?{$_.GetTypeCode() -eq "Double"}|measure -max).maximum

    ReplyDelete
  29. TASK 1 ($n|?{$_.GetTypeCode() -eq "Double"}|measure -max).maximum

    ReplyDelete
  30. My 33char solution that is less generic that my first:
    -(($n|?{$_-is[double]}|sort)[-1])

    ReplyDelete
  31. 1.
    $n|?{$_-Match'\.'}|%{$_-as[double]}|measure -ma|select -exp ma*

    ReplyDelete
  32. 2.
    [int]::parse(-join("▲'".tochararray()|%{[int]$_}),'He')
    cut and paste can't set characters below ascii 32, and I must comment that in doube quotes after -join must be character with ascii code 30 and single quote ' (ascii 39) solution is 55 characters long

    ReplyDelete
  33. Task 2 (41 chars):
    [int]"$([int][char]'{')$([int][char]'-')"

    ReplyDelete
  34. 2. even shorter - 50 chars
    [int]::parse(-join("▲ ","'"|%{[int][char]$_}),'He')

    ReplyDelete
  35. 3.
    -join('X XXXX X X XX X XX X XX X XXX XX X X XX X XX'-replace' ',1-replace'X',0-split'(\d{6})'|?{$_}|%{[char][convert]::tobyte("1$_",2)})

    ReplyDelete
  36. TASK 1 - Who's taller?
    PowerShell v5

    Answer:
    $n[11]*-1

    Alexander Johansson (aleqs__@outlook.com)

    ReplyDelete
  37. Task 3 (195 chars):
    for($i=0;$i-lt80;$i+=8){write-host([char][convert]::ToInt32(" X X XX XXXX XXX XXX XX X X XXX X X X XX XX X XX X X XX XX XX XX ".replace(" ",0).Replace("X",1).Substring($i,8),2))-N}

    Not sure if it's allowed with the semicolon in the for statement. If not I'd like to hear it so I can take another crack.

    ReplyDelete
  38. There has to be easier/better way to do #1, but here is my attempt:
    [math]::Abs(($n|?{$_-is[double]}|sort)[-1])

    ReplyDelete
  39. And last but not least - #3
    [regex]'(.{3})'|% Re* 'X X XXX X X XXXXXXX '{switch($args.groups[1].value){'X '{'P'}' X '{'o'}' X'{'w'}'XX '{'e'}'X X'{'r'}' XX'{'S'}'XXX'{'h'}' '{'l'} }}
    (should read as one line)

    ReplyDelete
  40. Solution1 30 characters
    ($n|?{$_-is"Double"}|Sort)[-1]

    ReplyDelete
  41. Solution 2 - 14 characters
    [int][char]"〹"

    ReplyDelete
  42. Solution1 correction. Did not have absolute value before. Nw solution below
    ($n|?{$_-is"Double"}|Sort)[-1]*-1

    ReplyDelete
  43. Solution1 new correction. My second entry for question 1 works but only because the number in the array is of negative value. Multiplying by -1 works in this case. If the Largest Double was positive then my solution wouldn't work. New solution is 43 characters:
    [math]::abs(($n|?{$_-is"Double"}|Sort)[-1])

    ReplyDelete
  44. My solution for Task 1:
    ($n|?{$_-is[Double]}|%{[math]::abs($_)}|sort)[-1]
    Using Powershell 5.

    ReplyDelete
  45. Solution3: Doesn't fell like a winner :) 1094 characters
    "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX".Split(" ")|%{Write-Host $([char]$_.Length)-NoNewline}

    ReplyDelete
  46. TASK 2 - Can you count to five?
    PowerShell v5

    Answer:
    [int][char]'〹'

    Alexander Johansson (aleqs__@outlook.com)

    ReplyDelete
  47. Dont know if my previous entry for number three was accidentally submitted as unknown..
    If so, here it is again, My solution for Task 3:
    -join((("X X XXXXX X X X X XX X X XX XX X XX X X XXXX XX X X X XXX X XX"-replace"X","0"-replace" ","1")-split"(\w{8})").split("",[StringSplitOptions]'RemoveEmptyEntries')|%{[char][convert]::toint16($_,2)})

    Unig Powershell 5.

    ReplyDelete
  48. Task3

    ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XX XXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX "|Select-String '((.)+?)\1+' -AllMatches | %{$_.matches}|%{"$([char](121-($_.value.length)))"})-join ''

    ReplyDelete
  49. ($n|?{$_.GetType().Name -eq "Double"}|sort -Desc)[0]

    ReplyDelete
  50. Task 2 : [int]((("a".Length)..("Hello".Length)) -Join "")

    ReplyDelete
  51. TASK 1 - Who's taller?
    PowerShell v5
    I update the answer since you added "The one-liner must work also with different values of $n" which I think is a bit unfair since I didn't see it until now! :D

    Answer:
    (($n|?{$_-is[double]})-replace'-'|sort)[0]

    Alexander Johansson (aleqs__@outlook.com)

    ReplyDelete
  52. #1 max value in $n
    $n -match '\d'|measure -Ma|% ma*
    # @KevinMarquette

    ReplyDelete
  53. #2 count to five
    [int][char]'〹'
    @KevinMarquette

    This is kind of cheating but technically correct. Have to copy/paste this into the shell (and there is a chance the encoding will be lost along the way). I found this by running this command:
    [char]12345

    ReplyDelete
  54. #3 produce Powershell using a string of X and spaces

    # joke submit:
    "X "|% "Powershell"

    # more in the spirit of the contest
    (0,31,39,21,34,3,24,21,28,28 | % -B{$a="X "|%{[int][char]$_[1]..([int][char]$_[0]*2)}|%{[char]$_} }{$a[$_+48]} ) -join ''
    @KevinMarquette

    This one takes the string "X " and converts it into the alphabet, then uses the numbers to index the letters. Not very elegant but it works.

    ReplyDelete
  55. # 3 the string Powershell starting from the string "X "
    # I looked at the rules and if you will allow it, I want to change my response to this

    "X "|% "Powershell"

    @KevinMarquette

    ReplyDelete
  56. Task 1 (91 characters)

    ($n |%{"$_"}|?{$_.contains('.')}|%{[math]::Abs($_)}|Sort)[0]|%{("$($_)").replace(".",",")}

    ReplyDelete
  57. #1 maximum value of the floating point numbers as an absolute value

    $n|?{$_-is [double]}|measure -Ma|% {[math]::abs($_.maximum)}

    @KevinMarquette
    My first one was flawed. Didn't read the rules close enough.

    ReplyDelete
  58. Task 3 (265 chars)

    ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XX XXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX "|sls '((.)+?)\1+' -A|%{$_.matches}|%{"$([char](121-($_.value.length)))"})-join''

    ReplyDelete
  59. Task 1 (74 chars, @mickyballadelli)

    "$(($n |?{$_-match'\d'}|%{[math]::Abs($_)}|Sort -D)[0])".Replace(".",",")

    ReplyDelete
  60. Task 1 (52 chars) @mickyballadelli

    ($n |?{$_-match'\d'}|%{[math]::Abs($_)}|Sort -D)[0]

    ReplyDelete
  61. J'avais un gros bug sur le dernier, désolé:

    Task 1 (57 chars) @mickyballadelli

    ($n|?{$_-match'\d+\.\d+'}|Sort -D)[0]|%{[math]::Abs($_)}

    ReplyDelete
  62. Task 2 (46 chars) @mickyballadelli

    [int]([byte][char]'{',[byte][char]'-'-join'')

    ReplyDelete
  63. My solution for Task 2:
    -join([int][char]'{',[int][char]'-')
    Using Powershell 5

    ReplyDelete
  64. ....And i just realized my mistake... New (Hopefully working) solution to Task 2:
    [int](-join([int][char]'{',[int][char]'-'))
    Using Powershell 5

    ReplyDelete
  65. Task 1, 34: ($n-match'\.'|sort)[-1]-replace'-'

    ReplyDelete
  66. Task 2, 39: +-join([char[]]'+,-./'|%{$_-[char]'*'})

    ReplyDelete
  67. # Johan Akerstrom, jakerstrom@gmail.com
    # I'm on PS 5.0

    #Task 1, 43 chars:
    $n = $n = -1,-2,-5,-8.9,'b',-9.11,-6,-3,-2,-9.1,-1,-1.4,'a'
    [math]::Abs(($n|?{$_-is[double]}|sort)[-1])

    #Task 2, 35 chars:
    [int]-join([char[]]'{-'|%{[int]$_})

    #Task 3, 20 chars:
    "X "|%{'PowerShell'}

    ReplyDelete
  68. #Task1
    ($n-match'\.'|sort)[-1]*-1

    ReplyDelete
  69. #Task2
    [int]-join('b','c','d','e','f'|%{[int]([char]$_-[char]'a')})

    ReplyDelete
  70. #Task 3
    -join(-8,23,31,13,26,-5,16,13,20,20|%{[char]($_+[int][char]('X '-replace' ',''))})

    ReplyDelete
  71. Task 3 (PS 5 -- 259 chars) @mickyballadelli

    ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XX XXXXXXX XXXXXXXXXXXXXXXXX XXXXXXXXXXXXX "|sls '((.)+?)\1+' -A|%{$_.matches}|%{"$([char](121-($_.length)))"})-join''

    ReplyDelete
  72. Task 3 (PS 5 - 249 chars) @mickyballadelli

    ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X XXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXX "|sls '((.)+?)\1*' -A|%{$_.matches}|%{"$([char](120-($_.length)))"})-join''

    ReplyDelete
  73. Task 1 validated by function: @mickyballadelli

    56: ($n|?{$_-match'\d+\.\d+'}|Sort -D)[0]|%{[math]::Abs($_)}

    ReplyDelete
  74. Task 2 validated by function @mickyballadelli

    43: [int]([int][char]'{',[int][char]'-'-join'')

    ReplyDelete
  75. Task 3 validated by function @mickyballadelli

    248: ("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X XXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXX
    "|sls '((.)+?)\1*' -A|%{$_.matches}|%{"$([char](120-($_.length)))"})-join''

    ReplyDelete
  76. Update: since apparently the "largest" was before converted to absolute values, new solution to task 1:
    ($n|?{$_-is[Double]}|sort|%{[math]::abs($_)})[-1]
    Same amount of characters, still Powershell 5.
    (I blame language barriers for this one..)

    ReplyDelete
  77. New solution for question 3. 299 characters
    "X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXX XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXX".Split(" ")|%{Write-Host([char]($_.Length+79))-N}

    ReplyDelete
  78. Newer solution question3. 289 chars
    " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX".Split(" ")|%{Write-Host([char]($_.Length+80))-N}

    ReplyDelete
  79. Fabien: Exo 1 : $n -replace '^-'|?{$_ -like "*.*"}|sort|select -first 1

    ReplyDelete
  80. Task 2 update, I didn't check it :(
    [int](("{","-"|%{[int][char]$_})-join"")

    Rhys Edwards

    ReplyDelete
  81. Fabien: Exo 2: [int][char]"p"*[int][char]"o"-[int][char]"W"

    ReplyDelete
  82. Task 3:
    ("
    XXXXX
    X XXX
    X X X
    X X
    XX
    XX
    X X X
    XXX
    XXX "-split"`n"|%{[char]([convert]::toint32([int32]($_-replace"X",1-replace" ",0),2)+80)})-join""

    Rhys Edwards

    ReplyDelete
  83. Task 1:
    [math]::abs(($n|?{$_-is[double]}|sort)[-1])

    Rhys Edwards

    ReplyDelete
  84. @mickyballadelli 53 chars

    Check-Task 1 {($n|?{$_-match'\d+\.'}|Sort -D)[0]|%{[math]::Abs($_)}}

    ReplyDelete
  85. Task2 (41 chars) @mickyballadelli

    Check-Task 2 {[int]"$([int][char]'{')$([int][char]'-')"}

    ReplyDelete
  86. Task 1 (33 chars) @mickyballadelli

    Check-Task 2 {[int]([int[]][char[]]'{-'-join'')}

    ReplyDelete
  87. oops I meant task 2 --- 33 chars @mickyballadelli

    Check-Task 2 {[int]([int[]][char[]]'{-'-join'')}

    ReplyDelete
  88. New solution for question 3 using 64 characters. You say that I can use as many Xs and whitespaces as I like or need. I choose to use none :)
    ""|%{1,32,40,22,35,4,25,22,29,29|%{Write-Host([char]($_+79))-N}}
    If this solution is not acceptable then I will add an X and a whitespace in the initial string. Pls let me know /Simon

    ReplyDelete
  89. #Task2
    [int]-join('bcdef'-as[char[]]|%{[int]($_-[char]'a')})

    ReplyDelete
  90. Task 2, 28: +-join[int[]][char[]]'☺☻♥♦♣'

    The string '☺☻♥♦♣' is actually characters 1 through 5. They can be entered via Alt+01 through Alt+05 on the console; they cannot be entered in the ISE.

    ReplyDelete
  91. Task 3, 164: -join(-split'XXXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXXXXXXXX X XXXXXXXXXXXXXX XXXXXXXXXXXXXXX XXXX X XXXXXXXX XXXXXXXX'|%{$x=0}{[char]($_.Length+100-32*($x++%5-eq0))})

    ReplyDelete
  92. Task 3, 153: -join(' X X XXXX XX XXX X X X XX X X XX X X X X X X XX X XX '-split"`t"|%{[char][Convert]::ToInt32(("1$_"-replace' ',0-replace'X',1),2)})

    Binary coding of the string, using spaces for 0, tabs for separation.

    ReplyDelete
  93. # Answer 1:
    [math]::abs(($n|?{$_ -is[double]}|measure -ma).Maximum)

    # Answer 2:
    [int][char]'〹'

    # Answer 3:
    [string]::new(([regex]::Matches(" X    X XXXXXX XXXX  X XXX  X  X  XXX X   X  X XX XX  X XX  ".Replace(' ',0).Replace('X',1),'\d{6}')|%{[Text.Encoding]::UTF8.GetChars([Convert]::ToInt32("1$_",2))}))

    ReplyDelete
  94. -join(" X X XX XXXX XXX XXX XX X X XXX X X X XX XX X XX X X XX XX XX XX ".Replace(' ',0).Replace('X',1) -split'(?<=\G.{8})\B'|%{[char][convert]::ToInt16($_,2)})

    ReplyDelete
  95. Task 3, 153: -join(' X X XXXX XX XXX X X X XX X X XX X X X X X X XX X XX '-split"`t"|%{[char][Convert]::ToInt32(("1$_"-replace' ',0-replace'X',1),2)})

    ReplyDelete
  96. Solution 1: [math]::abs(($n|?{$_-Is[double]}|measure -Ma).Maximum)
    Solution 2: [int]((-[int][char]"J"..-[int][char]"F"|%{[char]($_+[int][char]"{")})-join"")
    Solution 3: "X "|%{$_.Replace(" ","Shell").Replace("X","Power")}

    ReplyDelete
  97. Task 2, 9: +'〹'[+$z]

    Requires uninitialized variable $z, though. Alternatively:

    +'〹'[!$?]

    in the hopes that the last command was successful (can obviously be a character shorter if it wasn't).

    ReplyDelete
  98. Task 2, 8: +'〹'['']

    One of these days I'll actually think before posting. This is not that day, though.

    ReplyDelete
  99. Task 3, 118: -join(' X                          '-split"`t"|%{[char](($_[0,1]|%{'X             ᠎ '.IndexOf($_)})-join'*16+'|iex)})

    This uses some ... creative interpretation of the word "whitespace", including not only space, but also everything else Unicode has to offer ;). Hexadecimal encoding of the word PowerShell by mapping 0–F to X and whitespace characters.

    ReplyDelete
  100. And another attempt to paste 2nd: +(-join[int[]][char[]]'{-')
    It starts with plus sign, bracket, join operator, int array, char array, literal string with curly and minus, closing bracket. ;)

    ReplyDelete
  101. Task 3, 117: -join(' X                          '-split' '|%{[char](($_[0,1]|%{'X             ᠎ '.IndexOf($_)})-join'*16+'|iex)})

    This time with a literal tab instead of "`t". Saves the one escape char.

    ReplyDelete
  102. Task 3, 90: Check-Task 3 { -join(-split'XXXX XXXXXX XXXXXXX XX XXXXX XXX XXXXXXXX XX X X'|%{'leSProwh'[$_.Length-1]}) }

    Very trivial encoding of indexes into a reservoir of characters to use. Unary coding of the indexes. Now, this might be a bit debatable, as I defined the characters that can be produced from the encoding, but changing the X-and-whitespace string will change the output, so I guess it should count (also contains only X and spaces, without going crazy on the whitespace rule like previous solutions).

    ReplyDelete
  103. Task 3, 89: -join(-split'XXXX XXXXXX XXXXXXX XX XXXXX XXX XXXXXXXX XX X X'|%{' leSProwh'[$_.Length]})

    Minor optimization of the solution before.

    ReplyDelete
  104. #1
    $n-match'\d{1}.\d{1}'-replace'-',''|measure -min|select -Expand minimum

    ReplyDelete
  105. 2#
    [int](('bcdef'.ToCharArray()|%{([byte][char]$_)-([byte][char]'a')})-join'')

    ReplyDelete
  106. Really wasn't sure about #3 but here is my shot:

    (((('XXXXXXXXXX'))-replace('(?<=^.{0}).*','PowerShell')))

    ReplyDelete
  107. I learnt a lot from these little tasks! thanks a lot!

    ReplyDelete
  108. Task 3 238 characters, PS 5, @mickyballadelli

    Check-Task 3 {(('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX` `X` `XXXXXX` `XXXXXXXXXXXXXXXX` `XXXXXXXXXXXX` ').split('`') |% {"$([char](120-($_.length)))"})-join''}

    ReplyDelete
  109. Task 3 (236 characters) @mickyballadelli
    Check-Task 3 {(('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX` `X` `XXXXXX` `XXXXXXXXXXXXXXXX` `XXXXXXXXXXXX` ').split('`')|%{"$([char](120-($_.length)))"})-join''}

    ReplyDelete
  110. Task 3 234 Characters @mickyballadelli

    Check-Task 3 {(('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX` `X` `XXXXXX` `XXXXXXXXXXXXXXXX` `XXXXXXXXXXXX` ').split('`')|%{"$([char](120-$_.length))"})-join''}

    ReplyDelete
  111. Second try on Task 3:
    [string]::new(([regex]::Matches(' X    X XXXXXX XXXX  X XXX  X  X  XXX X   X  X XX XX  X XX  '.Replace(' ',0).Replace('X',1),'\d{6}')|%{[char][Convert]::ToInt32("1$_",2)}))

    ReplyDelete
  112. 212 Chars (yay!!) @mickyballadelli

    Task 3

    Check-Task 3 {((' `X`XXXXXXXXX` `XXXX` ` ` ` ` ').split('`')|%{if($_[0] -eq"X"){"$([char](110+$_.length))"}else{"$([char](110-$_.length))"}})-join''}

    ReplyDelete
  113. Task 3 (204 chars) @mickyballadelli

    Check-Task 3 {((' `XXX`XXXXXXXXXXX` `XXXXXX` ` ` ``').split('`')|%{if($_[0] -eq"X"){"$([char](108+$_.length))"}else{"$([char](108-$_.length))"}})-join''}

    ReplyDelete
  114. Second try on Task 1:
    [math]::abs(($n|?{$_-is[double]}|measure -ma).Maximum)

    ReplyDelete
  115. I just saw that only one answer per comment was allowed... I wrote three in my first comment. In case that comment will be ignored here is the second answer.
    Task 2:
    [int][char]'〹'

    ReplyDelete
  116. Task 3 (190 characters) @mickyballadelli

    Check-Task 3 {((' `XXX`XXXXXXXXXXX` `XXXXXX` ` ` ``').split('`')|%{"$([char]108)+(if($_[0] -eq'X'){$_.length}else{-$_.length})))"})-join''}

    ReplyDelete
  117. Task 3 (192 characters) (sorry the previous one was bugged) @mickyballadelli

    Check-Task 3 {((' `XXX`XXXXXXXXXXX` `XXXXXX` ` ` ``').split('`')|%{"$([char]$(if($_[0] -eq'X'){108+$_.length}else{108-$_.length}))"})-join''}

    ReplyDelete
  118. Task 3 (191 characters) @mickyballadelli

    Check-Task 3 {((' `XXX`XXXXXXXXXXX` `XXXXXX` ` ` ``').split('`')|%{"$([char](108+$(if($_[0] -eq'X'){$_.length}else{-$_.length})))"})-join''}

    ReplyDelete
  119. Task 3 (187 Characters) @mickyballadelli

    Check-Task 3 {((' `XXX`XXXXXXXXXXX` `XXXXXX` ` ` ``').split('`')|%{"$([char](108+$_.Length-$(if($_[0] -eq' '){$_.length*2})))"})-join''}

    ReplyDelete
  120. Check-Task 1 {[math]::Abs(($n|?{$_-is[double]}|sort)[-1])}
    Check-Task 2 {+[char]'〹'} # The character is UNICODE U+3039 (decimal 12345)
    Check-Task 3 {"X "|%{'PowerShell'}}

    This gives me all green and the following result:
    43: [math]::Abs(($n|?{$_-is[double]}|sort)[-1])
    10: +[char]'〹'
    20: "X "|%{'PowerShell'}

    ReplyDelete
  121. Check-Task 1 {[math]::Abs(($n|?{$_-is[double]}|sort)[-1])}
    Check-Task 2 {+[char]'〹'} # The character is UNICODE U+3039 (decimal 12345)
    Check-Task 3 {"X "|%{'PowerShell'}}

    This gives me all green and the following result:
    43: [math]::Abs(($n|?{$_-is[double]}|sort)[-1])
    10: +[char]'〹'
    20: "X "|%{'PowerShell'}

    Before you consider "X "|%{"PowerShell"} as a joke then ask yourself this...
    Is your start string and your end string the same string?
    Does...
    [System.Runtime.InteropServices.Marshal]::StringToCoTaskMemAnsi($startString...)
    [System.Runtime.InteropServices.Marshal]::StringToCoTaskMemAnsi($endString...)
    yield the same pointer value? If not then a pure replacement ought to be within the rules since you say nothing about the "PowerShell" string not to be part of the oneliner. Or you could be more specific in what type of algorithm you are expecting. :)

    Having said that.... Here is my non jokes version of task 3 :)

    Check-Task 1 {[math]::Abs(($n|?{$_-is[double]}|sort)[-1])}
    Check-Task 2 {+[char]'〹'} # The character is UNICODE U+3039 (decimal 12345)
    Check-Task 3 {" X X XXXXXX XXXX X XXX X X XXX X X X XX XX X XX "-replace"X",1-replace" ",0|tee -Va s|%{-join(0..9|%{[char]([Convert]::ToInt32($s.SubString($_*6,6),2)+64)})}}

    This gives me 43,10 and 170

    ReplyDelete
  122. TASK 3 - Powershell is the secret word
    ' XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX'.Split()|%{Write-Host -NoNewline([char]($_.Length+80))}

    Alexander Johansson (aleqs__@outlook.com)

    ReplyDelete
  123. 3. Sorry, make an error, check function help alot, still 152

    -join('X XXXX X X XX X XX XX XX X XXX XX X X XX X XX'-replace' ',1-replace'X',0-split'(\d{6})'|?{$_}|%{[char][convert]::tobyte("1$_",2)})

    ReplyDelete
  124. 1. Forget about Abs, 78
    [Math]::Abs(($n|?{$_-Match'\.'}|%{$_-as[double]}|measure -ma|select -exp ma*))

    ReplyDelete
  125. 3.
    I Don't khow, it is considered as a joke or not ? if Yes, note than input string MUST BE USED
    62: 'X '|%{(powershell -?| ?{$_-match'-Version <'})-replace'\[.*'}

    ReplyDelete
  126. 3. even shorter if not a joke
    30: 'X '|%{$ShellId-replace'.*\.'}

    ReplyDelete
  127. 3. based on previous but input string (formally) used
    35: 'X '|%{($_+$ShellId)-replace'.*\.'}

    You really should consider, if input MUST be used and in which form

    ReplyDelete
  128. Task 2 (32 chars):
    [int](''..'.....'.Length-join'')

    Brgds @csandfeld

    ReplyDelete
  129. Task 3 (183 chars):
    'X XX XXXXXXXXXX XX XXXXX XXXX XXXXX XX XXXXXXXXX XXXXXXXXX '|%{([regex]::Matches($_,'(X+)|( +)')|%{$_.Value.Length|%{if($i++%2){[char](119-10*$_+$j)}else{$j=$_}}})-join''}

    Brgds @csandfeld

    ReplyDelete
  130. # Another update Johan Akerstrom,jakerstrom@gmail.com

    Check-Task 1 {[math]::Abs(($n|?{$_-is[double]}|sort)[-1])}
    Check-Task 2 {+[char]'〹'} # The character is UNICODE U+3039 (decimal 12345)
    Check-Task 3 {
    -join(0..9|%{[char]([Convert]::ToInt32($s.SubString($_*6,6),2)+64)}-b{$s=" X X XXXXXX XXXX X XXX X X XXX X X X XX XX X XX "-replace"X",1-replace" ",0})
    }

    43,10,163

    ReplyDelete
  131. New entry for task 3. I solved my earlier question. Write-Host does not output a string. That is why I was getting red in Check-Task. Anyway new entry below: 71 chars
    "X"|%{[string]::Concat((0,31,39,21,34,3,24,21,28,28|%{[char]($_+80)}))}

    ReplyDelete
  132. 1.
    76: ($n|?{$_-Match'\.'}|%{$_-as[double]}|measure -ma|select -exp ma*)-replace'-'

    ReplyDelete
  133. 1.
    69: ($n|?{$_-Match'\.'}|%{$_-as[double]}|measure -ma).Maximum -replace'-'

    ReplyDelete
  134. My 14 char answer to Task2:
    [int][char]"〹"
    /SimonW

    ReplyDelete
  135. My 159 char answer to Task3:
    -join('X X X X X X XX XX X X X X X XX XX XX '-split'(.{6})'-replace'X','1'-replace' ','0'|?{$_}|%{[char](120-[convert]::ToInt32($_,2))})
    /SimonW

    ReplyDelete
  136. # Task 1
    $n | ?{$_ -like "*.*"} | Measure -Ma | Select -Exp Ma* | %{[math]::abs($_)}
    Shortest but more error prone, I initially made this one :
    $n | ?{$_.GetType() -eq [Double]} | Measure -Max | Select -Expa Ma* | %{[math]::abs($_)}

    ReplyDelete
  137. #Task 2
    [int][char]"〹"
    Character is not displaying correctly but I simply used the ascii value of "12345" to get it.

    ReplyDelete
  138. # Task 3
    "XXXXXXXX XXXXXXX XXXXXX XX XXXXX XXXX XXX XX X X " -replace "XXXXXXXX ","P" -replace "XXXXXXX ","o" -replace "XXXXXX ","w" -replace "XXXXX ","r" -replace "XXXX ","S" -replace "XXX ","h" -replace "XX ", "e" -replace "X ","l"
    Not sure I understood correctly the task though.
    Thanks for the contest !

    ReplyDelete
  139. 3. if the input string should be "used"
    33: 'X '|%{$_+$ShellId-replace'.*\.'}

    but I think the rule should say "input string must be converted to 'Powershell' without use of other input sources"
    and than my 152 char solution come in play

    ReplyDelete
  140. 3. IfNotAJoke
    28: -join('X '+$ShellId)[12..21]

    ReplyDelete
  141. Task 1 (48 Chars) @mickyballadelli

    $n|?{$_-match'\.'}|Sort)[-1]|%{[math]::Abs($_)}

    ReplyDelete
  142. 2.
    38: [int]-join($?..('aaaaa'.length)|%{$_})

    ReplyDelete
  143. 2. oops I was too fast
    32: [int]-join($?..('aaaaa'.length))

    ReplyDelete
  144. Task 1:

    [math]::Abs(($n|?{$_ -match '^-?\d+\.\d+$'}|sort -D|select -F 1))

    ReplyDelete
  145. Task 2:

    [int](('@ABCD'.ToCharArray()|%{[char]($_ -0xF)}) -join '')

    ReplyDelete
  146. Task 2

    [int](([char[]]'@ABCD'|%{[char]($_ -0xF)}) -join '')

    ReplyDelete
  147. Task 3

    (' XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX XXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXX'.split(' ')|%{[char]($_.Length+80)}) -join ''

    ReplyDelete
  148. My 158 char answer to Task3:
    -join(' XX X X X XX X XX X XX X X XX XXX X XXX X'-split'(.{6})'-replace'X','1'-replace' ','0'|?{$_}|%{[char](79+[convert]::ToInt32($_,2))})
    /SimonW

    ReplyDelete
  149. TASK 3 - Powershell is the secret word

    Answer:
    ' XXXXXXXXXXX XXXXXXXXXXXXXXXXXXX X XXXXXXXXXXXXXX XXX XXXX X XXXXXXXX XXXXXXXX'.Split()|%{if($_.Length-match'[0,3]'){[int]$i=$_.Length+80}else{$i=$_.Length+100}Write-Host -NoNewline([char]$i)}

    Alexander Johansson (aleqs__@outlook.com)

    ReplyDelete
  150. My 154 char answer to Task3:
    -join(' XX X X X XX X XX X XX X X XX XXX X XXX X'-split'(.{6})'-replace'X',1-replace' ',0|?{$_}|%{[char](79+[convert]::ToInt32($_,2))})
    /SimonW

    ReplyDelete
  151. My 148 char answer to Task3:
    -join(' XX X X X XX X XX X XX X X XX XXX X XXX X'-split'(.{6})'-replace'X',1-replace' ',0|%{[char](79+[convert]::ToInt32($_,2))})
    It throws a bunch of errors but only outputs one string to the outputstream.
    /SimonW

    ReplyDelete
  152. TASK 3 - Powershell is the secret word

    Answer:
    ' XXXXXXXXXXX XXXXXXXXXXXXXXXXXXX X XXXXXXXXXXXXXX XXX XXXX X XXXXXXXX XXXXXXXX'.Split()|%{if($i){$l=$_.Length}if($l-match'[0,3]'){$i=$l+80}else{$i=$l+100}Write-Host -NoNewline([char]$i)}

    Alexander Johansson (aleqs__@outlook.com)

    ReplyDelete
  153. 3. IfNotAJoke
    28: -join('X '+$ShellId)[12..21]

    ReplyDelete
  154. 2.
    30: [int]-join($?..'aaaaa'.length)

    ReplyDelete
  155. 1.
    58: ($n|?{$_-match'^-?\d+\.\d+$'}|sort|select -l 1)-replace'-'
    48: ($n|?{$_-like'*.*'}|sort|select -l 1)-replace'-' #but here is an error with other $n values like 'a.a'

    ReplyDelete
  156. 1
    50: ($n|?{$_-match'^-?\d+\.\d+$'}|sort)[-1]-replace'-'
    40: ($n|?{$_-like'*.*'}|sort)[-1]-replace'-' #but here is an error with other $n values like 'a.a'

    ReplyDelete
  157. I know it's too late but just find this page :(
    task 3 in 29 chars ( with a string that use 0 space and X )
    ''+(iwr http://goo.gl/2nzV8B)

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...