0
\$\begingroup\$

Introduction

A polyglot is a program that is valid in multiple languages at once. An iterative quine is a program that outputs another program that outputs another program that outputs the source of the original program. Note that the number of chained programs does not have to be 3; it could be 2, 4, or 97384.

Challenge

Your task is to write a polyglot iterative quine. Each program in the program chain must be a polyglot.

  • Each of your programs must take no input.
  • As stated above, each of the programs must output the source of the next program in the chain. The last program in the chain must output the source code of the first program.

Scoring

Your score is calculated as follows:

  • For each program in the chain, take the number of languages it is valid in. Sum the results.
  • Sum the byte count of each program in the chain.
  • Divide the byte count by the number from the first program.

Rules

  • The length of the chain must be at least 2.
  • Each program in the chain must be valid in at least 2 languages.
  • The program with the lowest score wins.
  • "Different language" is defined as follows:
    • A language where the source code of the compiler or interpreter is not the same as another, and the compiler or interpreter does not run the same language as another. Some examples of different languages are: Python 2 and 3, C and C++, Java and C, and Lua and Ruby. However, by this definition, using tcc instead of gcc does not count as a different language, because tcc runs the same language as gcc: C.
  • Programs are allowed to throw errors, but only after they print out the output of the program. For example, print(1/0);print(<quine stuff>) in Python 3 would be invalid, but print(<quine stuff);print(1/0) would be.
\$\endgroup\$
12
  • \$\begingroup\$ In order for this sort of challenge to work it is going to need to be clear what counts as different languages. Otherwise we get a lot of questions as to whether all versios of python are the same language, whether using different C compilers counts as using different language etc. Related reading \$\endgroup\$ – Wheat Wizard Dec 11 '19 at 21:12
  • \$\begingroup\$ @WheatWizard - ok, I will fix that \$\endgroup\$ – sugarfi Dec 11 '19 at 21:19
  • 1
    \$\begingroup\$ @Dracos18s Those aren't polyglots \$\endgroup\$ – Jo King Dec 11 '19 at 22:25
  • 3
    \$\begingroup\$ What do you mean by "number of languages it is valid in"? Number of languages where that source code can be run without errors? Or without syntax errors? Is print(1/0) considered valid in Python 3, for example? \$\endgroup\$ – 79037662 Dec 11 '19 at 23:58
  • 1
    \$\begingroup\$ If I prefix my code with a comment character (e.g. #, does my score suddenly decrease because it can be run in hundreds of different languages with erroring? On the other hand, my ><> program works perfectly fine but terminates in an error (which is also fine by community standards). Perhaps you should just say the program has to output the next program in the sequence for each language and leave it at that? \$\endgroup\$ – Jo King Dec 12 '19 at 7:37
2
\$\begingroup\$

Wumpus, ><>, Befunge-98, \$\frac{57+57}{3+3}=19\$

"]<0~[#34ooo!O;#53&o@,k*4e-1#'$ #o#!-1'#'+3*a9*c5+*68%2++

Try it in Wumpus! Try it in ><>! Try it in Befunge-98!

A modified version of a previous polyglot of mine that makes it iterative by flipping the first 0 to a 1 and back again.

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