215
\$\begingroup\$

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.

\$\endgroup\$
  • 18
    \$\begingroup\$ 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. \$\endgroup\$ – Joe Z. Aug 23 '13 at 19:22
  • 3
    \$\begingroup\$ Are we allowed to print newlines (or any other unprintable ASCII characters)? \$\endgroup\$ – flornquake Aug 24 '13 at 0:30
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Kaz Aug 24 '13 at 2:00
  • 1
    \$\begingroup\$ How did this question get revived? It's started getting upvotes again. \$\endgroup\$ – Joe Z. Jan 31 '14 at 16:38
  • 3
    \$\begingroup\$ @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. \$\endgroup\$ – Joe Z. Feb 1 '14 at 3:01

103 Answers 103

3
\$\begingroup\$

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{|}
\$\endgroup\$
3
\$\begingroup\$

Python 2, 68 83 88 (but it actually reads the file)

No comments, no hacks, it just opens itself, and checks the contents. Includes the set logic from this answer.

print"".join(set(map(chr,range(32,127)))-set(open(__file__).read()))

Changed to print the output and not an array.

\$\endgroup\$
  • 1
    \$\begingroup\$ Outputs the following characters which are in the program: ` 127[]acdefrtx` \$\endgroup\$ – user8943 Aug 24 '13 at 2:24
  • \$\begingroup\$ @ZeroPiraeus I've corrected that, and have met your score! \$\endgroup\$ – user8777 Aug 24 '13 at 5:47
  • 3
    \$\begingroup\$ These are definitely not ASCII characters. ASCII below 32 only contains control codes (Backspace, Bell, etc.), whitespace (CR, LF, tab), and the null char. \$\endgroup\$ – Felix Dombek Aug 24 '13 at 13:25
  • 1
    \$\begingroup\$ @Felix These are from Code page 437 (which starts at U+2639, I believe) \$\endgroup\$ – Doorknob Aug 24 '13 at 15:02
  • 1
    \$\begingroup\$ You can get this down to 62 chars in python3 using @WolframH 's idea: print(*set(map(chr,range(32,127)))-set(open(__file__).read())). Longer by 1 character than the other answer, but more pythonic in my opinion \$\endgroup\$ – Peter Gibson Aug 29 '13 at 1:47
3
\$\begingroup\$

Bash (pure), 93 92 88 bytes

eval "a=$'$(printf '\\x%x' {32..127})'"
while read -rn1 c;do a=${a/"$c"};done<$0
echo $a

Example

cat > foo.sh # now paste and C-d
bash foo.sh  # !#&*+,45689:>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`bgjkmqsuyz|~
wc -c foo.sh # 93 (including end-of-line \n)

Explanation

  • The eval thing: construct a string that looks like \x20\x21...\x7f, and use bash&ksh's c-style-quote $'c-escape-str' to wrap it, in order to escape it into some real list-of-chars.
  • Then we use a while loop to read chars one-by-one, and use the 'replace first occurance' ${var/pat} to kill corresponding chars in $a. Note that we didn't set IFS properly, and read by default will consume \x20, \n and \t. The \x20 part will be handled later.
  • Finally we abuse IFS again so it can eat the space.

The output is in ASCII char order.

This very literal (for code golfs at least) one actually ended up smaller than what I expected it to be. Otherwise I will be thinking about # !&*+abc....

\$\endgroup\$
3
\$\begingroup\$

brainfuck, 90 bytes

++++[->+++>++++++++<<]>-[->.>+<+<]>+.+++>++[-<.<++>+>]<+.++<++[->.>+<+<]>+.++>+++++[-<.+>]

Try it online!

Tape Layout:

[Initial Count Cell] , [Counter Cell One] , [Ascii Cell] , [Counter Cell Two]

Explanation:

++++[->+++>++++++++<<]>-      # sets counter cell one to 11 and ascii cell to 32
[->.>+<+<]                    # prints ascii 32-42 and creates counter cell two
>+.+++>++                     # prints ascii 44 and sets counter cell two to 13
[-<.<++>+>]                   # prints ascii 47-59 and resets counter cell one
<+.++<++                      # prints ascii 61 and sets counter cell one to 28
[->.>+<+<]                    # prints ascii 63-90 and resets counter cell two
>+.++>+++++                   # prints ascii 92 and sets counter cell two to 33
[-<.+>]                       # prints remaining ascii characters

Output:

 !"#$%&'()*,/0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\^_`abcdefghijklmnopqrstuvwxyz{|}~
\$\endgroup\$
3
\$\begingroup\$

R, 72 bytes

cat(intToUtf8(setdiff(32:126,utf8ToInt("\\\"(),12368:ITUacdefinostu"))))

Try it online!

With correction from @JayCe

\$\endgroup\$
  • \$\begingroup\$ nicely done! Beats out the default polyglot by a fair margin! \$\endgroup\$ – Giuseppe May 15 '18 at 18:49
  • 1
    \$\begingroup\$ I think you're missing \\ in the string which costs 2 bytes :( Otherwise I tried to golf it further but couldn't - clever use of setdiff ! \$\endgroup\$ – JayCe May 16 '18 at 20:21
2
\$\begingroup\$

Q, 44

-1"c"$til[128]except"i"$"-1\"c$til[28]exp;";

.

q)-1"c"$til[128]except"i"$"-1\"c$til[28]exp;";
345679:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\^_`abdfghjkmnoqrsuvwyz{|}
\$\endgroup\$
2
\$\begingroup\$

C++ 143

#include<fstream>
#include<iostream>
char c[256],d,e=32;int main(){for(std::fstream i(__FILE__);i>>d;)c[d]++;for(;++e<127;)c[e]||std::cout<<e;}

Alternative version using macros - 155

#include"iostream"
#define d int main(){while(s,*s)l[*s++]++;for(e=35;++e<127;)!l[e]&&std::cout<<e;}
#define t(a)#a
#define f(a)t(a)
char*s=f(d),l[257],e;d

And a version without 'reflection' (examining own source) - 139

#include"iostream"
char h['~'],*a="'()*+,:;<=[]acdefhilmnorstu{}",i='#';int main(){for(;*a;)h[*a++]++;for(;++i<'~';)if(!h[i])std::cout<<i;}
\$\endgroup\$
2
\$\begingroup\$

Bash, with coreutils, 80

p=printf
for o in {32..126};{
c=`$p $($p "\%o" $o)`
grep -qF "$c" $0||$p "$c"
}

Output is:

!#&'}+,/45789:<>}@ABCDEGHIJKLMNOPQRSTUVWXYZ[]^_abhjklmsuvwxyz~
\$\endgroup\$
  • \$\begingroup\$ Never heard about this for v in something; COMPOUND_CMD syntax. Great… \$\endgroup\$ – Arthur2e5 Mar 2 '16 at 8:13
  • \$\begingroup\$ Just a grep replacement, but 5-bytes longer: [[ $(<$0) = *"$c"* ]] \$\endgroup\$ – Arthur2e5 Mar 2 '16 at 8:15
  • \$\begingroup\$ only 3 bytes longer now: remove the double quotes \$\endgroup\$ – Arthur2e5 Feb 19 '18 at 0:04
2
\$\begingroup\$

PowerShell, 75 bytes

[char[]](32..39+42+44+45+47+58..90+92+94..96+98+100..103+105..113+115..126)

A different approach than the other PowerShell answer. Here, we manually build a list of ASCII values (...) that aren't in the source code, then cast that as a char-array [char[]]. PowerShell will by default write out values alone on a line like this, so we get printing for free.

Characters used in code: ()+.0123456789[]achr

\$\endgroup\$
2
\$\begingroup\$

Marbelous, 111 bytes

@0
--7E
<XE\
../\@0
:E\
}0}0
&0&1
{0{>
}0
-F
-E
-5
-4
>0
-7
>D
-F
>0
-2
>0
-2
>0
-3
>3
-2
-6
-8
-9
>0
&0&1
\/\/

Main board loops from 0x7E down to 0x20, E\ function rejects values by decrementing and comparing to small numbers (Marbelous' built in < and > operators only work on the range 0-35).

\$\endgroup\$
2
\$\begingroup\$

Python 2, 62

from string import*;print set(printable)-set(open("p").read())


Code must be saved in a file called p.

Lowest python solution so far ;D

\$\endgroup\$
2
\$\begingroup\$

Bash internals only, 133 bytes

w=printf
while IFS= read -r -n1 r;do i[$($w %d \'$r)]=1;done<$0
for r in {33..126};do [[ 1 -ne ${i[$r]} ]]&& $w \\$($w "%o" $r);done

Save and run with bash <filename>

Explanation

  1. Make printf shorter.
  2. For each char r read from $0 (i.e. the script itself), set i[ord(r)] to 1.
  3. For each number r in range(33, 127), if i[r] is not 1, printf the char corresponding to the number r. The $w \\$($w "%o" $r) part is where the number-to-char magic is: convert the number to OCT, and then prepend a backslash, and finally feed to printf to really print it.

The output is in ASCII order.

\$\endgroup\$
  • \$\begingroup\$ Actually I count 132. You can spare a few more characters: pastebin.com/G8YDBzJj – 113 characters. \$\endgroup\$ – manatwork Jan 31 '14 at 9:59
  • 1
    \$\begingroup\$ This would get my upvote with some explanation about how it works. \$\endgroup\$ – Stéphane Gourichon Mar 19 '15 at 19:37
2
\$\begingroup\$

Java - 111 Bytes

I know I'm 4 years too late, but I just found this question.

void SPARE_VOMIT(){System.out.print(0!=('^'>>8|3&6%2<<~7*4)?"$#/^@\bc[]":'`'-5+"lnbfghjkqwxyz".toUpperCase());}

I tried to put as few characters in the ignored String as possible.

Ungolfed:

void SPARE_VOMIT(){                                   // vomit out all the spare characters
    System.out.print(0 != ('^'>>8|3&6%2<<~7*4) ?             // Both sides here = 0
                     "$#/^@\bc[]"              :             // The shame string...
                     '`'-5 + "lnbfghjkqwxyz".toUpperCase()); // Print 91 and caps.
}
\$\endgroup\$
  • 2
    \$\begingroup\$ SPARE_VOMIT... heh... +1 \$\endgroup\$ – Magic Octopus Urn Aug 3 '17 at 14:51
2
\$\begingroup\$

><>, 44 43 37 35 bytes

crossed out 44 is still regular 44 ;(

" 'r:{-}30{l4-*?.~~:9e*=?;:l2=?o1+}

Try it online!

Outputs !#$%&(),/5678<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdfghijkmnpqstuvwxyz|

How It Works:

"   Wrapping string literal, adding the source code to the stack.
    This adds a space at the start to initialise the counter
  '  Runs another string literal over the whole code
     This means both " and ' are added to the stack
   r:  Get the counter from the bottom of the stack and duplicate it
     {-}  Get the bottom of the stack and check if it is equal to the counter. Push the check to the bottom of the stack
        30  Add 3, 0 to the stack for later
          {l4-*  Get the equality check from the bottom of the stack and OR it with whether the stack is empty of values to check against
               ?.  If the character is equal or the stack is empty, continue. 
                   Else set the instruction pointer to 3,0 to check against the next character
                 ~~  Pop the excess 3,0
                   :9e*=?;  Check if the counter is equal to the 126, the last character, and end if so.
                          :l2=?o  If the stack is empty of values to check (ie the character is not in the code), print it.
                                1+}  Add one to the counter and, because ><> is toroidal, loop back to the beginning
\$\endgroup\$
2
\$\begingroup\$

Memory GAP, 3104 bytes

74b87337454200d4d33f80c4663dc5e5f7bd60b75b29d79b660a2859395c1a240e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf47cef8a734855777c2a9d0caf42666e69b21afc54fb48d153c19101658f4a2a480e9f1e8e40bb79e800b0cc9433830cf40e9f1e8e40bb79e800b0cc9433830cf40e9f1e8e40bb79e800b0cc9433830cf4594f803b380a41396ed63dca39503542f7bd60b75b29d79b660a2859395c1a240e9f1e8e40bb79e800b0cc9433830cf40e9f1e8e40bb79e800b0cc9433830cf40e9f1e8e40bb79e800b0cc9433830cf40e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a092433234ec78fcc91ffb1e54cd85e4a092433234ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a092433247bce5c74f589f4867dbd57e9ca9f808f7bd60b75b29d79b660a2859395c1a2434ec78fcc91ffb1e54cd85e4a092433234ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf4594f803b380a41396ed63dca395035420e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a0924332f7bd60b75b29d79b660a2859395c1a2434ec78fcc91ffb1e54cd85e4a09243320cc175b9c0f1b6a831c399e269772661f7bd60b75b29d79b660a2859395c1a24f24c2c15b9d03797c6874986a8d1951634ec78fcc91ffb1e54cd85e4a0924332faf05c15dfad45dafd1fc23d51236853f0a1dfdc675b0a14a64099f7ac1cee8374b87337454200d4d33f80c4663dc5e5f7bd60b75b29d79b660a2859395c1a240e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf40e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a092433234ec78fcc91ffb1e54cd85e4a09243320cc175b9c0f1b6a831c399e269772661f7bd60b75b29d79b660a2859395c1a2434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf4594f803b380a41396ed63dca39503542f7bd60b75b29d79b660a2859395c1a2434ec78fcc91ffb1e54cd85e4a0924332faf05c15dfad45dafd1fc23d5123685334ec78fcc91ffb1e54cd85e4a09243320cc175b9c0f1b6a831c399e269772661f7bd60b75b29d79b660a2859395c1a24f0a1dfdc675b0a14a64099f7ac1cee83f24c2c15b9d03797c6874986a8d1951634ec78fcc91ffb1e54cd85e4a09243327cef8a734855777c2a9d0caf42666e69b21afc54fb48d153c19101658f4a2a48a87deb01c5f539e6bda34829c8ef2368c68271a63ddbc431c307beb7d2918275852438d026c018c4307b916406f98c6274985f5115ad149212a917dbef8ec801b21afc54fb48d153c19101658f4a2a480cc175b9c0f1b6a831c399e269772661f7bd60b75b29d79b660a2859395c1a2434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf474b87337454200d4d33f80c4663dc5e5f7bd60b75b29d79b660a2859395c1a240e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf40e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243324124bc0a9335c27f086f24ba207a4912f7bd60b75b29d79b660a2859395c1a24f24c2c15b9d03797c6874986a8d1951634ec78fcc91ffb1e54cd85e4a0924332faf05c15dfad45dafd1fc23d5123685374985f5115ad149212a917dbef8ec801

Try it online!

Expanded:

74b87337454200d4d33f80c4663dc5e5f7bd60b75b29d79b660a2859395c1a240e9f1e8e40bb79e8
00b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf4
34ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e
54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf47cef8a734855777c2a9d0caf42666e69
b21afc54fb48d153c19101658f4a2a480e9f1e8e40bb79e800b0cc9433830cf40e9f1e8e40bb79e8
00b0cc9433830cf40e9f1e8e40bb79e800b0cc9433830cf4594f803b380a41396ed63dca39503542
f7bd60b75b29d79b660a2859395c1a240e9f1e8e40bb79e800b0cc9433830cf40e9f1e8e40bb79e8
00b0cc9433830cf40e9f1e8e40bb79e800b0cc9433830cf40e9f1e8e40bb79e800b0cc9433830cf4
34ec78fcc91ffb1e54cd85e4a092433234ec78fcc91ffb1e54cd85e4a092433234ec78fcc91ffb1e
54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a0924332
47bce5c74f589f4867dbd57e9ca9f808f7bd60b75b29d79b660a2859395c1a2434ec78fcc91ffb1e
54cd85e4a092433234ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf4
594f803b380a41396ed63dca395035420e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e
54cd85e4a0924332f7bd60b75b29d79b660a2859395c1a2434ec78fcc91ffb1e54cd85e4a0924332
0cc175b9c0f1b6a831c399e269772661f7bd60b75b29d79b660a2859395c1a24f24c2c15b9d03797
c6874986a8d1951634ec78fcc91ffb1e54cd85e4a0924332faf05c15dfad45dafd1fc23d51236853
f0a1dfdc675b0a14a64099f7ac1cee8374b87337454200d4d33f80c4663dc5e5f7bd60b75b29d79b
660a2859395c1a240e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a0924332
0e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e8
00b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf4
0e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a092433234ec78fcc91ffb1e
54cd85e4a09243320cc175b9c0f1b6a831c399e269772661f7bd60b75b29d79b660a2859395c1a24
34ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf4594f803b380a4139
6ed63dca39503542f7bd60b75b29d79b660a2859395c1a2434ec78fcc91ffb1e54cd85e4a0924332
faf05c15dfad45dafd1fc23d5123685334ec78fcc91ffb1e54cd85e4a09243320cc175b9c0f1b6a8
31c399e269772661f7bd60b75b29d79b660a2859395c1a24f0a1dfdc675b0a14a64099f7ac1cee83
f24c2c15b9d03797c6874986a8d1951634ec78fcc91ffb1e54cd85e4a09243327cef8a734855777c
2a9d0caf42666e69b21afc54fb48d153c19101658f4a2a48a87deb01c5f539e6bda34829c8ef2368
c68271a63ddbc431c307beb7d2918275852438d026c018c4307b916406f98c6274985f5115ad1492
12a917dbef8ec801b21afc54fb48d153c19101658f4a2a480cc175b9c0f1b6a831c399e269772661
f7bd60b75b29d79b660a2859395c1a2434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e8
00b0cc9433830cf474b87337454200d4d33f80c4663dc5e5f7bd60b75b29d79b660a2859395c1a24
0e9f1e8e40bb79e800b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e8
00b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf4
34ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf40e9f1e8e40bb79e8
00b0cc9433830cf434ec78fcc91ffb1e54cd85e4a09243320e9f1e8e40bb79e800b0cc9433830cf4
34ec78fcc91ffb1e54cd85e4a09243324124bc0a9335c27f086f24ba207a4912f7bd60b75b29d79b
660a2859395c1a24f24c2c15b9d03797c6874986a8d1951634ec78fcc91ffb1e54cd85e4a0924332
faf05c15dfad45dafd1fc23d5123685374985f5115ad149212a917dbef8ec801

Explanation

Memory GAP's instructions are md5 hashes of their actual instructions. Using ; as a delimiter, this is the "original" program:

;
aaaa;size;dup;add;dup;add;dup;add;


dup;open;pop;
dup;

dup;
dup;
aaaaa;size;dup;dup;dup;dup;add;add;add;dup;add;aaa;size;add;add;dup;aaaaa;dup;add;size;add;a;size;neg;add;
btwn;

swap;
aaaa;size;dup;add;dup;add;dup;add;dup;dup;add;add;a;size;add;dup;aaaaa;size;add;btwn;
add;

a;size;swap;neg;add;
open;
pop;char;out;nil;shut;pop;

a;size;add;
dup;
aaaa;size;dup;add;dup;add;dup;add;
dup;dup;add;dup;add;aa;size;neg;add;btwn;
shut;

This simply iterates over the range between 32 and 126, and prints it if and only if it does not fall between '0' and '9' or 'a' and 'f'.

\$\endgroup\$
2
\$\begingroup\$

Z80Golf, 83 bytes

00000000: 2b2b 7036 092e 452c 453b 3b78 6f2c 4523  ++p6..E,E;;xo,E#
00000010: 2323 2323 2323 2323 2323 2323 2323 2329  ###############)
00000020: 2929 2929 2929 2929 307e 7620 2122 2425  ))))))))0~v !"$%
00000030: 2627 282a 2d2f 3132 3334 3537 3839 3a3c  &'(*-/12345789:<
00000040: 3d3e 3f40 4142 4344 7172 7374 7577 797a  =>?@ABCDqrstuwyz
00000050: 7b7c 7d                                  {|}

Try it online!

Printable characters aren't too useful in z80, but we can write this:

   dec hl
   dec hl
   ld (hl),b
   ld (hl),9
   ld l,'E'
   inc l
   ld b,l

   dec sp      ; $0009 starts here
   dec sp
   ld a,b
   ld l,a
   inc l
   ld b,l
   inc hl
   inc hl
   inc hl
   inc hl
   inc hl
   inc hl
   inc hl
   inc hl
   inc hl
   inc hl
   inc hl
   inc hl
   inc hl
   inc hl
   inc hl
   inc hl
   add hl,hl
   add hl,hl
   add hl,hl
   add hl,hl
   add hl,hl
   add hl,hl
   add hl,hl
   add hl,hl
   add hl,hl
   jr nc, $+2+'~'
   halt
   db " !\"$%&'(*-/12345789:<=>?@ABCDqrstuwyz{|}"

The idea is to print characters from 'F' to 'n', and put all the remaining characters in the code (the "garbage" string at the end).

The preamble writes 09 (tab) to $fffe, so that we can point SP there to jump to $0009 after putchar. The ld (hl), b achieves nothing; I just get rid of 'p' there.

L is initialized to 'E'+1, and counts up until (HL+17) << 9 overflows (sets the carry), which is when L is 111 = 'o', the first character we don't want to print.

If the carry is not set, we jump over a halt instruction and the garbage string, into thousands of NOPs, the PC eventually running into putchar = $8000 and returning to $0009.

See this answer for some more info on how this code prints characters in the first place.

\$\endgroup\$
  • \$\begingroup\$ nvm I saw that the code had to be printable as well. \$\endgroup\$ – qwr Jun 20 '18 at 19:16
1
\$\begingroup\$

Ruby (50)

puts (?#..?~).to_a.join.tr"()?!#.,~_aijnoprstu",""

Outputs:

$%&'*+-/0123456789:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^`bcdefghklmqvwxyz{|}
\$\endgroup\$
1
\$\begingroup\$

Python, 94

print !"#$%&'90*+,-.0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[/\]^_`abcdefghjklmoqsuvwxyz{|}
\$\endgroup\$
  • 1
    \$\begingroup\$ The "do nothing" solution was already posted. \$\endgroup\$ – Joe Z. Nov 27 '13 at 22:15
  • \$\begingroup\$ @JoeZ. I've changed it to do something \$\endgroup\$ – Timtech Nov 28 '13 at 12:06
1
\$\begingroup\$

Ruby 2.1.0

206 204 characters

chars_in_source = File.read("self.rb").chars.uniq.map(&:ord)
printable_ascii = (20..126).to_a
not_in_source = printable_ascii.reject { |c| chars_in_source.include?(c) }

puts not_in_source.map(&:chr).join

And the output is:

#$%'*+,-/345789;<>@ABCDEGHIJKLMNOPQRSTUVWXYZ[\]^`gkvwxyz~

Not the shortest here (in fact, it might be the longest). But that's the great thing about this: it got me to go try something I'd never done before.

\$\endgroup\$
  • \$\begingroup\$ VariableNamesGreaterThanOneCharacterLongException on line 1 \$\endgroup\$ – CalculatorFeline Mar 2 '16 at 4:38
1
\$\begingroup\$

Python, 88 81 78 77 bytes

actually reads the file

I tried to do it the 'clean' (as in 'easy to read') way, turned out quite nice, although i'm still new to python and probably this can be shortened as well.

file named 'a' is the file executed.

from string import*
for c in printable:
    if c not in open('a').read():print c

And it prints out all the ASCII characters not found in source file. I know this was supposed to be a clever hack (as in all those which contain all the ascii set or addresses, or use an error), but I wanted to do explicitly what was asked :]

Anyone has a suggestion how to make it even shorter while still going in this direction?

[edit] trimmed one more char, thanks for the tip!

\$\endgroup\$
  • 1
    \$\begingroup\$ Timtech's tip makes possible to reduce 1 more character. \$\endgroup\$ – manatwork Jan 31 '14 at 12:30
1
\$\begingroup\$

Javascript 78 chars

bghjklm()seuABCDEFGHIJKLMNOPQRSTUVWXYZvwyz!@#$%^&*1234567890{}[]-=_+\;"'.,<>/?

Outputs:

SyntaxError: Unexpected identifier

Not the shortest code, but threw a try for fun. Notice the colon (:) and space () are covered in Output also.

Feedback appreciated.

\$\endgroup\$
  • \$\begingroup\$ And I just notice now that @xem has already done something similar to my code. Sorry, at CodeGolf people (and xem), if you all consider what I did unknowingly is copying another's work, I will happily delete my answer. \$\endgroup\$ – Gaurang Tandon Jan 31 '14 at 14:54
1
\$\begingroup\$

PYG 0.1 (17):

P(*Se(STP)-Se(Q))

prints

$
,
0
4
8
<
@
D
H
L
X
\
`
d
h
l
p
t
x
|


#
'
+
/
3
7
;
?
C
G
K
O
W
[
_
c
g
k
o
s
w
{
"
&
.
2
6
:
>
B
F
J
N
R
V
Z
^
b
f
j
n
r
v
z
~


!
%
1
5
9
=
A
E
I
M
U
Y
]
a
i
m
q
u
y
}

Not the shortest, but it gets the job done. Also, since I just created this "Language" (it's actually shortend Python), I'll explain what it does.

  • Q gives the program's code
  • STP gives all printable characters
  • Se is equal to Python's set
  • - substracts the two sets
  • * is also the same as python's
  • P prints it.

Knowing this, this would convert to the following python: for i in set(__import__("string").printable)-set(open(__file__).read()): print i

\$\endgroup\$
1
\$\begingroup\$

Befunge, 44 characters

tested in http://www.bedroomlan.org/tools/befunge-93-playground

$#~"01g`!#@_:01>g#1-#0*#:_!> #,!#g!_01g1+01p

it has exactly one quotation mark in the code, so that whenever it is executed, the program enters string mode, reading the code until it loops back to the same quotation mark, stops string mode and continues execution.

it does this for every printable ascii character, rejects it if it's in the code and continues. maybe i'll golf it more later

\$\endgroup\$
1
\$\begingroup\$

CBM BASIC v2.0 - 63

0fori=84+5to127.
3?chr$(i);:next
6rem "!#%&'*,-/<>@abdgjklmpqsuvw
\$\endgroup\$
1
\$\begingroup\$

><>, 86 bytes

Naive implementation : for each character in the 0x20 - 0x7e range, browse its codespace until it reaches the character or the end of the codespace.

' 'v1+>}:{:@@g:?!v{:}=?v30.
>  >00^   0+1v!?~<
^+1;?='~':<          ~~<
~:o       ^  >

Output :

"#$%&()*,-/2456789ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]_`abcdefhijklmnpqrstuwxyz|

This is definitely golfable, I'll try to improve the flow control later.

\$\endgroup\$
1
\$\begingroup\$

Perl 6, 41 bytes

say [~] keys (' '..'~') (-)$*PROGRAM.comb # 41 bytes
IYZnCpl?W8|}K!^i"`Bhuvw6F<\S,=JrVLQE54%Xqg_1{/3+Tjx#Ht&;7>02@ND:9Udfz

The reason the order of the output is random is that the Set Minus operator (-) produces a Set, which is inherently unordered.

\$\endgroup\$
1
\$\begingroup\$

Javascript/coffeescript/actionscript/more, 96

// #qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890~`!@$%^&*()-_=+[{]}\|;:'",<.>?


Other languages it works in are basically anything with // comments (and doesn't need something like class a{public static void main(String[]a){) This also works in Perl 5 (Thanks @BradGilbertb2gills for pointing that out!)

\$\endgroup\$
  • \$\begingroup\$ I was just about to comment that this would work in almost any language... \$\endgroup\$ – Sparr Nov 18 '15 at 23:47
  • \$\begingroup\$ # qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890~`!@/$%^&*()-_=+[{]}\|;:'",<.>? Python - 95 bytes EDIT: Damn code blocks \$\endgroup\$ – DJgamer98 Nov 19 '15 at 14:59
  • \$\begingroup\$ If you placed the # character before qwerty then it will also work in Perl 5. \$\endgroup\$ – Brad Gilbert b2gills Nov 29 '15 at 19:16
  • \$\begingroup\$ @BradGilbertb2gills cool! \$\endgroup\$ – ev3commander Nov 29 '15 at 21:17
  • \$\begingroup\$ Perl 5 will either see // as a null regex, or a defined-or operator. (say undef // 1) I'm not sure which. ( If it is the latter, it may only work on 5.10 or newer ) \$\endgroup\$ – Brad Gilbert b2gills Nov 29 '15 at 21:41
1
\$\begingroup\$

Lua, 94 bytes

f="l=...for i=32,126 do c=string.char(i)io.write(l:find(c,0,1)and\"\"or c)end"loadstring(f)(f)

Writes the algorithm in a string and uses loadstring to run it as a function passing in its string definition as the argument.

\$\endgroup\$
  • \$\begingroup\$ Hello, and welcome to Programming Puzzles and Code Golf! Great answer! \$\endgroup\$ – NoOneIsHere May 10 '16 at 23:25
1
\$\begingroup\$

Smalltalk - 47

^#DI,($ to:$~)difference:thisContext sourceCode

This works in Squeak 6.x and produces the String:

'!"%&''*+-./0123456789;<=>?@ABEFGHJKLMNOPQRSTUVWXYZ[\]_`abgjklmpqvwyz{|}'
  • ($ to:$~) forms a left String ranging the 95 characters
  • thisContext sourceCode produces a decompileString of the snippet
  • difference: reject all the caracters from the left String that appears in the decompileString.
  • #DI, which concatenates a Symbol with letters D and I to left String is here to make those 2 letters appear in code.
    It is necessary because the decompileString prefixes the snippet with DoIt ^ which is the name of the pseudo-method. Those letters will thus be removed.
    Same for the leading ^ that indicates to return the result, it is in the decompileString so has to be in the code even if optional
    Letters o and t are already in source code, so it's OK.
  • 'DI', would work but result string is printed with quotes ' so source must not have quotes
  • "DI" would be even shorter, unfortunately decompileString remove comments
  • We could eliminate method name with ($ to:$~)difference:(thisContext sourceCode last:52) but it is longer (52)

The code consumes 25 different characters, and thus produces 70 different characters (among 73, quote ' appearing 3 more times for printing the String)

\$\endgroup\$
1
\$\begingroup\$

RProgN 2, 24 bytes

{`{.` `~Rx={x\-`x=};x.}{

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.