# Output all of printable ASCII using all of printable ASCII

Output all 95 bytes from 0x20 to 0x7E inclusive (printable ASCII including space), in any order, each at least once. The source code of your program must use all of those bytes, each at least once.

• Your program must be irreducible (meaning you cannot strictly remove some characters from the program and then have it still function correctly), so you can't just add a comment containing the remaining characters
• Your program, and its output, can contain any additional bytes outside this range if you like (bytes, not characters), such as newlines
• You must output them as bytes, not decimal code-points or anything else like that
• Standard rules and loopholes apply
• This is Code Golf, so the shortest program in bytes wins (even though all programs will be at least 95 characters)
• For irreducibility, must the removed characters be consecutive? And does "function correctly" mean to still produce the same output? – xnor Oct 14 at 19:35
• So let me see if I understand the irreducibility condition. Is it that "There does not exist a shorter program obtained by deleting some of the characters in the original that also outputs the required 95 bytes, regardless of whether this shorter program uses all 95 distinct bytes"? – xnor Oct 14 at 19:42
• I've downvoted this as it leaves no room for creativity; the optimal solution in pretty much every language is going to be the literal string. – Shaggy Oct 14 at 20:20
• Actually I don't agree that it's necessarily boring. Getting 96 or 97 bytes is quite straightforward, by using a literal string. Getting 95 bytes seems much more tricky (if possible at all): and this seems to be born-out by the small number of answers that have achieved this so far... – Dominic van Essen Oct 15 at 9:40
• @Shaggy Update: after finally managing to get 95 bytes in Husk, I'm all the more convinced that this isn't a trivial challenge at all... This can't be done with the literal string. – Dominic van Essen Oct 15 at 11:39

# Husk, 95 95 bytes

Edit: adjusted to fix bug pointed-out by Neil. Same bytes

mcW=2R\.5+46L" !#$%&'()*,-/013789:;<=?@ABCDEFGHIJKMNOPQSTUVXYZ[]^_abdefghijklnopqrstuvwxyz{|}~  Try it online! Well, 96 bytes in Husk is trivial as a literal string, but 95 bytes was much more tricky. The strategy that I've used is to (1) output all 95 printable ASCII characters using a program written using only non-repeating ASCII characters (this isn't completely straightforward, since many of the useful commands in Husk are encoded by non-ASCII characters), and then (2) to adjust it so that output is dependent on the length of a literal string containing all the unused characters: this second bit will ensure that all the characters are used, and also that the program is irreducible. Here's how it works: mcW=2R\.5+46L"... m # map this function: c # ASCII character # across all the elements in this list: W # indexes of all elements that satisfy: =2 # are equal to 2 # among all the elements in this list: R # repeat this value: \ # reciprocal of .5 # .5 # this number of times: +46 # add 46 to L # the length of "... # this string # the string consists of all the printable ASCII characters, # with the characters of the program removed. There are 15 # characters in the program, so the remaining 95-15=80 characters # are all present in the string. # So, to output all the ASCII characters up to # 126, we need to add 126-80 = 46.  • So... how is this not irreducible modulo deletion of the \? – Neil Oct 16 at 12:15 • @Neil - Shit! You're right! ...will try to think of a solution! – Dominic van Essen Oct 16 at 12:51 • @Neil - Fixed now, I think. Thank goodness. I wasn't sure it would work at all... Please don't find any more bugs! – Dominic van Essen Oct 16 at 13:30 # Self-modifying Brainfuck, 95 bytes +[.<] !"#$%&'()*,-/0123456789:;=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\^_abcdefghijklmnopqrstuvwxyz{|}~


Try it online!

The + in the beginning is just to enter the loop, [.<] prints the source code backwards.

• Lovely. It's nice to see some actual programming to achieve 95 bytes. Well done. – Dominic van Essen Oct 15 at 14:50

print(' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~')  ;) Try it online! • This could be improved by removing some characters already used by print('') (ex. (, ), ', p, r, i, n, t – Nosrep Oct 15 at 16:14 • @Nosrep It still would need to output those characters, so you can't just remove them from the string. – Xcali Oct 15 at 18:29 • @Nosrep: You still have to somehow output them, though, don't you? – Eric Duminil Oct 15 at 19:22 • Ah, misread the question, sorry. – Nosrep Oct 16 at 0:09 # R & likely polyglot, 97 bytes " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~"


Try it online!

2 wasted characters: the second """ to close the string, and the need to use "\\" to escape the escaping function of the "\" character.

This 'program' will probably function in most languages that (like R) output unassigned strings (or other variables & expressions) by default, and so is a very likely polyglot.

I suspect, though, that most languages will require at least one character (often a quotation mark or similar, as used here) to specify a string, and not all languages output the string together with surrounding quotation marks (or whatever). R does, which is beneficial here, but getting down to 95 bytes might only work for a few, if any...

• Yes. That's why I indicated 'likely polyglot'... – Dominic van Essen Oct 14 at 19:31

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~  Text programs always print their contents. • "almost all ASCII files, including readmes, and interpreted programming language source code files, are actually written in Text. " LOL – pxeger Oct 14 at 20:03 • Also polyglot in Charcoal: Try it online! – Neil Oct 14 at 20:05 • This doesn't seem to qualify as a programming language according to our standards – Luis Mendo Oct 14 at 20:27 • – pppery Oct 14 at 20:33 • "there's already tons of interpreters for Text, perhaps the most famous of which is Notepad. On Unix-derived systems, the traditional interpreter is 'cat'." LOL... "Given that books and paper are fully capable of executing Text programs, they're actually probably some the first computers ever invented" OMG – Kaddath Oct 15 at 9:59 # APL (Dyalog Unicode), 104 bytes ⎕←' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~'


Try it online!

Most APL interpreters would not require the ⎕←, and would thus require only 98 bytes; a quoted string evaluates to itself. The requirement for ⎕← is an artifact of TIO.

• If the requirement for explicit inclusion of each character had not been part of the problem specification, this could have been solved with ⎕←⎕UCS 31+⍳95 when ⎕IO←1, or ⎕←⎕UCS 32+⍳95 when ⎕IO←0. This is, in fact, how I generated the character vector to use in the above solution. – Jeff Zeitlin Oct 14 at 19:22

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~  Try it online! I'm not sure If we're allowed not to open the <?php tag in the header.. If not, that's only 2 bytes more, the simpler it just to close it: # PHP, 97 bytes ?> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~


Try it online!

• The first line is probably fine. It is a full PHP program that outputs all characters. However, I would swap the space into ! " <-- like this. If you use, say, XAMPP to access a test page, it will be interpreted as HTML, which may eat up the first character. As such, I would also move the & to the very last place. And maybe do < ![...]& instead, to prevent <=> from being interpreted as an HTML tag, on a browser. On php -r, this is perfectly fine. – Ismael Miguel Oct 16 at 0:01
• Well, the output of the PHP program would be correct, how a browser interprets it is not anymore part of the program. – Petruza Oct 16 at 11:45

main=putStr[' '.."#$%&()*+,-/01234689:;<>?@ABCDEFGHIJKLMNOPQRTUVWXYZ\\^_bcdefghjkloqsvwxyz{|}~"!!75]  Try it online! # Gaia, 96 bytes  !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~"”


Try it online!

Alternately (same byte count):

“ !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~"  Try it online! # Python 2, 101 bytes print[(' !"#$%&*+-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_abcdefghijklmnopqrstuvwxyz{\|}~',)]


Try it online!

'"" !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~\  Try it online. Explanation: '" # Push the character '"' "... # Push a string with all printable ASCII characters, except for '"' # (NOTE: The \ is at the end so we won't have to escape it to \\) # (implicitly output the entire stack joined together as result)  • Where's the \? – Dominic van Essen Oct 15 at 9:47 • @DominicvanEssen Oh, thanks for noticing! Apparently it has to be escaped. Should be fixed now. – Kevin Cruijssen Oct 15 at 11:35 # ><>, 95 bytes "ra7+2*>o< !#$%&'(),-./01345689:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_bcdefghijklmnpqstuvwxyz{|}~


Try it online!

Simple ><> quine, with extra chars added.

"ra7+2*>o< !#$%&'(),-./01345689:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_bcdefghijklmnpqstuvwxyz{|}~ " Begin string mode ra7+2... Pushes string to stack " End string mode (after wrapping around) r Reverse stack a7+2* Push 34 (") to the stack >o< Repeatedly outputs until stack is empty, when it errors  # C (gcc), 111 107 bytes Thanks to Noodle9 and Nahuel Fouilleul for noticing the errors and the reductions! main(b){for(b=32;putchar(b++)<" !#$%&'*,-./014789:>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\^_degjklqsvwxyz|~"[65];);}


Try it online!

• 108 bytes – Noodle9 Oct 14 at 20:18
• @Noodle9, m, i, n are missing in the source ; however answer may be shortened because h is already in putchar and 7 in 67 also the last space char – Nahuel Fouilleul Oct 14 at 20:27
• 107 bytes – Nahuel Fouilleul Oct 14 at 20:38
• 107 bytes – Petr Fiedler Oct 14 at 21:08

# Assembly (NASM, 32-bit, Linux), 175 bytes

mov ecx,y
mov edx,z
mov ebx,1
mov eax,4
int 128
section .data
y db" !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~",34 z equ$-y


Try it online!

# C (gcc), 112110 111 bytes

Saved 2 bytes thanks to Nahuel Fouilleul!!!
Added a byte to fix a bug kindly pointed out by Neil.

f(){puts(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~");}  Try it online! Straight up print those characters, nothing fancy here. • 110 bytes – Nahuel Fouilleul Oct 14 at 20:44 • @NahuelFouilleul Ah, we can output newlines too - thanks! :-) – Noodle9 Oct 14 at 22:13 • I don't see a \ in the output... – Neil Oct 16 at 12:17 • @Neil Of course it needs escaping itself - thanks! :-) – Noodle9 Oct 16 at 12:41 # Retina 0.8.2, 96 bytes  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~


Try it online! Explanation: Simply replaces the empty input with the desired output.

0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:<=>?@[\\]^_\{|}~ \;  Try it online! The joys of auto pushing everything # 05AB1E, 96 bytes “ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~


Try it online.

Explanation:

“     # Start a dictionary string
...  # Push all printable ASCII characters, which are used as is in dictionary string
# (after which this string is output implicitly as result)


See this 05AB1E tip of mine (section How to use the dictionary?) to understand why this works.

{" !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz|~"}  Try it online! The extra byte is because the " has to be paired. The block is outputted as it was written in the source code followed by a newline. # Ruby, 99 98 bytes p"<({[CODE G0Lf_FTW!)}]>,.QmAkX/hlP5xwRc6&vZ-:?$Msq*UNb7%IKn'd|B8eYt=rg3S1yi9z\\j4a2o;@^JVp~#+uH"


Try it online!

I'd love to see a shorter Ruby version but I don't know how it could be built.

I tried to use a regex in order to save one or two characters, but there needs to be a space between p and /, and \ needs to be escaped:

p /\\# "!$%&'()*+,-.0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY[Z]^_abcdefghijklmnopqrstuvwxyz{|}~/  ## Batch, 102 bytes @echo " !#$&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~%%


Command execution in Batch is a little odd. There are four stages:

• Environment variable expansion
• Parsing a line into individual commands that are piped or chained
• Expanding for variables
• Delayed environment variable expansion (if enabled)

for variables are named with a leading %, which is a source of confusion. Fortunately in Batch scripts any use of % other than an environment variable always needs to be quoted as %%, which is then turned into a single %. (In this script I have put the quoted % at the end as it made verifying the script easier.)

To alter the way the line is parsed into commands, special characters can be quoted by preceding them with ^ or (except for " itself) by containing them in "s. (A trailing " is not necessary for the last command on a line.) The "s are not actually removed by the parser, as the arguments are passed to the application as a single string, and the application is expected to use the "s to help identify quoted arguments.

However echo doesn't bother doing any parsing, instead just printing the argument string literally. In this case I've put the " at the beginning for readability but it could go anywhere before the first special character.

• The @ at the beginning reminds me that commands are echoed by default, so why not use something like set a="!#\$&'()*+,-./0123456789:;<>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_bcdfghijklmnopqruvwxyz{|}~%% (which an @) and have it print all ASCII characters, as intended, by echoing the command before executing (note that the characters s, e, t, ␠, a, and = were removed from the tail, so it does not print any character twice… – Holger Oct 16 at 14:40
• which → without, i.e. without an @ – Holger Oct 16 at 14:46
• @Holger Better still, just use a comment? – Neil Oct 16 at 17:40
• @Holger I've changed my mind, the problem is that the echo includes the current working directory, which always includes :\> characters. So the resulting program is no longer irreducible. – Neil Oct 16 at 19:13
• Could be a long discussion, whether the prompt belong to the program output, but I see your point. – Holger Oct 17 at 7:58