In this challenge, you'll create some programs which behave similarly to genes. When you run one, it will return one of its two "alleles" (a half of its source code), and concatenating any two alleles from your programs will result in a new, functioning program (which returns its own alleles).
As an example, say you write two programs, \$A\$ and \$B\$. These in turn each consist of two "alleles", \$A_0A_1\$ and \$B_0B_1\$. Running \$A\$ would return either \$A_0\$ or \$A_1\$ randomly, and \$B\$ would return \$B_0\$ or \$B_1\$.
Combining any two of these alleles should form a program \$C\$. For example, \$A_0B_0\$, when run, should return one of \$A_0\$ or \$B_0\$, similarly to its parents. If \$C\$ was instead \$A_1B_0\$, it'd return one of those two alleles instead.
One possibility if you had multiple generations, starting with three programs, could look like this:
Rules
You must write at least two genetic quines, with each initial one having two unique alleles (the total number of unique alleles should be twice the number of initial programs). All permutations of alleles must form a functioning genetic quine.
A genetic quine takes no input when run, and returns the source code of one of its two alleles, randomly. It consists only of the code in its two alleles, concatenated. For example, if print(xyz)
and if 1
were two alleles, print(xyz)if 1
and if 1print(xyz)
should both work.
Note that standard quine rules must be followed, so the genetic quines should not read their own source code, and alleles should be non-empty.
The random choice must have a uniform probability of choosing either quine, and the quines must follow standard rules (so non-empty). You may not use the current time (directly) or some undefined behavior for randomness; a properly seeded PRNG or source of randomness should be used.
Scoring
Your score (lowest score per language wins) will be the average byte count of all of your alleles, plus an amount determined by \$\frac{b}{2^{n-1}}\$ (making your total score \$b+\frac{b}{2^{n-1}}\$), where \$b\$ is your average byte count and \$n\$ is the number of genetic quines you wrote. This means that writing two initial programs with four alleles would give you a "bonus" (more like a penalty) of \$\frac{1}{2}\$, three would give you \$\frac{1}{4}\$, four would be \$\frac{1}{8}\$, and so on. This is a penalty, not a multiplier: your score will never be lower than your average byte count.