8
\$\begingroup\$

Your task is to make a program which interprets the language it is run in, but also works in many languages.

Let's say you make a Brainfuck-Underload self-interpreglot, as it will be called. Run in Brainfuck, this program should be a Brainfuck interpreter; run in Underload, it should be a Underload interpreter.

Your program should work like the hypothetical given above: given a list of languages L1, L2, L3, L4... up to Ln, it should be an L1 interpreter in L1, an L2 interpreter in L2, an L3 interpreter in L3, up to being an Ln interpreter in Ln.

Your program can handle errors in any way. However, it must never output to STDERR (or closest equivalent) if the input given for interpretation has no errors.

It must output to STDOUT (or closest equivalent) and take input from STDIN (or again, closest equivalent).

You can choose any interpretation of a given language, e.g. if your polyglot works in Brainfuck, it can interpret Brainfuck with finite or unbounded tape. You must specify what interpretations you choose to use for each language.

Programs must have at least 2 characters for this challenge to prevent empty programs from competing.

Functions such as exec and eval are allowed.

Only a Turing-complete subset of a language has to be interpreted.

Different languages have to be interpreted, not different language versions.

Your score is C/(L^3), where C is code length, computed in bytes with UTF-8 encoding, and L is the amount of languages. The lowest score wins: if two winning answers have the same score the one posted earlier wins.

Have fun.

\$\endgroup\$
  • 1
    \$\begingroup\$ Are functions such as exec and eval allowed? Does the entire language spec have to be interpreted or just a turing complete subset? \$\endgroup\$ – FlipTack Dec 28 '19 at 17:27
  • \$\begingroup\$ Yes and yes. Mostly for non-esoteric languages. \$\endgroup\$ – Andrew Dec 28 '19 at 18:47
  • 4
    \$\begingroup\$ @FlipTack's second question was an "either/or" not a "yes/no"! :D \$\endgroup\$ – Shaggy Dec 28 '19 at 19:35
  • \$\begingroup\$ "In languages without any method of input (e.g. ///) programs may get input through an insertion into the source code" does this make the empty program a valid submission in some languages? codegolf.meta.stackexchange.com/a/10553/89930 \$\endgroup\$ – 79037662 Dec 29 '19 at 18:47
6
\$\begingroup\$

GolfScript/MathGolf/CJam, 2 bytes, score = 2/27 ≈ 0.074075

The most boring (yet probably the optimal) answer. (CJam's addition made the program longer by 1 byte; but this still contributes to the ending score...)

Going forward to see what is the most common character choice for an evaluation operator...

l~

TIO for MathGolf

TIO for CJam

TIO for GolfScript

What other languages have ~ as an evaluation built-in?

Not adding those languages to the polyglot. Because I'm too lazy.

Explanation (MathGolf and CJam)

l  Read an input
 ~ Evaluate the input

Explanation (GolfScript)

l  Do nothing
 ~ Evaluate the (implicit) input
\$\endgroup\$
5
\$\begingroup\$

Jelly, 05AB1E, GolfScript 8 bytes, score = \$\frac 8 {27} \approx 0.296\$

.Vq;~
ɠV

Try it online Jelly!

Try it online 05AB1E!

Try it online GolfScript!

In all cases, takes a program in the relevant language from STDIN and executes it, with any output going to STDOUT.

\$\endgroup\$
  • \$\begingroup\$ The scoring has been updated, so this is now 23/27 ~ 0.851 \$\endgroup\$ – Lyxal Dec 29 '19 at 1:43
  • \$\begingroup\$ Sorry about that. The challenge keeps changing :-/ \$\endgroup\$ – Luis Mendo Dec 29 '19 at 9:59
3
\$\begingroup\$

Keg and Python 3, 19 characters, score = \$ \frac{19}{8} \$

exec(input())
"ø¿ß"

Try it online! (Keg)

Try it online! (Python 3)

Uses the same approach as Nick first did, but with Keg instead.

I'll have to figure out how to add another language to get competitive again.

\$\endgroup\$
3
\$\begingroup\$

GolfScript/Keg, 6 bytes, score = 3/4 = 0.75

Do we have to use at least one practical language? It doesn't seem to say that in the spec.

ß.~\;

Golfscript

ß     # Odd undefined ops
 .    # Copy the input
  ~   # Evaluate it
   \; # Discard the unevaluated copy

Keg

ß     # Take input & evaluate the input
 .    # Output the result as a number
  ~   # Push a random number
   \; # Escape the ; character
\$\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.