Quantcast
Channel: Hacker News 50
Viewing all articles
Browse latest Browse all 9433

code golf - Print every character your program doesn't have - Programming Puzzles & Code Golf Stack Exchange

$
0
0

Comments:"code golf - Print every character your program doesn't have - Programming Puzzles & Code Golf Stack Exchange"

URL:http://codegolf.stackexchange.com/questions/12368/print-every-character-your-program-doesnt-have


PowerShell: 96

Must be saved and run as a script.

diff([char[]](gc $MyInvocation.InvocationName))([char[]](32..126))-Pa|?{$_.SideIndicator-eq'=>'}

diff is a built-in alias for Compare-Object.

gc is a built-in alias for Get-Content.

$MyInvocation.InvocationName gets the full path to the script being executed.

32..126 is the decimal equivalent for 0x20..0x7e, and so creates an array of the decimal ASCII codes we're looking for.

[char[]] takes the contents of the next object and puts them into an array, breaking them up and converting them into ASCII characters. So, we now have two arrays of ASCII characters - one pulled from this script, the other defined by the challenge criteria.

-Pa sets Compare-Object to "Passthru" format, so only the items which are found different between the inputs are output at the console - indicators of which items were in which input are still stored in the object's data, but are not displayed.

|?{$_.SideIndicator-eq'=>'} pipes Compare-Object's output to Where-Object, which filters it down to only the items which are exclusive to the second input.


Viewing all articles
Browse latest Browse all 9433

Trending Articles