30 languages, 248 bytes, 248/30^3 = 0.009185
#|#?15g,@ kkmNmSaIeoe99+{\#/-;n@0ea
#[9!@>.>.eeaww#-1@*"12" L
#{
###
#`{
25
print(4^2 +7)/2
"""
Jo is here.
$'main'MoO OOM
7
>Jo, 30
>X Jo
f::=~27
::=]##}#(prin 29)
print (7/6*24)###;alert 2#-[>+<-----]>-.|#(write(if(= 1/5 .2)26 3))"""
Edit: Beatnik removed since primality testing in Beatnik might not be possible.
The code has tabs in it (which get mangled by Stack Exchange) and a trailing newline, so here's the xxd
:
00000000: 237c 233f 3135 672c 4020 2020 0920 2020 #|#?15g,@ .
00000010: 206b 6b6d 4e6d 5361 4965 6f65 3939 2b7b kkmNmSaIeoe99+{
00000020: 5c23 2f2d 3b6e 4030 6561 0a23 5b39 2140 \#/-;n@0ea.#[9!@
00000030: 3e2e 3e2e 6565 6177 7723 2d31 402a 2231 >.>.eeaww#-1@*"1
00000040: 3222 094c 0a23 7b20 090a 2323 230a 2360 2".L.#{ ..###.#`
00000050: 7b0a 3235 0a70 7269 6e74 2834 5e32 202b {.25.print(4^2 +
00000060: 3729 2f32 0a0a 0a22 2222 0a4a 6f20 6973 7)/2...""".Jo is
00000070: 2068 6572 652e 0a24 276d 6169 6e27 4d6f here..$'main'Mo
00000080: 4f20 4f4f 4d0a 2037 0a3e 4a6f 2c20 3330 O OOM. 7.>Jo, 30
00000090: 0a3e 5820 4a6f 0a66 3a3a 3d7e 3237 0a3a .>X Jo.f::=~27.:
000000a0: 3a3d 5d23 237d 2328 7072 696e 2032 3929 :=]##}#(prin 29)
000000b0: 0a70 7269 6e74 2028 372f 362a 3234 2923 .print (7/6*24)#
000000c0: 2323 3b61 6c65 7274 2032 232d 5b3e 2b3c ##;alert 2#-[>+<
000000d0: 2d2d 2d2d 2d5d 3e2d 2e7c 2328 7772 6974 -----]>-.|#(writ
000000e0: 6528 6966 283d 2031 2f35 202e 3229 3236 e(if(= 1/5 .2)26
000000f0: 2033 2929 2222 220a 3))""".
Alternatively, you can copy and paste the code from this "Try it online!" link.
This is pretty badly golfed, but I wanted to play off the idea that, once you have enough languages, byte count doesn't matter as much any more. Having said that there are some languages I could still easily add (e.g. Objeck) but are currently too long to be useful. I'm running out of good languages though, so I might stop here for now.
Run all programs with </dev/null 2>/dev/null
(i.e. empty input, surpressed STDERR).
The explanation's quite long, so here's an executive summary:
No. Lang. Non-esolang? 2D esolang? BF/BF-deriv?
--------------------------------------------------------------------------
1 COW ✓
2 CoffeeScript ✓
3 Common Lisp ✓
4 Retina
5 Befunge-93 ✓
6 Python 2 ✓
7 Rail ✓
8 ETA
9 Prelude
10 Gol><> ✓
11 evil
12 Foo ✓
13 Ruby ✓
14 ><> ✓
15 Brian & Chuck ✓
16 Whitespace
17 3var
18 Axo ✓
19 Labyrinth ✓
20 Starry
21 Fission ✓
22 Brainfuck ✓
23 Julia ✓
24 Lily ✓
25 GolfScript
26 Chicken Scheme ✓
27 Thue
28 Perl 6 ✓
29 Picolisp ✓
30 TRANSCRIPT
COW is a Brainfuck derivative with additional commands, one of which is numeric output. Anything invalid is ignored, so the executed program is merely
MoO OOM
which increments the cell to 1 then prints it as a number.
2. CoffeeScript (includes interpreter)
CoffeeScript sees:
# comments
###
multiline comment
###;alert 2# comment
which simply alerts 2.
(Yes, it'd probably be better if another language took this slot, but I'm too lazy to reshuffle at this point :P)
Common Lisp (clisp) sees:
#|
multiline comment
|#(write(if(= 1/5 .2)26 3))"""
1/5
is a rational and not equal to 0.2
, so 3 is printed. The proceeding """
is a syntax error.
Note that print
seems to output a preceding newline and trailing space in Common Lisp. However, luckily, write
works in both Common Lisp and Chicken Scheme.
Restrictions introduced: Every second line starting from the first needs to be a valid regex.
Every pair of lines form a replacement stage, replacing instances of matches of the first line's regex with the second line. In the middle, we have the pair
"""
which replaces the initial empty string with """
. The final empty line, not part of any pair, is treated as a match stage, counting the number of matches of the regex. There are four instances of empty string in """
, namely 1"2"3"4
.
Befunge is a 2D language, and the relevant instructions are
# # 15g,@
in the first line, and the 5
in the 25
line. #
skips the next instruction, 15g
gets the char at position (1, 5)
in the code (the 5
in the 25
line), ,
outputs the char and @
halts.
Python sees:
# comments
25
print(4^2 +7)/2
"""
multiline string
"""
(4^2+7)/2 = (xor(4,2)+7)/2 = (6+7)/2 = 13/2 = 6
, which gets print
ed.
Rail is a 2D language, and execution start from the $
of the main function, heading southeast. Thus, the relevant portion of code is
$'main'
7
o
J
with the o
and J
coming from lines used by TRANSCRIPT. After outputting 7, the train hits an unrecognised J
instruction, which crashes the program.
Restrictions introduced: Chars before the ETA program should not be in etaoinsh
.
ETA only recognises the letters etaoinsh
and their uppercase versions, meaning the code starts off with
NSaIeoe
n...e
pushes a base 7 number based on what's within the delimiters, which for SaI
is 624
, or 312 in decimal. o
then outputs as char, apparently after modulo 256, giving the char 8
(code point 56). e
then tries to divide with an empty stack, which fails.
Restrictions introduced: No more than one of ()
in any column, ()
matched reading a column at a time, no infinite loops caused by ()
.
This requires the Python interpreter to have NUMERIC_OUTPUT = True
set.
Prelude is a language where each line is executed separately. A lot of chars get executed, but the important part is the
9!
on the second line, which outputs 9. ()
in Prelude denote a loop, but thanks to the prominence of #
s (which pop from the stack), the tops of the stacks are always 0 by the time a loop is hit, so none of them are run. Prelude's source code restrictions regarding ()
introduced some extraneous spaces though.
This part (and ><>) work like Martin's answer. The relevant code is
# ;n@0ea
Gol><> is a 2D language and #
reflects the IP, making it travel leftwards. It wraps around, push 10, 14 and 0 to the stack. @
then rotates the stack, bringing 10 to the top, n
outputs it and ;
halts the program.
This part's also similar to Martin's answer.
evil ignores everything except lowercase letters. Ignoring a few more characters, the relevant part is
aeeeaeeaww
where a
increments the variable A
, e
is evil's weave function which shuffles the bits of A
, and w
outputs A
. Hence we output 1
twice, giving 11
.
But what about the rest of the instructions, and especially that w
on the last line? Let's just say that sometimes it's easiest to just mess with the code and pray it still works in everything which, here, it somehow did...
Foo outputs anything between double quotes, so the relevant part is the
"12"
on the second line. However, since we need double quotes later we use a method similar to Martin's answer to make Foo error out, namely the preceding #-1@
. It's unclear why that works in a language which soldiers on in the face of empty stack and division by zero errors, but I'm glad it does.
Like Python, Ruby sees:
# comments
25
print(4^2 +7)/2
"""
multiline string
"""
However, it's worth noting that the multiline string is actually three separate strings (""
, "..."
, ""
) concatenated together. The print line outputs (4^2+7) = xor(4,2)+7 = 6+7 = 13
, before erroring out trying to divide nil
by 2.
This part's the same as the Gol><> part, except @
brings the 14 up to the top instead, which gets outputted.
Brian & Chuck is a BF derivative with two tapes, where one tape's instruction pointer is the other tape's memory pointer. In the absence of ```
, the first two lines of the source code are used to initialise the tapes.
The relevant chars in the first two lines are:
?15
# >.>.
The ?
in Brian's tape passes control over to Chuck in the cell being pointed to (the #
) is nonzero. Chuck then executes >.>.
, outputting the two chars after the question mark.
Using STL
for space, tab and line feed respectively, the start of the program is:
SSSTSSSSL
TL
STL
L
L
The first line pushes 16 (+10000
base 2), the preceding TLST
prints it as a number. The next three newlines halt the program.
Note, however, that this program is interpreter specific. The rest of the code syntax errors in most interpreters, so a more lenient interpreter is required, like the one linked above.
Of the first line, a slew of instructions get executed, but the relevant ones are
kkmmao#/
Due to ETA's restriction, we use k
to decrement the variable B rather than a
to increment it. kk
decrements B to -2 and mm
squares B twice to 16, which is incremented to 17 with a
. This is then outputted with o
.
#
is then used to reset B to 0, and /
causes the program to error out via division by 0.
Restrictions introduced: No instructions before the Axo program which change the direction of the IP
Once again, a slew of instructions get executed in the first line, but the relevant ones are
# # 15 ,@ 9 9 + { \
Axo is a 2D language like Befunge, and #
is similarly a bridge that skips the next instruction, but only if the top of the stack is zero. 15,
push to the stack, but the stack is emptied with @
. 99+
then pushes 18, {
outputs and \
halts.
Labyrinth is another 2D language, and the executed instructions are
#|#
[9!@
#
pushes the length of the stack, which is 0 the first time. |
is bitwise OR, not changing anything since the stack just has 0s at this point, and the second #
now pushes 1 due to the lone zero. We turn right due to the 1, 9
converts this 1 to 1*10+9 = 19
, !
prints it and @
halts.
This program relies on the fact that [
is not currently a recognised instruction, and hence is treated as a wall.
Restrictions introduced: All +
s must have at least one preceding space
If we strip away unrecognised characters, the relevant part of the code is
, +.. +
,
is input, but since we pipe from /dev/null
there is none, pushing 0 to the stack. A +
with n >= 5
preceding spaces pushes n-5
, so the next instruction pushes 2. ..
then outputs these two digits in reverse order.
Next we have a +
with a single preceding space, which duplicates. However, the stack is empty, so we error out.
The only relevant part for Fission is
*"12"L
L
spawns an atom moving leftward, "21"
prints 21 and *
halts.
Introduced restrictions: No .
before the first [
This requires an interpreter which gives 0 on EOF and has 8-bit cells. The relevant code is
,+-[>.>.-+.>,>]-[>+<-----]>-..
The inital -
is to offset the +
, and the first [...]
is not executed since the cell is 0. The following -[>+<-----]>-
sets the cell to the char code of 2
, and ..
outputs it twice.
Julia sees:
# comments
25
print(4^2 +7)/2
What's printed is 4^2+7 = pow(4,2)+7 = 16+7 = 23
, and the program errors out trying to divide nothing
by 2. Note that Julia doesn't seem to mind the fact that the rest of the code would cause a syntax error anyway.
Lily sees:
# comment
#[
multiline comment
]## comment
print (7/6*24)# comment
7/6*24 = 1*24 = 24
is printed.
GolfScript sees:
# comments
25
print(
GolfScript is stack-based, so 25 is pushed to the stack, then popped and printed with print
. (
then tries to decrement the implicit empty string on the stack, which fails and errors out the program.
Chicken Scheme has the same #| ... |#
multiline comment syntax as Common Lisp. However, in
(write(if(= 1/5 .2)26 3))
1/5
is a float which is equal to 0.2
, so 26 is outputted instead.
Thue is a language based on string rewriting. The first relevant part is
f::=~27
::=
which defines a substitution f -> 27
then denotes the end of substitutions with ::=
. The lone f
in if
is then replaced with 27
, which is outputted.
Perl 6 has a new comment syntax, namely #`(some bracket)
which is a multiline comment all the way to the matching bracket. Thus, Perl 6 sees:
# comments
#`{
multiline comment
}# comment
print (7/6*24)# comment
which prints 7/6*24 = 28
.
Picolisp sees:
# comment
#{
multiline comment
}#(prin 29)
which prints 29. The line afterwards then causes a syntax error.
TRANSCRIPT is a thematic esolang modelled after text adventures. Unrecognised lines are ignored (which allows you to add extra story/flavour text amongst the actual code instructions), so the relevant lines are:
Jo is here.
>Jo, 30
>X Jo
The first line declares a string variable Jo
, using a two-letter name since one-letter names seem to fail. The second line sets this string to "30"
, which is outputted by X
("examine") in the third line.
Why not have different minor types as unique? It's not like the similarities could help you. You would have to use some pretty specialised code that runs completely different in python 2.7.1 and 2.7.3 – Blue – 2015-12-03T16:56:51.353
6@muddyfish You might be able to fetch the minor version within the code, which would then give you free solutions for all
2.7.1
to2.7.n
. (Actually, sweerpotato does just that with major versions.) – Martin Ender – 2015-12-03T17:04:24.18014I think maybe shortest solution by language doesn't make sense here... :P – FryAmTheEggman – 2015-12-03T20:44:10.447
@FryAmTheEggman I just copy the script :P I'm not good enough at reading compacted JS/jQuery to remove that bit. – Mego – 2015-12-04T03:27:07.130
3@Mego Neither am I, that's why I leave sarcastic comments about the problem so that other people find out about it :P – FryAmTheEggman – 2015-12-04T03:50:00.263
12I just wanted to congratulate you on how well-balanced your scoring is. When code challenges mix two quantities into one score the balance is almost always off such that the best answer will just optimise one of the scores without having to consider the other one at all. The cubic weight of the number of languages was perfect here... while it was always possible to add another language it was always a very nice (but doable) challenge to do so in the number of bytes available. :) – Martin Ender – 2015-12-05T23:49:43.197
@StewieGriffin: Would I satisfy the javascript requirements if the version used for it was only supported in firefox and they droped support of that version since version 12? – Zaibis – 2015-12-08T14:12:47.597
20
In this PPCG challenge we've been collaboratively building a polyglot. It now has a better score on this challenge than the leading entries submitted to this challenge, but it wouldn't make sense to copy a group effort that's constantly being improved over, so I'm just dropping a mention in the comments here.
– None – 2017-03-17T23:56:53.9831^^How about community wiki with a link to the challenge? – geokavel – 2017-08-08T04:02:47.943
1I meant put the latest answer from the answer chain polyglot question as a community wiki answer on this question. – geokavel – 2017-08-08T15:47:48.607