Skip to content

Instantly share code, notes, and snippets.

@rdbartram
Last active June 4, 2020 13:05
Show Gist options
  • Save rdbartram/b66be3d6e80315139829f5efb8e66435 to your computer and use it in GitHub Desktop.
Save rdbartram/b66be3d6e80315139829f5efb8e66435 to your computer and use it in GitHub Desktop.
My attempts at Code-Golf.io in PowerShell
# 12 days of christmas
$i=0;while($i-lt12){$f="On the $(("First;Second;Third;Fourth;Fifth;Sixth;Seventh;Eighth;Ninth;Tenth;Eleventh;Twelfth"-split";")[$i]) day of Christmas;My true love sent to me;A Partridge in a Pear Tree.;Two Turtle Doves;Three French Hens,;Four Calling Birds,;Five Gold Rings,;Six Geese-a-Laying,;Seven Swans-a-Swimming,;Eight Maids-a-Milking,;Nine Ladies Dancing,;Ten Lords-a-Leaping,;Eleven Pipers Piping,;Twelve Drummers Drumming,"-split";";$a=$f[0,1]+$f[$(2+$i)..2];$a[-2]=$i++ ?$a[-2]+', and':$a[-2];$a+''|write-host}
# fizzbuzz
1..100|%{($_%3?$^:'Fizz')+($_%5?$^:'Buzz')??$_}|write-host
# seven segment
$n=$args;1..3|%{$l=$_;$o="";$n.ToCharArray()|%{$o+=('{"1":{"1":" ","2":" |","3":" |"},"2":{"1":" _ ","2":" _|","3":"|_ "},"3":{"1":" _ ","2":" _|","3":" _|"},"4":{"1":" ","2":"|_|","3":" |"},"5":{"1":" _ ","2":"|_ ","3":" _|"},"6":{"1":" _ ","2":"|_ ","3":"|_|"},"7":{"1":" _ ","2":" |","3":" |"},"8":{"1":" _ ","2":"|_|","3":"|_|"},"9":{"1":" _ ","2":"|_|","3":" _|"},"0":{"1":" _ ","2":"| |","3":"|_|"}}'|convertfrom-json).$_.$l};write-host $o}
# 99 bottles of beer
$i=100;$f=" of beer on the wall";function t($b,$c='n'){"$($b-gt 0?$b :$c+"o more") bottle$($b-ne 1?'s':'')"};while(0-lt$i--){@("$((t $i ($i -eq 0?'N':'n')))$f, $(t $i) of beer.;$(($i -gt 0)?"Take one down and pass it around":"Go to the store and buy some more"), $(t ((0-lt$i)?$i-1:99))$f.").Split(";")+''|write-host}
# evil numbers
0..50|%{if(0-eq([Convert]::ToString($_,2)-replace'0').length%2){write-host $_}}
# fibonacci
$f=0..1;while($f.count-lt31){$f+=$f[-1]+$f[-2]};$f|write-host
# leap years
1800..2400|%{if(!($_%4)-and!(!($_%100)-and$_%400)){write-host $_}}
#Pangram Grep
$args|?{($_.tolower()-replace'\W|\d|_'-split''|select -Unique).count-eq27}|write-host
# Rock-paper-scissors-Spock-lizard
$t="Tie";$args|%{switch -regex($_){βœ‚{switch -regex($_){πŸ“„{'βœ‚ cuts πŸ“„'}πŸ’Ž{'πŸ’Ž crushes βœ‚'}🦎{'βœ‚ decapitates 🦎'}πŸ––{'πŸ–– smashes βœ‚'}default{$t}}break}πŸ“„{switch -regex($_){πŸ’Ž{'πŸ“„ covers πŸ’Ž'}🦎{'🦎 eats πŸ“„'}πŸ––{'πŸ“„ disproves πŸ––'}default{$t}}break}πŸ’Ž{switch -regex($_){🦎{'πŸ’Ž crushes 🦎'}πŸ––{'πŸ–– vaporizes πŸ’Ž'}default{$t}}break}🦎{switch -regex($_){πŸ––{'🦎 poisons πŸ––'}default{$t}}}default{$t}}}|write-host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment