240
\$\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\$
15
  • 23
    \$\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.
    Commented Aug 23, 2013 at 19:22
  • 4
    \$\begingroup\$ Are we allowed to print newlines (or any other unprintable ASCII characters)? \$\endgroup\$
    – flornquake
    Commented Aug 24, 2013 at 0:30
  • 2
    \$\begingroup\$ How did this question get revived? It's started getting upvotes again. \$\endgroup\$
    – Joe Z.
    Commented Jan 31, 2014 at 16:38
  • 7
    \$\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.
    Commented Feb 1, 2014 at 3:01
  • 2
    \$\begingroup\$ Can we output non-ASCII characters as well? \$\endgroup\$ Commented Nov 23, 2017 at 16:19

114 Answers 114

295
\$\begingroup\$

Polyglot, 95

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

Does nothing.

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

PHP 5.2, 4 + 69

<?<<

Save as a file called !"#$%&'()*+-.023456789;=>@ABCDEFGIJKMNOQRUVWXYZ[\]^`bfghjkmqvwz{|}~. short_open_tag needs to be On in your php.ini.

The output is:

PHP Parse error:  syntax error, unexpected T_SL in /wherever/!"#$%&\'()*+-.023456789;=>@ABCDEFGIJKMNOQRUVWXYZ[\\]^`bfghjkmqvwz{|}~ on line 1
\$\endgroup\$
5
  • 47
    \$\begingroup\$ Haha, nice bending of the rules. \$\endgroup\$ Commented Aug 27, 2013 at 19:12
  • 1
    \$\begingroup\$ I considered doing something similar with bash, but didn't because I thought it was too obvious to be interesting. \$\endgroup\$ Commented Aug 28, 2013 at 8:12
  • 2
    \$\begingroup\$ I believe output is assumed to be stdout. This does not print to stdout. \$\endgroup\$
    – Cruncher
    Commented Nov 28, 2013 at 14:46
  • 1
    \$\begingroup\$ Not all filesystems support naming files things like that. \$\endgroup\$ Commented Nov 28, 2013 at 22:26
  • \$\begingroup\$ Doesn't work in newer PHP versions since they fixed the confusing error message (now it includes the "<" in the error). It's still a cool solution though! \$\endgroup\$
    – FIQ
    Commented Feb 4, 2014 at 11:50
58
\$\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\$
0
52
\$\begingroup\$

JavaScript - 88

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

prints "bcdfghijkmnpquvxyz"

\$\endgroup\$
3
  • 17
    \$\begingroup\$ Wow I like the toLowerCase idea, it's brilliant! \$\endgroup\$ Commented Nov 29, 2013 at 15:20
  • 7
    \$\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
    Commented Mar 12, 2018 at 12:40
  • \$\begingroup\$ @Umbrella 82 \$\endgroup\$
    – l4m2
    Commented Jan 9, 2023 at 7:37
29
\$\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\$
3
  • 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.
    Commented Aug 25, 2013 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.
    Commented Aug 25, 2013 at 19:39
  • 1
    \$\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\$ Commented Dec 10, 2018 at 15:18
27
\$\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\$
1
  • 4
    \$\begingroup\$ 69 characters, nice \$\endgroup\$
    – galois
    Commented Oct 16, 2019 at 16:00
26
\$\begingroup\$

><> - 80

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

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

\$\endgroup\$
22
\$\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\$
5
  • 2
    \$\begingroup\$ Damn, that's clever. \$\endgroup\$
    – marinus
    Commented Aug 23, 2013 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
    Commented Aug 23, 2013 at 18:17
  • \$\begingroup\$ And utilising in any order, however many times you want you can also remove the semicolon. \$\endgroup\$
    – Howard
    Commented Aug 23, 2013 at 18:52
  • \$\begingroup\$ @Howard I'm afraid I don't understand your idea. You can post it as a separate answer. \$\endgroup\$ Commented Aug 23, 2013 at 18:53
  • \$\begingroup\$ @PeterTaylor I thought I printed a space? \$\endgroup\$ Commented Aug 23, 2013 at 19:05
19
\$\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\$
11
  • \$\begingroup\$ can you explain a bit? \$\endgroup\$
    – joey rohan
    Commented Oct 1, 2013 at 18:01
  • 1
    \$\begingroup\$ @joeyrohan Sure, just added an explanation below it. :) \$\endgroup\$
    – asteri
    Commented Oct 1, 2013 at 18:10
  • 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\$ Commented Nov 28, 2013 at 13:29
  • 10
    \$\begingroup\$ You could have told me that this is going to print every single Unicode character before I executed it in my terminal. \$\endgroup\$
    – user344
    Commented Jun 14, 2014 at 20:55
  • 1
    \$\begingroup\$ You can save a character by changing it to indexOf(++c) and removing the c++ inside the for loop \$\endgroup\$
    – Daniel M.
    Commented May 9, 2016 at 14:54
16
\$\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\$
15
\$\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\$
6
  • \$\begingroup\$ Can't you put the if after the $><<x to save one of the end lines? \$\endgroup\$
    – Josh
    Commented Aug 23, 2013 at 23:10
  • \$\begingroup\$ @Josh Yes. I will do that now. \$\endgroup\$
    – Doorknob
    Commented Aug 23, 2013 at 23:26
  • \$\begingroup\$ You can take it to 58: (?!..?~).map{|x|$><<x if/[()ifmap{}|x?!.~\/\\\[\]$><]/!~x} \$\endgroup\$
    – Ry-
    Commented Aug 25, 2013 at 15:15
  • 1
    \$\begingroup\$ Ah, and with a better choice of variable name, 57: (?!..?~).map{|a|$><<a if/[()ifmap{}|?!.~\/\\\[\]$><]/!~a} \$\endgroup\$
    – Ry-
    Commented Aug 25, 2013 at 15:18
  • \$\begingroup\$ $><<((32..126).map(&:chr)-IO.read(__FILE__).chars).join 55 bytes using a different approach. \$\endgroup\$
    – twe4ked
    Commented Mar 12, 2017 at 22:36
15
\$\begingroup\$

Befunge (48)

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

Outputs: {zyxwvutsrqponmlkjihgfedcba`_^][ZYXWVUTSRQPONMLKJIHGFEDCBA240

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Holy cow! Nice work! \$\endgroup\$
    – Cruncher
    Commented Nov 28, 2013 at 18:21
14
\$\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
12
\$\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\$
2
12
\$\begingroup\$

Brainfuck, 173

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

Pretty long, I might try again later.

\$\endgroup\$
1
  • 9
    \$\begingroup\$ write a program that does nothing and add the rest od ascii to the source, worst case feels like 96 characters. \$\endgroup\$
    – Jasen
    Commented Dec 27, 2014 at 2:13
11
\$\begingroup\$

J (52 40)

Edit: Duh, forgot about e.

'''([email protected]#[)~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\$
6
  • \$\begingroup\$ @JanDvorak: whoops typo \$\endgroup\$
    – marinus
    Commented Aug 23, 2013 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
    Commented Aug 23, 2013 at 17:08
  • \$\begingroup\$ The new one looks much more quiney. \$\endgroup\$ Commented Aug 23, 2013 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
    Commented Aug 23, 2013 at 17:11
  • \$\begingroup\$ Yeah, I did the ASCII thing to avoid languages like APL. \$\endgroup\$
    – Joe Z.
    Commented Aug 23, 2013 at 19:38
8
\$\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\$
2
  • 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\$ Commented Aug 24, 2013 at 22:46
  • \$\begingroup\$ Massively late, I know, but with some new Python 3 tricks you can take it down to 55 chars: x=r"print(*{*map(chr,range(32,127))}-{*x})#=\""\nexec(x). \$\endgroup\$
    – sagiksp
    Commented Oct 21, 2019 at 12:52
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\$
1
  • \$\begingroup\$ Sane and instructive. \$\endgroup\$ Commented Mar 19, 2015 at 19:35
7
\$\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\$
7
\$\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\$
6
\$\begingroup\$

Javascript, 92

(function f(){for(i=32;126>i++;)!~(""+f).indexOf(c=String.fromCharCode(i))&&console.log(c)})()
\$\endgroup\$
3
  • \$\begingroup\$ Is this a fair solution? alert(' !"#$%^*+/-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`bcdfghijkmnopqsuvwxyz{|}~') Comes in at 95 chars and is dumb as hell. :p \$\endgroup\$
    – tristin
    Commented Oct 2, 2013 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
    Commented Oct 3, 2013 at 9:09
  • 1
    \$\begingroup\$ Haha, oops. Oh well. \$\endgroup\$
    – tristin
    Commented Oct 3, 2013 at 19:09
5
\$\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\$
5
\$\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\$
5
  • \$\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\$
    – user15703
    Commented Jan 30, 2014 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
    Commented Jan 30, 2014 at 18:20
  • \$\begingroup\$ man ascii could save you another letter, I think. \$\endgroup\$
    – user15703
    Commented Jan 31, 2014 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\$ Commented May 21, 2018 at 10:15
  • \$\begingroup\$ BTW, if the ascii program is installed, you could use that in place of man ascii. \$\endgroup\$ Commented May 21, 2018 at 10:16
5
\$\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\$
6
  • 9
    \$\begingroup\$ I'm not going to upvote anything that has a comment \$\endgroup\$ Commented Aug 23, 2013 at 16:46
  • \$\begingroup\$ My answer should show the worst possible way to solve this task. (Use the comment loophole). \$\endgroup\$ Commented Aug 23, 2013 at 16:52
  • 11
    \$\begingroup\$ ok... except for that polyglot that is nothing but a comment. \$\endgroup\$ Commented Aug 23, 2013 at 17:04
  • \$\begingroup\$ @JohannesKuhn However, as it's the longest code that works, it won't win the contest. :P \$\endgroup\$
    – Joe Z.
    Commented Aug 23, 2013 at 17:11
  • 6
    \$\begingroup\$ @JoeZ. it wins by a wide margin if you divide by the number of languages it works in \$\endgroup\$ Commented Aug 23, 2013 at 19:09
5
\$\begingroup\$

Vyxal, 11 bytes

I don't think I saw any Vyxal on here! Prints all printable ASCII with kQ and filters chars out with F

kQ`\kQF\``F

Try it Online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Welcome to Code Golf, and nice answer! \$\endgroup\$
    – rydwolf
    Commented Sep 22, 2023 at 22:50
  • 1
    \$\begingroup\$ @RydwolfPrograms Thank you! Happy to be here! \$\endgroup\$
    – ffseq
    Commented Sep 22, 2023 at 22:54
  • 1
    \$\begingroup\$ Welcome to the vyxal crew :p \$\endgroup\$
    – lyxal
    Commented Sep 22, 2023 at 23:41
  • 1
    \$\begingroup\$ @lyxal Good documentation, great balance between readability and conciseness. What's not to love?? \$\endgroup\$
    – ffseq
    Commented Sep 22, 2023 at 23:48
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\$
1
  • 5
    \$\begingroup\$ Nope, the JSFuck one is longer. \$\endgroup\$
    – Joe Z.
    Commented Dec 31, 2014 at 20:38
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\$
4
  • \$\begingroup\$ you can change import Data.List to import List \$\endgroup\$ Commented Aug 28, 2014 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
    Commented Aug 28, 2014 at 16:59
  • 1
    \$\begingroup\$ well, that's weird, try it with ghc or ghci? It works for me \$\endgroup\$ Commented Aug 28, 2014 at 17:01
  • \$\begingroup\$ @proudhaskeller nope, can't get it to work. This is with GHC 7.8.3. \$\endgroup\$
    – FireFly
    Commented Aug 28, 2014 at 17:19
4
\$\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\$
1
  • 3
    \$\begingroup\$ SPARE_VOMIT... heh... +1 \$\endgroup\$ Commented Aug 3, 2017 at 14:51
4
\$\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\$
1
4
\$\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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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