44
\$\begingroup\$

Background

As most PPCG regulars will know, a is a program which outputs its own source code when run; and the Levenshtein distance between two strings is the minimum number of insertions, deletions, and edits needed to change one string into the other. In this challenge, we're combining the two concepts into a "levenquine": a program that outputs its own source code, but with one instance of one character inserted, deleted, or replaced with a different character. (In other words, the Levenshtein distance between the program and its output is 1.)

The task

Write a levenquine such that its output is a levenquine, the output of that program is also a levenquine, and so on. Additionally, at some point, the sequence of repeatedly running the program, running its output, running its output's output, etc. must eventually come back to the original program.

There's one additional restriction that makes things much harder: there must be two distinct programs somewhere within this cycle which have no characters in common (in other words, there's no character that exists within one program and also exists within the other program). Your program is therefore going to have to gradually transform itself into a different character set, and back again.

If you're using a programming language which has unavoidable boilerplate that's required in any program that produces output (e.g. it only has one way to write a print statement and no other useful forms of output), you may treat that boilerplate as nonexistent for the purpose of determining which characters two programs have in common. You must, however, still count that boilerplate for the purpose of determining the Levenquine property of the code.

Clarifications

  • Each of the "programs" in the cycle can be either a full program or a function. They don't all have to be the same, e.g. some could be full programs and some could be functions.
  • Not all the programs in the cycle need to use the same form of output. For example, some could output via standard output, and some could output via standard error.
  • Your programs will be run with no input (or in languages which require input to do anything at all, the simplest possible input).
  • Proper quine rules apply; although a Levenquine is not a true quine, you may not do anything that would be illegal when writing a proper quine. In particular, the null program is never valid output from a proper Levenquine (and thus cannot be part of your cycle).
  • The Levenquine restriction is measured in terms of characters, rather than bytes (e.g. ê is one character even when the source is encoded in UTF-8). The no-characters-in-common restriction is also measured in terms of characters. The victory condition, however, counts in bytes.

Victory condition

Please submit at least the following three programs from the cycle: the shortest program (measured in bytes); and two programs from the cycle that have no characters in common. It's possible that two of these are the same, and it's also possible that all three are distinct. The score is based on the length in bytes of the shortest program, with shorter being better, thus making this a kind of competition.

\$\endgroup\$
  • \$\begingroup\$ For people who can see deleted posts: the Sandbox post was here. \$\endgroup\$ – user62131 Apr 11 '17 at 21:45
  • \$\begingroup\$ I think it'd also be good for answers to include the length of the cycle. \$\endgroup\$ – mbomb007 Apr 11 '17 at 21:54
  • \$\begingroup\$ What if, say, the language has several functions for performing output, but they all pairwise share characters? \$\endgroup\$ – Ørjan Johansen Apr 11 '17 at 23:45
  • 2
    \$\begingroup\$ @ØrjanJohansen: I guess I wouldn't be too opposed to just picking one of them and sticking with it in that case. However, it's arguably noncompeting; I wanted the rule to be objective, because otherwise people have a tendency to try to poke loopholes in it, and if you try to make the rule too complex there tend to be arguments over what it means. \$\endgroup\$ – user62131 Apr 12 '17 at 1:00
  • \$\begingroup\$ Can it be a levenquine bit-wise? As in the distance from the original source code is 1 byte off? \$\endgroup\$ – Magic Octopus Urn Oct 31 '17 at 20:28
31
\$\begingroup\$

Gol><>, 252 167 bytes

1>'r&ff9++r}}r&f*bc++1z.r}r6=z?Hzznr6rHr}r:ee+6+=z9*5c*+1z . }&z+5c*&H}rebe*b+ke++rHS6PWSb`S6P$$1W5/11b6W6EE/W6EE`S6P$$W61`S6P5W6$5_61P1WW_b_

Try it online!

And the mutually distinct (Verification) program:

0<CŽB‚‚UGGŽ™™ŽB‚F~GGM–JŽ™ŽRY–[d––ŠŽRŽdŽ™ŽVGRGY–UFQFGM–<J<™B–GQFBd™Ž~F~G‡GGŽd;oRl-7-7so~|;oRl@@-Ms7QKMM3-3-3~R-4sRaaK-3sRaa|;oRl@@sR43M|;oRlQ-sR43@Q{RMlMss3{~{"

Try it online!

This is mostly inspired by my answer to the Mutually Exclusive Quines challenge, with kudos also going to Bubbler's Gol><> answer.

Here is a verification program you can run. Unfortunately, it times out, but you can watch how one section of code builds the other section and then you can copy the last version printed and paste it into the input to continue. Eventually, you'll reach the first program you put in.

Explanation

Both sections of code are composed of two sections, the actual executing part and the data containing the other section of code. They both function practically identically:

They depend on a flag (the first character of the code, either 1 or 0). If the flag is set, they will start building the other section of code by taking the 252th character down, adding/subtracting 28 from it and appending it to the code.

For example, here are the first two iterations of the code after the first program above:

1>'r&ff9++r}}r&f*bc++1z.r}r6=z?Hzznr6rHr}r:ee+6+=z9*5c*+1z . }&z+5c*&H}rebe*b+ke++rHS6PWSb`S6P$$1W5/11b6W6EE/W6EE`S6P$$W61`S6P5W6$5_61P1WW_b_C

1>'r&ff9++r}}r&f*bc++1z.r}r6=z?Hzznr6rHr}r:ee+6+=z9*5c*+1z . }&z+5c*&H}rebe*b+ke++rHS6PWSb`S6P$$1W5/11b6W6EE/W6EE`S6P$$W61`S6P5W6$5_61P1WW_b_CŽ

Eventually when it reaches the end of the current section, it flips the second character of the code (< to > and back again) to point to the other section.

Here are both sections together, about to switch from executing the first section to executing the second.

1>'r&ff9++r}}r&f*bc++1z.r}r6=z?Hzznr6rHr}r:ee+6+=z9*5c*+1z . }&z+5c*&H}rebe*b+ke++rHS6PWSb`S6P$$1W5/11b6W6EE/W6EE`S6P$$W61`S6P5W6$5_61P1WW_b_CŽB‚‚UGGŽ™™ŽB‚F~GGM–JŽ™ŽRY–[d––ŠŽRŽdŽ™ŽVGRGY–UFQFGM–<J<™B–GQFBd™Ž~F~G‡GGŽd;oRl-7-7so~|;oRl@@-Ms7QKMM3-3-3~R-4sRaaK-3sRaa|;oRl@@sR43M|;oRlQ-sR43@Q{RMlMss3{~{"

Try it online!

The flags are the opposite for each section, so the newly executing section will start deleting the other section of code until it reaches its own code. At this point, it flips the flag and the cycle repeats again.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy