# Print every character your program doesn't have

Your task is to build a program (using only printable ASCII characters and/or tabs and newlines) that prints out exactly the characters in the printable ASCII space (0x20 to 0x7e) that don't appear in your program's source code (in any order, however many times you want).

The shortest code to do this in any language wins.

• They are, but they're not in the range 0x20 to 0x7e, which are defined as the "printable ASCII characters". Technically tabs and newlines are actually control characters. – Joe Z. Aug 23 '13 at 19:22
• Are we allowed to print newlines (or any other unprintable ASCII characters)? – flornquake Aug 24 '13 at 0:30
• Tabs and newlines do not render in such a way that they occupy a printing position. They move the position. See the ANSI C "isprint" function. – Kaz Aug 24 '13 at 2:00
• @Timwi: If you wanted to do that, you'd have to output all the characters in the CJK character space too (excluding the ones appearing in your code). It's too complicated to manage, so I restricted it to just ASCII. – Joe Z. Feb 1 '14 at 3:01
• Can we output non-ASCII characters as well? – caird coinheringaahing Nov 23 '17 at 16:19

### GolfScript, 15 12 characters

{),32>^.}.~


Based on Jan Dvorak's answer with a few twists and also in the style of Peter Taylor's one.

#undef X;A!"$%&'()*+-[,.]/0123456789:<=>?@BCDEFGHIJKLMNOPQRSTUVWYZ\^_abcghijklmopqrstvwxyz{|}~  Does nothing. • No, but this is a polygot. I don't want to destroy that. – Johannes Kuhn Aug 23 '13 at 16:26 • I fed this into the GNU Fortran compiler and it segfaulted. – marinus Aug 23 '13 at 16:43 • In C, #undef X;whatever junk you want works. – ugoren Aug 23 '13 at 16:56 • "The shortest code to do this in any language wins." For the lack of a code that works in any language, this entry should win, since it's the code that works in the greatest number of languages. ;-D – msb Aug 27 '13 at 23:33 • @JoeZ. I know, just kidding, trying to bend the interpretation of the definition to favour the most creative answer IMO. ;-) – msb Sep 4 '13 at 0:27 # PHP 5.2, 4 <?<<  Save as a file called NYUIOMK()'DEAQRWVX[Z]\^@CBGFJqwv{z}|~bgfkj203547698;=>!#"%$&+*-.php somewhere in /home. short_open_tag needs to be On in your php.ini.

The output is:

PHP Parse error:  syntax error, unexpected T_SL in /home/wherever/NYUIOMK()'DEAQRWVX[Z]\^@CBGFJqwv{z}|~bgfkj203547698;=>!#"%$&+*-.php on line 1  • Haha, nice bending of the rules. – Johannes Kuhn Aug 27 '13 at 19:12 • Nice, but unfortunately I can spot a : in the output. – Howard Aug 28 '13 at 4:57 • – The Guy with The Hat Feb 27 '14 at 17:47 • I appreciate it, @TheGuywithTheHat, but I answered this about a year ago, as opposed to yesterday. – Ry- Feb 27 '14 at 18:07 • @TheGuywithTheHat This was one of the answers when the loophole was funny, new and lead to your linked meta post. Now it isn't anymore. – Johannes Kuhn Oct 17 '14 at 14:27 ## JavaScript - 88 alert("BCDFGHIJKMNPQUVXYZ".toLowerCase())// !#$%&'*+,-0123456789:;<=>?@[\]^_{|}~AERTOWS


prints "bcdfghijkmnpquvxyz"

• Wow I like the toLowerCase idea, it's brilliant! – Pierre Arlaud Nov 29 '13 at 15:20
• You can save three characters with a bit of math: "!#$%&*+,-13:<=>?@[\]^_{|}~AERTOWS";alert('BCDFGHIJKMNPQUVXYZ'.toLowerCase()+95*72) because 95*72 = 6840 and moving the wasted characters to a string allows you to use the quotes instead of wasting them. Besides that, hiding characters in a comment feels cheesy. – Umbrella Mar 12 at 12:40 ### Whitespace, 61 57 characters It's not the shortest but it probably has the simplest logic (it's just a loop really). Here it is completely commented, where S is space, T is tab, L is line feed: SSSTSSSSSL # push 0x20 LSSSL # label S SSSTL # push 1 TSSS # add SLS # duplicate top of stack SLS # duplicate again TLSS # output ASCII character SSSTTTTTTSL # push 0x7E TSST # subtract (result - 0x7E) LTTSL # branch to label S if top of stack is negative LLL # end  Thanks to @r.e.s. for correction to the above (required extra duplicate for the branch instruction) and for smaller numbers to push on the stack. • This doesn't work as-is, but can be fixed by inserting a duplicate-top-of-stack (SLS) immediately before the conditional branch (LTTSL) -- it's needed because the conditional branch command removes the top-of-stack. The resulting 64-character program works as advertised. (If the program is stored in a file with .ws extension, it can be tested online at golf.shinh.org/checker.html) – r.e.s. Aug 25 '13 at 16:24 • Also, the program length can be reduced to 57 using nearly the same program but with the three pushed numbers -94, 127, 126 changed to 32, 1, 126, respectively: SSSTSSSSSL LSSSL SSSTL TSSS SLS SLS TLSS SSSTTTTTTSL TSST LTTSL LLL. – r.e.s. Aug 25 '13 at 19:39 ### Golfscript, 26 24 characters "126,32>''+".~\-'.~\-"'-  Takes a range generation script, duplicates it, executes it, substracts it from its result, then substracts the result subtraction code and the other quote character. • Damn, that's clever. – marinus Aug 23 '13 at 17:28 • Remove ''+, escape program before subtraction, put in a noop .; (didn't find a better way to cover the dot), use code block instead of string -> {126,33>-.;}.~ which is 16 chars – Howard Aug 23 '13 at 18:17 • And utilising in any order, however many times you want you can also remove the semicolon. – Howard Aug 23 '13 at 18:52 • @Howard I'm afraid I don't understand your idea. You can post it as a separate answer. – John Dvorak Aug 23 '13 at 18:53 • @PeterTaylor I thought I printed a space? – John Dvorak Aug 23 '13 at 19:05 ## C, 8374 69 characters main(z) {for(;++z<96;"\33iE!vk?}GkRP8z"[z/7]&1<<z%7&&putchar(z+32));}  I really tried to get it down below 80 characters, but I just haven't been able to pull it off. I finally decided to post what I have, on the assumption that I (or someone else) will figure out 79-character solution ten minutes after posting this. Okay, it wasn't quite ten minutes, but it worked in principle. I really wanted to post a version that didn't have to have a gratuitous space in the source code, but that one landed in a strange-attractor orbit, bouncing between a handful of solutions. After many minutes of trying to nudge one of them into a stable solution, I gave up and added the space. Fish - 80 zbcdjkpqruvwxaABCDEFGHIJKLMNOPQRSTUVWXYZ#!"'$%^&*()@!+-[]{},;:/\<>=?|~0123456789


When fish errors it prints out "something smells fishy...". Since z is a bad instruction it errors right away

I know it's not winning any contests. I just wanted to try it in a language not normally used, just for kicks.

# Java - 209 195 152 140 characters

class a{public static void main(String[]a){for(char c=0;;c++)System.out.print("publicas{tvodmn(Srg[])h=0;w+ye.\"\\xO<?:}".indexOf(c)<0?c:"");}}


With line breaks and tabs

class a{
public static void main(String[]a) {
for(char c=0;;c++)
System.out.print("publicas{tvodmn(Srg[])h=0;w+ye.\"\\xO<?:} ".indexOf(c)<0?c:"");
}
}


Beware if you execute: program does not terminate. Haha

Explanation

1. for(char c=0;;c++): Since a char can be treated as an int, I use that to my advantage here to increment through all possible values of c. I omit the terminating condition in the loop (the one that would go between the two semicolons) in order to save on characters, since it wasn't specified that the program had to terminate. :)
2. "publicas{tvodmn(Srg[])h=0;w+ye.\"\\xO<?:} ".indexOf(c)<0?c:"": Sadly, not a very elegant approach, but it gets the job done. Manually list every character present in the source code as a String literal, then check whether the current char c occurs within it with indexOf(). If the indexOf() call returns -1, it doesn't exist, and therefore we should print it. The rest of it just uses the ternary operator to save on characters and space.
• can you explain a bit? – joey rohan Oct 1 '13 at 18:01
• @joeyrohan Sure, just added an explanation below it. :) – asteri Oct 1 '13 at 18:10
• cool ;) nice stuff :) – joey rohan Oct 1 '13 at 18:12
• You could put the ENTIRE ascii printable table in a comment and make a java programm that returns nothing. It'd beat yours :-) – Pierre Arlaud Nov 28 '13 at 13:29
• You could have told me that this is going to print every single Unicode character before I executed it in my terminal. – nyuszika7h Jun 14 '14 at 20:55

## Perl, 49 characters

say grep/[^+-246$-^aceghmprsy]/,map chr,041..126  This is an interesting challenge -- it's sort of the anti-quine, and I've managed to shorten the program a couple of times by increasing the range of characters that appear in it. ## Ruby, 8178686662 57 (?!..?~).map{|a|><<a if/[()ifmap{}|?!.~\/\\$$$><]/!~a}  Simply checks itself. Duplicate characters manually removed. Thanks to Josh for saving 4 characters, and minitech for saving 5 characters! • Can't you put the if after the ><<x to save one of the end lines? – Josh Aug 23 '13 at 23:10 • @Josh Yes. I will do that now. – Doorknob Aug 23 '13 at 23:26 • You can take it to 58: (?!..?~).map{|x|><<x if/[()ifmap{}|x?!.~\/\\><]/!~x} – Ry- Aug 25 '13 at 15:15 • Ah, and with a better choice of variable name, 57: (?!..?~).map{|a|><<a if/[()ifmap{}|?!.~\/\\><]/!~a} – Ry- Aug 25 '13 at 15:18 • ><<((32..126).map(&:chr)-IO.read(__FILE__).chars).join 55 bytes using a different approach. – twe4ked Mar 12 '17 at 22:36 ## Befunge (48) <|::-1,+*88:<+3*87 6<@.**85 9>"()~&"/% |!#';=?}  Outputs: {zyxwvutsrqponmlkjihgfedcba_^][ZYXWVUTSRQPONMLKJIHGFEDCBA240 • Holy cow! Nice work! – Cruncher Nov 28 '13 at 18:21 Not very serious, but I had to give it a go: ## JSFuck (138152) (compiled source here) Original source: for(x=0x7e;x>0x19;x--){ console.log(String.fromCharCode(x).replace(/[!\+]/ig, '')) }  Prints all characters except ()+[]! • (x) <=> [x][+[]], increases code size but makes the alphabet needed smaller. – FireFly Oct 3 '13 at 21:18 Your task is to build a program (using only printable ASCII characters and/or tabs and newlines) Gosh, you made it hard for APL (Is that delibarate?) So I decide to Ignore All Rules!!! ## APL(Dyalog), 3 10 ⎕AV  Prints the atomic vector (which includes all prinable ASCII characters) Turns out I completely forgot about the "without" part... But that's an easy fix ⎕AV~'AV'''  ~'AV''' means exclude (~) the characters A, V and single quote (escaped as doubled single quotes) Regarding printing non-ASCII, well, I am Ignoring All Rules. • "print[s] out exactly the characters in the printable ASCII space (0x20 to 0x7e) that don't appear in your program's source code" I believe the output may not contain characters outside of the printable ASCII space ("exactly" being the keyword), and your program contains 'A' and 'V' so they should not be printed. – FireFly Oct 4 '13 at 18:11 • You'll at least want to add ~ to the set of excluded characters. ;-) Btw, a similar J solution would be a.-.'a.-''' – FireFly Oct 4 '13 at 19:14 • You can Ignore All Rules, but that does disqualify you from being the accepted answer. – Joe Z. Oct 12 '13 at 2:35 ## GolfScript (18 16 chars) "),@^^32>#.~".~  Online demo with an extra line which does a correctness check and outputs the number of characters in error. (I have various equivalent alternatives. @^ can be replaced with \\; # can be replaced with  or ]. The right combination can be used with Howard's trick to equal his score of 15 because backslashes don't need escaping in blocks the way they do in string literals: {),\^32>].~}.~. But Howard deserves the credit for that trick). ## J (52 40) Edit: Duh, forgot about e. '''(-@.e#[)~95{32}a'(-.@e.#[)~95{.32}.a.  Old version: (>@(*/@('(>@*/''&~:).#]32{95}a'&~:)&.>)#])95{.32}.a.  Other variant (same length but less output): ([#~*/"1@('([#~*/"1@''&:0)95{.32}a'&~:"0))95{.32}.a.  • @JanDvorak: whoops typo – marinus Aug 23 '13 at 16:34 • Darn it! I was hoping I could get low enough in Ruby to beat you and then you drop it all the way to 40. :P – Doorknob Aug 23 '13 at 17:08 • The new one looks much more quiney. – John Dvorak Aug 23 '13 at 17:10 • @Doorknob: I have one in APL that's only 24 characters but it has non-ASCII characters in it. – marinus Aug 23 '13 at 17:11 • Yeah, I did the ASCII thing to avoid languages like APL. – Joe Z. Aug 23 '13 at 19:38 # Brainfuck, 173 +++++[->++++++<]>>>++[------<+>]<++++>>----[----<+>]>-[-------<+>]>-[---<+>]<------->>-[---<+>]<+++++++++>>--[-----<+>]<+++++>>+[---------<++>]+++++++++++++[<[.+<]>[>]<-]\=,  Pretty long, I might try again later. • write a program that does nothing and add the rest od ascii to the source, worst case feels like 96 characters. – Jasen Dec 27 '14 at 2:13 # Python 3 - 68 61 x=r"print(*set(map(chr,range(32,127)))-set(x+'=\"'))" exec(x)  ... thanks to @WolframH for the improvements. • I think you can put exec(x) in a new line and save the ; in x. Also, in Python 3, you can use x=r"print(*set(map(chr,range(32,127)))-set(x+'=\"'))"\nexec(x) for 61 chars (prints multiple spaces, which is allowed). – WolframH Aug 24 '13 at 22:46 • @WolframH ingenious, thanks! – user8943 Aug 24 '13 at 23:13 Javascript, 92 (function f(){for(i=32;126>i++;)!~(""+f).indexOf(c=String.fromCharCode(i))&&console.log(c)})()  • Is this a fair solution? alert(' !"#%^*+/-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_bcdfghijkmnopqsuvwxyz{|}~') Comes in at 95 chars and is dumb as hell. :p – tristin Oct 2 '13 at 18:59 • @tristin :P yeah javascript is a bit verbose when it comes to charcode to string. And isn't it output every character your program dosn't have. The text your alerting is in your program as well :) – C5H8NNaO4 Oct 3 '13 at 9:09 • Haha, oops. Oh well. – tristin Oct 3 '13 at 19:09 ## 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. # Java - 126 characters minimized: class hjq{public static void main(String...w){for(char z='"'|0;++z!='a';)if("'()+.0;=OS".indexOf(z)==~0)System.out.print(z);}}  unminimized: class hjq { public static void main(String... w) { for (char z = '"'|0; ++z != 'a';) { if ("'()+.0;=OS".indexOf(z) == ~0) { System.out.print(z); } } } }  This is an interesting problem, because individual tokens might benefit from their longer form because it re-uses characters. For example, normally String[] would be shorter, but String... removes the need for the square brackets in the conditional string. I found the trick was to try and use characters at the beginning and end of the range so you can exclude them from the output simply by altering your loop start and end. For Java, a key character to exclude is ", because having that in the string requires escaping it, which adds \ to your program, which needs to go in the string, which adds \\. By removing " from your conditional string you remove 4 characters. This can be achieved by making sure you use and ! and starting your loop from #. All the lowercase letters appear near the end of the range, with only {, |, } and ~ coming after them. Because of Java's verbosity, most of the lowercase letters are used just for the boilerplate. Likewise, { and } are trivial for a Java program, because the boilerplate requires them. | can be used if you have an or condition, but I couldn't find a way to take advantage of one that leads to a shorter program than just using | as a bitwise operator. The |0 makes me feel a little dirty, because it's the only part that's a nop just to get the character in there. ~0 yields -1, which is handy because that's what we need to check for with indexOf. Combining this with using != for the loop conditional eliminates the < character altogether, which means it doesn't need to go inside the conditional string. ## PHP - 93 <? //A"%&'()*+[,.]/0123456789:=-@ABCDEFGHIJKLMNOPQRSTUVWYZ\^_abcdefghijklmopqrstuvwxyz{|}~#  Output: nothing The OP asks to print all the unused characters, well, I just use them all • What about <?='A"%&\'()*+[,.]/0123456789:=-@ABCDEFGHIJKLMNOPQRSTUVWYZ\^_abcdefghijklmopqrstuvwxyz{|}~#'? – jocap Sep 1 '14 at 14:24 ## sh (47) tr</dev/urandom -cd $:print:]|tr -d "cat 0"  Uses the self-referential approach. Assumes /dev/urandom will eventually output every octet at least once. Doesn't terminate. If we assume that man is installed, we could instead make use of the ascii(7) manpage (and thus have a terminating program) (44 chars, thanks @fennec). man ascii|tr -cd \[:print:]|tr -d "cat 0"  • Could you use another file, possibly with a shorter name, that's essentially guaranteed to have all possible octets? and might even terminate? I'm thinking like /dev/memory or something. – fennec Jan 30 '14 at 14:20 • @fennec if we assume that man and zsh are installed, man zshall seems to fit the criteria. I could add that as a variation. – FireFly Jan 30 '14 at 18:20 • man ascii could save you another letter, I think. – fennec Jan 31 '14 at 2:51 • Which tr are you using? GNU tr treats the - in "cat 0" as a range operator, which breaks the output. – Toby Speight May 21 at 10:15 • BTW, if the ascii program is installed, you could use that in place of man ascii. – Toby Speight May 21 at 10:16 Definitely the longest solution here, but coding in Lino is always fun: # L.in.oleum - 655 523 characters "libraries"/arch/cpu/base;/hmi/conout;/data/bytes;/data/string/t2s;/data/heap;/data/heap/connect/mgrab;"stockfile"a;"directors"displaystatus=engage;"injection"c=524;b<-bytes.bytesizeconvert:c;b<-heap.alloc:b;a<-heap.alloc:c;[filecommand]=readfile;[filename]=stockfile;[fileposition]=0;[fileblocksize]=c;[fileblockpointer]=b;arch.fileread;[string.psource]=b;[string.ptarget]=a;string.t2s;b<-heap.alloc:7fh;c=32;d=b;"f"[d_32]=c;+c;+d;?c<7fh>f;"w"d=[a];+a;?d=0>y;?d<32>w;?d>7eh>w;e=b;e+d;[e]=33;^w;"y"b+32;"v"conout.say:b;bye;  No comments, just reads the source compiled into binary. Save as a.txt or it won't compile! • Nope, the JSFuck one is longer. – Joe Z. Dec 31 '14 at 20:38 # Brainfuck, 133123114 110 bytes ++++++++++++++++[->++++++>++>+++>++++>++<<<<<]>-->>->->+[---<.+.+<.+<.+<.+.+.+>>>>]++[-<.+.+.+<.+>>]<+.<+.<++.  A bit of more tinkering with a former solution (before I realized the below was smaller - allthough this was before I did some heavy optimization). This works by storing 4 sets of ascii numbers and print them with some tricky looping, and then give the missing characters afterwards (i.e. ones that are between invalid ascii numbers). Original submission >>+++++++++++[<+<+>>->++>+++<<]<++>>++++++>>+++++[-<<<++++++>>>]<<<+<<[->>+.<<]>>++.++<[->+.<]>++.+>[-<+.>]<++.+>>[-<<+.>>]  It does the following: • Create 4 registers containing 11. 13, 28, 33 • Create a 5th with the value 31 to start the printing • Print ascii 32-42 (11) • Print ascii 44 • Print ascii 47-59 (13) • Print ascii 61 • Print ascii 63-90 (28) • Print ascii 92 • Print ascii 94-126 (33) ## Haskell (70) import Data.List main=putStrLn[' '..'~']\\" \\\"'.=DLS[]aimnoprstu~"  The boring duplicate-characters-in-program-in-a-string, subtract-from-universal-set solution. Far from a codegolf winner, though it's surprisingly legible for its length. (Now with list subtraction instead of filter/notWith.) • you can change import Data.List to import List – proud haskeller Aug 28 '14 at 15:06 • .@proudhaskeller huh, really? It doesn't seem to work when I try it with runhaskell: "Could not find module ‘List’". I noticed I'd miscount the number of characters though, so I corrected it. – FireFly Aug 28 '14 at 16:59 • well, that's weird, try it with ghc or ghci? It works for me – proud haskeller Aug 28 '14 at 17:01 • @proudhaskeller nope, can't get it to work. This is with GHC 7.8.3. – FireFly Aug 28 '14 at 17:19 # BitShift, 1038 bytes BitShift is a language which only supports 0 and 1 as syntax. I figured it would be easy to print all other characters, but since it doesn't really support looping it still ended up a massive 1038 bytes. However, I believe it's not really possible to go any smaller than this.. 101001100101011011010100110111010100100101011001101111010100100101011001000101011011010100101100110110101001001010110010001010110110101000001101010010010101100100010101101101010000010000011001010110110101000010000101011011010100110111010100100101011111100101011011010100110111010100100101011001101111010100100101011001000101011011010100000000011010100100101011001000101011011010100110010000101011011010100110111010100100101011001101001101010010010101100100010101101101010011001000010101101101010011011101010010010101111011111110010101101101010011011101010010010101100101100101011011010100010001010110110101001000010101101101010011011101010010010101110111110010101101101010011011101010010010101111111100101011011010100110111010100100101011111011110101001001010110010001010110110101001000100000101011011010100110111010100100101011111010011010100100101011001000101011011010100100000101011011010100110111010100100101011001101111010100100101011001000101011011010100010000010101101101010011011101010010010101101001101101010010010101101001101010  Prints  !"#%&'()*+,-./23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[$^_abcdefghijklmnopqrstuvwxyz{|}~  Try it here # J - 21 (u:32+i.97)-.1!:1<":5  write this to a file called 5 in the current directory. Then load execute the script with 0!:1<'5' Or 25 without the file trick: (-.~".)'(":u:32+i.0-~95)'  • Source code contains ', which isn't removed from the output. – FireFly Jul 13 '14 at 2:52 Clojure (142, 106, 103) (defn -main[](let[c"(fn[l](pr(reduce disj(set(map char(range 32 126)))l)));-\\\"o"]((load-string c)c)))  formatted: (defn -main [] (let [c "(fn[l](pr(reduce disj(set(map char(range 32 126)))l)));-\\\"o"] ((load-string c) c)))  Think this does it, may need some tweaks. output: #{@  ! A B b # C  D % E & F ' G H I * J + K k , L M . N / O 0 P Q q R S 4 T 5 U V v 7 W w 8 X x 9 Y y : Z z { < | = } > ^ ? _}  runs the string, which is evaluateable clojure code, on itself. String has some comments at the end to get the characters used outside of the string (main method, etc) # Cubically, 61 bytes ### Code: ~:5+1-777(B1D1+7)6+33077777(D3B3@6-7)0&2 !"#%'*,./489;<=>?AC  ### Unique characters in program:  !"#%&'()*+,-./0123456789:;<=>?@ABCD~  ### Output: EFGHIJKLMNOPQRSTUVWXYZ[$$^_abcdefghijklmnopqrstuvwxyz{|}
`