9
\$\begingroup\$

Write a program which will eventually, given enough time, print all possible permutations of ASCII characters (both printable and non-printable) less than or equal to its length, except itself. The text of the program must not appear anywhere in its output.

For example, if your program is abc, then part of your output could look like:

(many lines omitted)
ab0
ab1
ab2
...
abb
abd
(many lines omitted)

or

...[some character other than a]bcabacba5804g715^^*#0...

If your language requires characters that are not printable ASCII (e.g. Jelly or APL), print all combinations of characters in its code page.

The strings need not be separate from each other; a single character can be counted as part of multiple strings. You could try to create a superpermutation, which would be at least \$95! + 94! + 93! + 95 − 3 = 1.04 × 10^{148}\$ characters long.

Standard quine rules apply (no reading the program's source code) but this is also code golf.

\$\endgroup\$
  • 2
    \$\begingroup\$ While the overall task is clear, I think you're lacking in complete specification in a number of places (for example, do standard quine rules apply, or is this a code golf challenge etc.). As such, I've voted to close as "Needs details or clarity". However, please edit in more details, such as the questions I've brought up, anything else someone asks or my questions (below), and I'll consider reverting my vote. My questions are: \$\endgroup\$ – caird coinheringaahing Oct 10 '20 at 23:58
  • 3
    \$\begingroup\$ Languages that use custom code pages have to output the entire code page, but those that use Unicode only have to output printable ASCII. This seems unfair? " You may print either all strings with length less than or equal to your program, or all strings regardless of length" This seems like a very easy to exploit issue. I could submit a 1 byte program which outputs all characters but itself, it that valid? If so, that seems open to abuse. \$\endgroup\$ – caird coinheringaahing Oct 10 '20 at 23:58
  • \$\begingroup\$ @cairdcoinheringaahing I would say quine rules apply (no reading the program's source code) but also you should try to make the code as short as possible. I couldn't think of any better solution for languages that use extended characters. Can you? I don't have a problem with a 1 byte program outputting all characters but itself. \$\endgroup\$ – Purple P Oct 11 '20 at 0:14
  • \$\begingroup\$ I'd say, for the sake of fairness, that if a language such as Jelly has to output all combinations from its character page, a language that uses Unicode encoding should have to output all combinations of bytes from NUL to DEL (i.e. printable and non-printable characters) \$\endgroup\$ – caird coinheringaahing Oct 11 '20 at 0:16
  • \$\begingroup\$ I suggest you add this to the post: For example, if your program is `abc`, then your program must print every permutation of ascii characters **except** `abc` \$\endgroup\$ – Lyxal Oct 11 '20 at 0:23
2
\$\begingroup\$

Ruby, 92 91 bytes

eval$s=%q(a=*?\0..?\x7f;90.times{|i|puts a.product(*[a]*i).map(&:join)-["eval$s=%q(#$s)"]})

Try it online!

Forms arrays containing all permutations of ASCII characters (codepoints 00 to 127) of length 1 to 91, then subtracts from each the string eval$s=%q(#$s), which is equivalent to the full program (because of the interpolated string $s).

eval$s=%q(                             # evaluate $s, a (global) double-quoted string that contains most of the program
  a=*?\0..?\x7f;                       # create array of ASCII characters 00 to 127
  90.times{|i|                         # for permutations of length i = 1 to 91:
    puts a.product(*[a]*i).map(&:join) #   print all strings of length i...
    -["eval$s=%q(#$s)"]                #   not equal to the full program
  }
)
\$\endgroup\$
  • \$\begingroup\$ I ran this program in irb. After printing all the 3-character combinations, it printed all single characters, then stopped printing and consumed all my system's memory. \$\endgroup\$ – Purple P Oct 11 '20 at 23:43
  • \$\begingroup\$ @PurpleP That's expected behaviour - the code is attempting to create very large arrays of strings. Or are you saying that unlimited time is acceptable but not unlimited memory? \$\endgroup\$ – Dingus Oct 12 '20 at 0:35
  • 1
    \$\begingroup\$ Not at all, I just wanted to know if it was what you intended. \$\endgroup\$ – Purple P Oct 12 '20 at 0:39
1
\$\begingroup\$

Perl 5, 119, 110, 108 bytes

-9 bytes hardcoding code length thanks to @Dingus.

$C=q(while(y///c<109){s/^\xff*(.?)/"\0"x$-[1].chr(''ne$1?1+ord$1:0)/es;"\$C=q($C);eval\$C"ne$_&&say});eval$C

Try it online!

or to check the case when output is just before the source

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