Write a program that will output another distinct program, and so on, while using as few distinct characters (and as few bytes) as possible.

For example, program 1 should output program 2, and when program 2 is executed, it should output program 3. This can be nested as deeply as needed, but must be at least 3 distinct programs deep.


  • Your program can take no input.

  • When the program is executed, the output should be the source of another, different program. This includes the STDERR stream. This can continue as many times as needed, but must occur at least three times.

  • The output source code may be in a separate language.


$ <program-1>

$ <program-2>

$ <program-3>


Each answer is scored by the following formula:

(length_in_bytes * number_of_distinct_characters) / number_of_distinct_programs 

For example, if your answer was 10 bytes long, contained 5 distinct characters, and output 3 distinct programs, your score would be:

(10 * 5) / 3

or 16.66.

Lowest score wins.

Note: This challenge was inspired by the comments on this StackOverflow question.


closed as too broad by jimmy23013, Mego, Stewie Griffin, Addison Crump, TanMath Jan 14 '16 at 8:36

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ I suggest you add "lowest score wins" and remove anything above the TL;DR as per this meta answer \$\endgroup\$ – agtoever Jan 14 '16 at 8:09
  • 5
    \$\begingroup\$ I'm voting to close as too broad because there is no criteria on what the programs should do, other than spitting out other programs. It would be trivial to create an infinite sequence of programs in stack-based languages with implicit output like Seriously. \$\endgroup\$ – Mego Jan 14 '16 at 8:10
  • \$\begingroup\$ What's the score if you create infinite programs? 0? \$\endgroup\$ – agtoever Jan 14 '16 at 8:11
  • \$\begingroup\$ For example: Q;+ will result in an infinite sequence of Seriously programs, each containing the previous program repeated twice. Score: 3*3/infinity \$\endgroup\$ – Mego Jan 14 '16 at 8:15

Vitsy, 8 bytes, 8 distinct character, ∞ programs (score 0)

This is a simple proof in another stack-based language of Mego's comment.

' rd3*Z   Standard quine formula
 D     1  Increase the number of ones every output (output 1 will have 11,
          2: 111, 3: 1111, etc.)

Perl 5 - 34 bytes, 19 distinct characters, 10000000 programs (score 0.0000646)

$p="print q{$p}"for 1..1e7;print$p

The score can be lowered arbitrarily by increasing the constant 1e7, at the expense of taking longer and producing larger programs.


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