6
\$\begingroup\$

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)
\$\endgroup\$
11
  • 1
    \$\begingroup\$ 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"? \$\endgroup\$
    – xnor
    Oct 14 '20 at 19:42
  • 25
    \$\begingroup\$ 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. \$\endgroup\$
    – Shaggy
    Oct 14 '20 at 20:20
  • 2
    \$\begingroup\$ 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... \$\endgroup\$ Oct 15 '20 at 9:40
  • 1
    \$\begingroup\$ I've been struggling (unsuccessfully so far) in R to get a 95-byte solution. It only costs 17 bytes (intToUtf8(32:140)) to output all the required characters, leaving 78 bytes free to fill-in the missing characters in the code & make it irreducible. Unfortunately, the intToUtf8 function name annoyingly includes the letter t twice, which spoils everything (not to mention that R programs tend to use a lot of parentheses...), but I still feel that there might be a way, somehow... \$\endgroup\$ Oct 15 '20 at 9:43
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ Oct 15 '20 at 11:39

22 Answers 22

11
\$\begingroup\$

Husk, 95 95 bytes

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

mcW=2`R\.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=2`R\.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.
\$\endgroup\$
3
  • \$\begingroup\$ So... how is this not irreducible modulo deletion of the `\`? \$\endgroup\$
    – Neil
    Oct 16 '20 at 12:15
  • \$\begingroup\$ @Neil - Shit! You're right! ...will try to think of a solution! \$\endgroup\$ Oct 16 '20 at 12:51
  • \$\begingroup\$ @Neil - Fixed now, I think. Thank goodness. I wasn't sure it would work at all... Please don't find any more bugs! \$\endgroup\$ Oct 16 '20 at 13:30
9
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Lovely. It's nice to see some actual programming to achieve 95 bytes. Well done. \$\endgroup\$ Oct 15 '20 at 14:50
8
\$\begingroup\$

Python 3, 105 bytes

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

;)

Try it online!

\$\endgroup\$
4
  • \$\begingroup\$ This could be improved by removing some characters already used by print('') (ex. (, ), ', p, r, i, n, t \$\endgroup\$
    – Nosrep
    Oct 15 '20 at 16:14
  • 1
    \$\begingroup\$ @Nosrep It still would need to output those characters, so you can't just remove them from the string. \$\endgroup\$
    – Xcali
    Oct 15 '20 at 18:29
  • 1
    \$\begingroup\$ @Nosrep: You still have to somehow output them, though, don't you? \$\endgroup\$ Oct 15 '20 at 19:22
  • \$\begingroup\$ Ah, misread the question, sorry. \$\endgroup\$
    – Nosrep
    Oct 16 '20 at 0:09
8
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ Yes. That's why I indicated 'likely polyglot'... \$\endgroup\$ Oct 14 '20 at 19:31
6
\$\begingroup\$

Text, 95 bytes

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

Text programs always print their contents.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ "almost all ASCII files, including readmes, and interpreted programming language source code files, are actually written in Text. " LOL \$\endgroup\$
    – pxeger
    Oct 14 '20 at 20:03
  • 3
    \$\begingroup\$ Also polyglot in Charcoal: Try it online! \$\endgroup\$
    – Neil
    Oct 14 '20 at 20:05
  • 7
    \$\begingroup\$ This doesn't seem to qualify as a programming language according to our standards \$\endgroup\$
    – Luis Mendo
    Oct 14 '20 at 20:27
  • 8
    \$\begingroup\$ @LuisMendo Answers are not required to be in a programming language \$\endgroup\$ Oct 14 '20 at 20:33
  • 4
    \$\begingroup\$ "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 \$\endgroup\$
    – Kaddath
    Oct 15 '20 at 9:59
4
\$\begingroup\$

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.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ Oct 14 '20 at 19:22
4
\$\begingroup\$

PHP, 95 bytes

 !"#$%&'()*+,-./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!

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$ Oct 16 '20 at 0:01
  • \$\begingroup\$ Well, the output of the PHP program would be correct, how a browser interprets it is not anymore part of the program. \$\endgroup\$
    – Petruza
    Oct 16 '20 at 11:45
4
\$\begingroup\$

Haskell, 101 bytes

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

Try it online!

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

Gaia, 96 bytes

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

Try it online!

Alternately (same byte count):

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

Try it online!

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

Python 2, 101 bytes

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

Try it online!

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

MathGolf, 99 97 bytes

'"" !#$%&'()*+,-./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)
\$\endgroup\$
2
  • \$\begingroup\$ Where's the \? \$\endgroup\$ Oct 15 '20 at 9:47
  • \$\begingroup\$ @DominicvanEssen Oh, thanks for noticing! Apparently it has to be escaped. Should be fixed now. \$\endgroup\$ Oct 15 '20 at 11:35
3
\$\begingroup\$

><>, 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
\$\endgroup\$
2
\$\begingroup\$

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!

\$\endgroup\$
4
  • \$\begingroup\$ 108 bytes \$\endgroup\$
    – Noodle9
    Oct 14 '20 at 20:18
  • \$\begingroup\$ @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 \$\endgroup\$ Oct 14 '20 at 20:27
  • \$\begingroup\$ 107 bytes \$\endgroup\$ Oct 14 '20 at 20:38
  • \$\begingroup\$ 107 bytes \$\endgroup\$ Oct 14 '20 at 21:08
2
\$\begingroup\$

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!

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

Ruby, 99 98 bytes

p"<({[CODE G0Lf_FTW!)}]>,.QmAkX/hlP5xwRc6&vZ-:?$Msq*UNb7%IKn'd|B8eYt=rg3S1yi9`z\\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{|}~/
\$\endgroup\$
2
\$\begingroup\$

C (gcc), 112 110 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.

\$\endgroup\$
4
  • \$\begingroup\$ 110 bytes \$\endgroup\$ Oct 14 '20 at 20:44
  • \$\begingroup\$ @NahuelFouilleul Ah, we can output newlines too - thanks! :-) \$\endgroup\$
    – Noodle9
    Oct 14 '20 at 22:13
  • \$\begingroup\$ I don't see a `\` in the output... \$\endgroup\$
    – Neil
    Oct 16 '20 at 12:17
  • \$\begingroup\$ @Neil Of course it needs escaping itself - thanks! :-) \$\endgroup\$
    – Noodle9
    Oct 16 '20 at 12:41
1
\$\begingroup\$

Retina 0.8.2, 96 bytes


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

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

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

Keg, 101 bytes

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

Try it online!

The joys of auto pushing everything

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

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.

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

GolfScript, 96 bytes

{" !#$%&'()*+,-./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.

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

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.

\$\endgroup\$
5
  • \$\begingroup\$ 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… \$\endgroup\$
    – Holger
    Oct 16 '20 at 14:40
  • \$\begingroup\$ which → without, i.e. without an @ \$\endgroup\$
    – Holger
    Oct 16 '20 at 14:46
  • \$\begingroup\$ @Holger Better still, just use a comment? \$\endgroup\$
    – Neil
    Oct 16 '20 at 17:40
  • \$\begingroup\$ @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. \$\endgroup\$
    – Neil
    Oct 16 '20 at 19:13
  • \$\begingroup\$ Could be a long discussion, whether the prompt belong to the program output, but I see your point. \$\endgroup\$
    – Holger
    Oct 17 '20 at 7:58
1
\$\begingroup\$

Unified HQ9+ and possibly some other dialects, 95 bytes

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

Q prints the source code, h halts the program to prevent unnecessary output, and the rest are NOPS, but necessary to print everything.

No TIO.

\$\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.