12
\$\begingroup\$

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

\$\endgroup\$
  • 2
    \$\begingroup\$ So does this mean that if e.g. the program contains any repeated characters it is automatically disqualified? That's rough. \$\endgroup\$ – breadbox Sep 19 '13 at 5:45
  • 5
    \$\begingroup\$ Related: codegolf.stackexchange.com/questions/12368/… \$\endgroup\$ – John Dvorak Sep 19 '13 at 6:01
  • 1
    \$\begingroup\$ You might also want to rule on whether the old echo $0 is disqualified. \$\endgroup\$ – Peter Taylor Sep 19 '13 at 7:37
  • 3
    \$\begingroup\$ 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? \$\endgroup\$ – primo Sep 19 '13 at 8:00
  • 1
    \$\begingroup\$ @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) \$\endgroup\$ – John Dvorak Sep 19 '13 at 8:03
12
\$\begingroup\$

GolfScript, 14 characters

{`),32>46-^}.~

Output:

 !"#$%&'(*+/015789:;<=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]_abcdefghijklmnopqrstuvwxyz|
\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Frank Schmitt Sep 20 '13 at 13:06
  • \$\begingroup\$ Sorry, my mistake. In the title it reads "program+output", whereas later in the question it reads concatenated program+output. \$\endgroup\$ – Frank Schmitt Sep 20 '13 at 13:24
  • \$\begingroup\$ ), - wow. I love that. \$\endgroup\$ – John Dvorak Sep 20 '13 at 14:24
  • 1
    \$\begingroup\$ @JanDvorak codegolf.SE: the only place where people get excited about a close-paren and a comma. :P \$\endgroup\$ – Doorknob Sep 23 '13 at 12:22
  • \$\begingroup\$ @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. \$\endgroup\$ – John Dvorak Sep 23 '13 at 12:34
6
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ Let's see if I can print a bigger number :-) \$\endgroup\$ – John Dvorak Sep 19 '13 at 8:28
  • \$\begingroup\$ uh... can you translate the second line for me? \$\endgroup\$ – John Dvorak Sep 19 '13 at 9:09
  • 1
    \$\begingroup\$ @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`. \$\endgroup\$ – Dan Sep 20 '13 at 14:39
6
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Ah, sure, barewords. How could I have forgot? \$\endgroup\$ – John Dvorak Sep 20 '13 at 14:25
3
\$\begingroup\$

Ruby, 91 chars

%{ !"#$&\',-/450:<=>ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcefghijklmnqvwxyz|~};puts(?@‌​.ord*98+1)

Outputs 6273.

%{...} trick stolen from Jan Dvorak

\$\endgroup\$
  • \$\begingroup\$ Without comments. As clearly stated. \$\endgroup\$ – Johannes Kuhn Sep 20 '13 at 18:59
  • \$\begingroup\$ @JohannesKuhn Ah, didn't notice that. edited. \$\endgroup\$ – Doorknob Sep 20 '13 at 20:41
  • \$\begingroup\$ %{ !"#$&\',-/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. \$\endgroup\$ – r.e.s. Sep 23 '13 at 3:27
  • \$\begingroup\$ @r.e.s. Yep, it's hard to manage all these letters :P \$\endgroup\$ – Doorknob Sep 23 '13 at 11:51
  • \$\begingroup\$ Now \ is included three times. \$\endgroup\$ – Howard Sep 23 '13 at 11:53
3
\$\begingroup\$

Perl, 61 characters

print$:x8^CJIBQTOWAEULHVGFNMKRPZY,q<#"/;*g~?|={.>&+u15m97ws26

Output:

c@db[yo]le_ah\jfD`kX}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).

\$\endgroup\$
  • 1
    \$\begingroup\$ I find your program length is 61 characters. \$\endgroup\$ – r.e.s. Sep 22 '13 at 23:36
  • \$\begingroup\$ Thanks. My text editor reported 62 characters because of the EOF. \$\endgroup\$ – Grimy Oct 14 '13 at 16:36
1
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

Tcl 96, edit distance 12

if 0    {!"#$%&'()*+,-./123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdeghjklmnopqrstuvwxyz|~}
\$\endgroup\$
  • \$\begingroup\$ One of the spaces should be a tab, I'm afraid \$\endgroup\$ – John Dvorak Sep 19 '13 at 9:04
  • \$\begingroup\$ is a tab or space printable? \$\endgroup\$ – Johannes Kuhn Sep 19 '13 at 9:05
  • \$\begingroup\$ tab is unprintable (ASCII 9), but space is printable (ASCII 32). \$\endgroup\$ – John Dvorak Sep 19 '13 at 9:06
  • 1
    \$\begingroup\$ [Just saw that the OP only clarified this after you answered :)] \$\endgroup\$ – flornquake Sep 19 '13 at 14:19
  • 1
    \$\begingroup\$ 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.) \$\endgroup\$ – r.e.s. Sep 23 '13 at 3:14

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.