# Shortest program whose concatenated program+output is a permutation of the 95 printable ASCII characters

Write a program that's as short as possible (as measured by byte-count), takes no input, contains no comments, and outputs a character string/sequence, such that concatenated program+output is exactly 95 characters long and contains every printable ASCII character exactly once, i.e. program+output is a permutation of the 95 characters with ASCII codes 32-126:

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~  In the event of a tie, the winner is the entry whose (95-character) concatenated program+output is closest to the above string, as measured by the Levenshtein edit-distance (i.e. the number of single-character deletions, insertions, or substitutions required to put it into ASCII order). • So does this mean that if e.g. the program contains any repeated characters it is automatically disqualified? That's rough. Sep 19 '13 at 5:45 • Sep 19 '13 at 6:01 • You might also want to rule on whether the old echo$0 is disqualified. Sep 19 '13 at 7:37
• Are characters outside of the printable ascii character range (and possibly duplicates thereof) allowed? Or must the program+output contain every printable character exactly once, and nothing more? Sep 19 '13 at 8:00
• @primo I assume they are allowed. I think it's time to write a "shift-and-eval" solution that uses duplicates (though string literals are going to be hard to get) Sep 19 '13 at 8:03

### GolfScript, 14 characters

{),32>46-^}.~

 !"#$%&'(*+/015789:;<=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]_abcdefghijklmnopqrstuvwxyz|  • The challenge (at least as far as I understand it) was to write a program whose program and output is a permutation of the 95 printable ASCII chars, not to write the shortest possible program that outputs the 95 printable ASCII chars. Sep 20 '13 at 13:06 • Sorry, my mistake. In the title it reads "program+output", whereas later in the question it reads concatenated program+output. Sep 20 '13 at 13:24 • ), - wow. I love that. Sep 20 '13 at 14:24 • @JanDvorak codegolf.SE: the only place where people get excited about a close-paren and a comma. :P – Doorknob Sep 23 '13 at 12:22 • @Doorknob in golfscript it means "right uncons (rparen) and make an array of that size (comma)". In effect you're left with a string shortened by one character (the right curly) and an array ending just below that character's ASCII position (at |). Trim the unprintable chars, the period and xor (symmetric set difference here) with the source code (subtraction is taken) sans said right curly, and you're done. And yeah, string xor array is string. Sep 23 '13 at 12:34 ## Perl, 89 characters This is the best I've been able to do so far: q< !"#%&'()+/8:?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\^_abcdefghjklmosuvwxz|>; print~-$=.73*2,y[]{}


For those not conversant in Perl minutae, the two arguments to the print statement could be rendered as ~(-($=)) . (73 * 2) and tr///. The program outputs 6 characters: 591460  Unfortunately every single iteration construct that I can think of in Perl (for, while, until, map, grep) shares at least one character with print. If newlines were allowed to appear in the output, then I could use Perl 5.010 to eke out an 87-character solution: q{ !"#%&'*,-./0:;>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^bcdfgjkmnoprtuvxz|~}while($_+=say)<9

• Let's see if I can print a bigger number :-) Sep 19 '13 at 8:28
• uh... can you translate the second line for me? Sep 19 '13 at 9:09
• @JanDvorak $= is the number of horizontal lines in the current output device. By default 60. ~-$= is the bitwise inversion of the two's complement negative of 60, which happens to be 59. 73*2 is 146. . and , do what you would expect of them. y[]{} is another way to say tr///, which is the transliterate operator. It takes $_ and does nothing, because you didn't give it any characters to replace. It returns the number of characters replaced, which is 0. So we have ~-$= . 73*2 , y[]{} = 59 . 146 , 0 = '591460.
– Dan
Sep 20 '13 at 14:39

## PHP 67 bytes

<?=U4eB1gkFdA6J9snZD2IE8y5PhwQV^xHGmqYMfNjKpbR3vcLalCWi0_TtrOSXouz;


Output:

-|"/@>& *+}:[!],'~(){.\7#%$ It seems like there should be a 65 byte solution, outputting 30 chars instead of only 28, but I couldn't get it to line up. The 6 unused characters OSXouz have been tacked onto one of the string literals instead. Edit: Upon further reflection, it is not possible to generate more than 28 characters in this manner. UPPER ^ lower will always result in a character between 32 and 63, so all 10 digits are required for @[\]_{|}~. Four of the remaining 22 are used in the script itself, leaving only 18 which can be obtained with letters alone. The tiebreaker could be improved significantly, though. • Ah, sure, barewords. How could I have forgot? Sep 20 '13 at 14:25 ## Ruby, 91 chars %{ !"#$&\',-/450:<=>ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcefghijklmnqvwxyz|~};puts(?@‌​.ord*98+1)


Outputs 6273.

%{...} trick stolen from Jan Dvorak

• Without comments. As clearly stated. Sep 20 '13 at 18:59
• @JohannesKuhn Ah, didn't notice that. edited.
– Doorknob
Sep 20 '13 at 20:41
• %{ !"#$&\',-/450:<=>ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcefghijklmnqvwxyz|~};puts(?@.ord*98+1) is what I think you want (for 91 characters) with the semicolon moved over to be used as a printable separator (instead of a newline), and with the letters of 'ord' removed from inside the curly brackets. Sep 23 '13 at 3:27 • @r.e.s. Yep, it's hard to manage all these letters :P – Doorknob Sep 23 '13 at 11:51 • Now \ is included three times. Sep 23 '13 at 11:53 # Perl, 61 characters print$:x8^CJIBQTOWAEULHVGFNMKRPZY,q<#"/;*g~?|={.>&+u15m97ws26


Output:

c@db[yo]le_ah\jfDkX}zS-! %)('v304


$: defaults to " \n-". x8 repeats it eight times; the 24-character result is then bitwise-xored with a 23-character barestring (the last - is left as-is). Second part is a 12-character q-string bitwise-and a 10-character barestring (the last 2 characters are discarded). • I find your program length is 61 characters. Sep 22 '13 at 23:36 • Thanks. My text editor reported 62 characters because of the EOF. Oct 14 '13 at 16:36 # Ruby, 95 characters, 6 edits %{ !"#$&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz|~}


Yep. That's it. Just a free-floating string literal that is never printed. Ruby supports string literals (borrowed from Perl, I think) in the percent-type-delimiter form - the delimiter is any non-alphanumeric character, and if the opening delimiter is an opening bracket (any of [({<), the closing delimiter is the corresponding closing bracket (nested brackets are allowed).

I realise this is more of a baseline submission, but unless someone manages to actually print something or unless there's a language with a two-char freeform string literal with a different opening and closing delimiter, this is the best there is.

### Tcl 96, edit distance 12

if 0    {!"#$%&'()*+,-./123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdeghjklmnopqrstuvwxyz|~}  • One of the spaces should be a tab, I'm afraid Sep 19 '13 at 9:04 • is a tab or space printable? Sep 19 '13 at 9:05 • tab is unprintable (ASCII 9), but space is printable (ASCII 32). Sep 19 '13 at 9:06 • [Just saw that the OP only clarified this after you answered :)] Sep 19 '13 at 14:19 • join {!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghklmpqrstuvwxyz|~}` seems to work using 95 characters? (Thank you for your entry. Sorry about the chameleon -- unfortunately I edited in haste, and should have done things differently.) Sep 23 '13 at 3:14