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)
(many lines omitted)


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

  • 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\$ Commented Oct 10, 2020 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\$ Commented Oct 10, 2020 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
    Commented Oct 11, 2020 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\$ Commented Oct 11, 2020 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
    Commented Oct 11, 2020 at 0:23

2 Answers 2


Ruby, 92 91 86 bytes

Saved 5 bytes thanks to a comment by @Sisyphus on another answer.

eval s="a=*?\0..?\x7f;90.times{|i|puts a.product(*[a]*i).map(&:join)-['eval s=%p'%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="                               # evaluate s, a 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=%p'%s]                     # not equal to the full program
  • \$\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
    Commented Oct 11, 2020 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
    Commented Oct 12, 2020 at 0:35
  • 2
    \$\begingroup\$ Not at all, I just wanted to know if it was what you intended. \$\endgroup\$
    – Purple P
    Commented Oct 12, 2020 at 0:39

Perl 5, 119, 110, 108 bytes

-9 bytes hardcoding code length thanks to @Dingus.


Try it online!

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.