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

52
\$\begingroup\$

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.

\$\endgroup\$
271
\$\begingroup\$

Polyglot, 95

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

Does nothing.

\$\endgroup\$
  • 17
    \$\begingroup\$ No, but this is a polygot. I don't want to destroy that. \$\endgroup\$ – Johannes Kuhn Aug 23 '13 at 16:26
  • 89
    \$\begingroup\$ I fed this into the GNU Fortran compiler and it segfaulted. \$\endgroup\$ – marinus Aug 23 '13 at 16:43
  • 11
    \$\begingroup\$ In C, #undef X;whatever junk you want works. \$\endgroup\$ – ugoren Aug 23 '13 at 16:56
  • 84
    \$\begingroup\$ "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 \$\endgroup\$ – msb Aug 27 '13 at 23:33
  • 6
    \$\begingroup\$ @JoeZ. I know, just kidding, trying to bend the interpretation of the definition to favour the most creative answer IMO. ;-) \$\endgroup\$ – msb Sep 4 '13 at 0:27
141
\$\begingroup\$

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
\$\endgroup\$
  • 41
    \$\begingroup\$ Haha, nice bending of the rules. \$\endgroup\$ – Johannes Kuhn Aug 27 '13 at 19:12
  • 5
    \$\begingroup\$ Nice, but unfortunately I can spot a : in the output. \$\endgroup\$ – Howard Aug 28 '13 at 4:57
  • 11
    \$\begingroup\$ -1; meta.codegolf.stackexchange.com/a/1072/11066 \$\endgroup\$ – The Guy with The Hat Feb 27 '14 at 17:47
  • 75
    \$\begingroup\$ I appreciate it, @TheGuywithTheHat, but I answered this about a year ago, as opposed to yesterday. \$\endgroup\$ – Ry- Feb 27 '14 at 18:07
  • 8
    \$\begingroup\$ @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. \$\endgroup\$ – Johannes Kuhn Oct 17 '14 at 14:27
48
\$\begingroup\$

JavaScript - 88

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

prints "bcdfghijkmnpquvxyz"

\$\endgroup\$
  • 12
    \$\begingroup\$ Wow I like the toLowerCase idea, it's brilliant! \$\endgroup\$ – Pierre Arlaud Nov 29 '13 at 15:20
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – Umbrella Mar 12 '18 at 12:40
27
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ 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) \$\endgroup\$ – r.e.s. Aug 25 '13 at 16:24
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – r.e.s. Aug 25 '13 at 19:39
  • \$\begingroup\$ I know it's been over 5 years, but you can golf 5 bytes by changing the label S to label (empty) (LSSSL becomes LSSL and LTTSL becomes LTTL) and remove the exit at the end (the three LLL). Try it online raw 52 bytes or here with highlighting and explanation. \$\endgroup\$ – Kevin Cruijssen Dec 10 '18 at 15:18
22
\$\begingroup\$

C, 83 74 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.

\$\endgroup\$
21
\$\begingroup\$

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.

\$\endgroup\$
  • 2
    \$\begingroup\$ Damn, that's clever. \$\endgroup\$ – marinus Aug 23 '13 at 17:28
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ – Howard Aug 23 '13 at 18:17
  • \$\begingroup\$ And utilising in any order, however many times you want you can also remove the semicolon. \$\endgroup\$ – Howard Aug 23 '13 at 18:52
  • \$\begingroup\$ @Howard I'm afraid I don't understand your idea. You can post it as a separate answer. \$\endgroup\$ – John Dvorak Aug 23 '13 at 18:53
  • \$\begingroup\$ @PeterTaylor I thought I printed a space? \$\endgroup\$ – John Dvorak Aug 23 '13 at 19:05
20
\$\begingroup\$

Fish - 80

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

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

\$\endgroup\$
17
\$\begingroup\$

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.
\$\endgroup\$
  • \$\begingroup\$ can you explain a bit? \$\endgroup\$ – joey rohan Oct 1 '13 at 18:01
  • 1
    \$\begingroup\$ @joeyrohan Sure, just added an explanation below it. :) \$\endgroup\$ – asteri Oct 1 '13 at 18:10
  • \$\begingroup\$ cool ;) nice stuff :) \$\endgroup\$ – joey rohan Oct 1 '13 at 18:12
  • 2
    \$\begingroup\$ You could put the ENTIRE ascii printable table in a comment and make a java programm that returns nothing. It'd beat yours :-) \$\endgroup\$ – Pierre Arlaud Nov 28 '13 at 13:29
  • 9
    \$\begingroup\$ You could have told me that this is going to print every single Unicode character before I executed it in my terminal. \$\endgroup\$ – nyuszika7h Jun 14 '14 at 20:55
14
\$\begingroup\$

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.

\$\endgroup\$
14
\$\begingroup\$

Ruby, 81 78 68 66 62 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!

\$\endgroup\$
  • \$\begingroup\$ Can't you put the if after the $><<x to save one of the end lines? \$\endgroup\$ – Josh Aug 23 '13 at 23:10
  • \$\begingroup\$ @Josh Yes. I will do that now. \$\endgroup\$ – Doorknob Aug 23 '13 at 23:26
  • \$\begingroup\$ You can take it to 58: (?!..?~).map{|x|$><<x if/[()ifmap{}|x?!.~\/\\\[\]$><]/!~x} \$\endgroup\$ – Ry- Aug 25 '13 at 15:15
  • 1
    \$\begingroup\$ Ah, and with a better choice of variable name, 57: (?!..?~).map{|a|$><<a if/[()ifmap{}|?!.~\/\\\[\]$><]/!~a} \$\endgroup\$ – Ry- Aug 25 '13 at 15:18
  • \$\begingroup\$ $><<((32..126).map(&:chr)-IO.read(__FILE__).chars).join 55 bytes using a different approach. \$\endgroup\$ – twe4ked Mar 12 '17 at 22:36
14
\$\begingroup\$

Befunge (48)

<|::-1,+*88:<+3*87
6<@.**85
9>"()~&"/%$ |!#';=?}

Outputs: {zyxwvutsrqponmlkjihgfedcba`_^][ZYXWVUTSRQPONMLKJIHGFEDCBA240

\$\endgroup\$
  • \$\begingroup\$ Holy cow! Nice work! \$\endgroup\$ – Cruncher Nov 28 '13 at 18:21
12
\$\begingroup\$

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 ()+[]!

\$\endgroup\$
  • 2
    \$\begingroup\$ (x) <=> [x][+[]], increases code size but makes the alphabet needed smaller. \$\endgroup\$ – FireFly Oct 3 '13 at 21:18
12
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ "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. \$\endgroup\$ – FireFly Oct 4 '13 at 18:11
  • 1
    \$\begingroup\$ You'll at least want to add ~ to the set of excluded characters. ;-) Btw, a similar J solution would be a.-.'a.-''' \$\endgroup\$ – FireFly Oct 4 '13 at 19:14
  • 2
    \$\begingroup\$ You can Ignore All Rules, but that does disqualify you from being the accepted answer. \$\endgroup\$ – Joe Z. Oct 12 '13 at 2:35
11
\$\begingroup\$

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).

\$\endgroup\$
11
\$\begingroup\$

Brainfuck, 173

+++++[->++++++<]>>>++[------<+>]<++++>>----[----<+>]>-[-------<+>]>-[---<+>]<------->>-[---<+>]<+++++++++>>--[-----<+>]<+++++>>+[---------<++>]+++++++++++++[<[.+<]>[>]<-]\=,

Pretty long, I might try again later.

\$\endgroup\$
  • 6
    \$\begingroup\$ write a program that does nothing and add the rest od ascii to the source, worst case feels like 96 characters. \$\endgroup\$ – Jasen Dec 27 '14 at 2:13
10
\$\begingroup\$

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.
\$\endgroup\$
  • \$\begingroup\$ @JanDvorak: whoops typo \$\endgroup\$ – marinus Aug 23 '13 at 16:34
  • \$\begingroup\$ 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 \$\endgroup\$ – Doorknob Aug 23 '13 at 17:08
  • \$\begingroup\$ The new one looks much more quiney. \$\endgroup\$ – John Dvorak Aug 23 '13 at 17:10
  • 1
    \$\begingroup\$ @Doorknob: I have one in APL that's only 24 characters but it has non-ASCII characters in it. \$\endgroup\$ – marinus Aug 23 '13 at 17:11
  • \$\begingroup\$ Yeah, I did the ASCII thing to avoid languages like APL. \$\endgroup\$ – Joe Z. Aug 23 '13 at 19:38
7
\$\begingroup\$

Python 3 - 68 61

x=r"print(*set(map(chr,range(32,127)))-set(x+'=\"'))"
exec(x)

... thanks to @WolframH for the improvements.

\$\endgroup\$
  • 1
    \$\begingroup\$ 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). \$\endgroup\$ – WolframH Aug 24 '13 at 22:46
  • \$\begingroup\$ @WolframH ingenious, thanks! \$\endgroup\$ – user8943 Aug 24 '13 at 23:13
7
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Sane and instructive. \$\endgroup\$ – Stéphane Gourichon Mar 19 '15 at 19:35
7
\$\begingroup\$

PHP - 92

<? //A"$%&'()*+[,.]0123456789:=-@ABCDEFGHIJKLMNOPQRSTUVWYZ\^_`abcdefghijklmopqrstuvwxyz{|}~#

Output:

nothing

The OP asks to print all the unused characters, well, I just use them all

\$\endgroup\$
  • \$\begingroup\$ What about <?='A"$%&\'()*+[,.]/0123456789:=-@ABCDEFGHIJKLMNOPQRSTUVWYZ\^_`abcdefghijklmopqrstuvwxyz{|}~#'? \$\endgroup\$ – jocap Sep 1 '14 at 14:24
  • \$\begingroup\$ I knew that there would be a submission that just uses all the characters. \$\endgroup\$ – MilkyWay90 Feb 20 at 16:34
  • \$\begingroup\$ This doesn't use the characters !;>Xn \$\endgroup\$ – Jo King Apr 12 at 3:42
6
\$\begingroup\$

Javascript, 92

(function f(){for(i=32;126>i++;)!~(""+f).indexOf(c=String.fromCharCode(i))&&console.log(c)})()
\$\endgroup\$
  • \$\begingroup\$ Is this a fair solution? alert(' !"#$%^*+/-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`bcdfghijkmnopqsuvwxyz{|}~') Comes in at 95 chars and is dumb as hell. :p \$\endgroup\$ – tristin Oct 2 '13 at 18:59
  • 2
    \$\begingroup\$ @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 :) \$\endgroup\$ – C5H8NNaO4 Oct 3 '13 at 9:09
  • 1
    \$\begingroup\$ Haha, oops. Oh well. \$\endgroup\$ – tristin Oct 3 '13 at 19:09
6
\$\begingroup\$

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.

\$\endgroup\$
6
\$\begingroup\$

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`"
\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – fennec Jan 30 '14 at 14:20
  • \$\begingroup\$ @fennec if we assume that man and zsh are installed, man zshall seems to fit the criteria. I could add that as a variation. \$\endgroup\$ – FireFly Jan 30 '14 at 18:20
  • \$\begingroup\$ man ascii could save you another letter, I think. \$\endgroup\$ – fennec Jan 31 '14 at 2:51
  • \$\begingroup\$ Which tr are you using? GNU tr treats the - in "cat $0" as a range operator, which breaks the output. \$\endgroup\$ – Toby Speight May 21 '18 at 10:15
  • \$\begingroup\$ BTW, if the ascii program is installed, you could use that in place of man ascii. \$\endgroup\$ – Toby Speight May 21 '18 at 10:16
5
\$\begingroup\$

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

\$\endgroup\$
4
\$\begingroup\$

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!

\$\endgroup\$
  • 4
    \$\begingroup\$ Nope, the JSFuck one is longer. \$\endgroup\$ – Joe Z. Dec 31 '14 at 20:38
4
\$\begingroup\$

Brainfuck, 133 123 114 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)
\$\endgroup\$
4
\$\begingroup\$

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.)

\$\endgroup\$
  • \$\begingroup\$ you can change import Data.List to import List \$\endgroup\$ – proud haskeller Aug 28 '14 at 15:06
  • \$\begingroup\$ .@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. \$\endgroup\$ – FireFly Aug 28 '14 at 16:59
  • 1
    \$\begingroup\$ well, that's weird, try it with ghc or ghci? It works for me \$\endgroup\$ – proud haskeller Aug 28 '14 at 17:01
  • \$\begingroup\$ @proudhaskeller nope, can't get it to work. This is with GHC 7.8.3. \$\endgroup\$ – FireFly Aug 28 '14 at 17:19
3
\$\begingroup\$

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)'
\$\endgroup\$
  • \$\begingroup\$ Source code contains ', which isn't removed from the output. \$\endgroup\$ – FireFly Jul 13 '14 at 2:52
3
\$\begingroup\$

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)

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

Python 2, 69

for x in range(38):print chr(x+59)#!"$%&'*,-./012467bdjklmqsuvwyz{|}~

I use the longest (that I'm able to find) sequence of continuous chars I can print out and add the others as a comment after the code.

\$\endgroup\$
  • 8
    \$\begingroup\$ I'm not going to upvote anything that has a comment \$\endgroup\$ – John Dvorak Aug 23 '13 at 16:46
  • \$\begingroup\$ My answer should show the worst possible way to solve this task. (Use the comment loophole). \$\endgroup\$ – Johannes Kuhn Aug 23 '13 at 16:52
  • 9
    \$\begingroup\$ ok... except for that polyglot that is nothing but a comment. \$\endgroup\$ – John Dvorak Aug 23 '13 at 17:04
  • \$\begingroup\$ @JohannesKuhn However, as it's the longest code that works, it won't win the contest. :P \$\endgroup\$ – Joe Z. Aug 23 '13 at 17:11
  • 5
    \$\begingroup\$ @JoeZ. it wins by a wide margin if you divide by the number of languages it works in \$\endgroup\$ – John Dvorak Aug 23 '13 at 19:09

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.