An OEIS polyglot
4. Jelly, A000312
n=>40-n//
//[>[-]<[>+<-],]>>+<[->[>>+<<-]>[<+>-]>[<+>-]<<<]>>>>++++++[<++++++++>-]<<[>+<-]>+.
//ip@
//
;/**/
C# (Visual C# Interactive Compiler)
brainfuck
Runic Enchantments
Jelly
Explanation:
We only account for the last line, all of the other lines are ignored.
;/**/ Argument: z
;/ Reduce z by ; (concatenation) [1]
z is an integer, so this just returns z itself.
*/ Reduce z by * (exponentiation) [2]
Again, this returns z itself.
* Exponentiation: return [1] ** [2]
This resolves to (z ** z).
To make C# ignore the code, we're trying to put it in a comment. However, a line starting with /
isn't valid in Jelly, because /
needs an operand. The operand we're using here is ;
, since that also fits perfectly as a semicolon in C#. In fact, the semicolon and empty multi-line comment together make a link that calculates \$^2z=z^z\$. Note that the function submission in C# is still valid, as there's no general consensus disallowing multiple statements in an anonymous function submission (e.g. imports).
16. Java 8, A000290
//0q GxxJiiiiihhZUUUUUUUNYAxcccccbCLDLxyzUUUUUTxyzJCLOzUUUUUURzyzxyzxyzcccccbbCLGC//*/0e#'
/*
박망희 0#
;*/
//\u000A\u002F\u002A
n=>//\u002A\u002Fn->
/**/""+n==""+n?5/2>2?1:40-/**/n:n*n//AcaAcAAI(((1)(1)(1)1)((1)(((1)1)1)1)(((1)(1)1)(((1)((1)1)(1)1)1)(((1)(1)(1)(1)1)(((1)(1)((1))(1)1)((1)((1)1)(1)1)(((1)1)(1)(1)1)1)(((1)1)(1)1)(((1)1)1)1)1)1)
//[>[-]<[>+<-],]>>+<[->[>>+<<-]>[<+>-]>[<+>-]<<<]>>>>++++++[<++++++++>-]<<[>+<-]>+.wvWwwWWwwwwwwWwWWWw
//ip@
//
;/**/
//I01-* h
//
;/*""'"""'""""""""""'"""" "'""'"""""""'"""'""""'"'"""""""'"""'""""""'"""'""""""""""*/
Never thought I'd see the day where I would be able to add a Java answer as 16th answer in a polyglot-chain! :D
1. Try it in C#: \$a(n)=40-n\$
2. Try it in brainfuck: \$a(n)=1+n\text{ mod }2\$
3. Try it in Runic Enchantments: \$a(n)=4^n\$
4. Try it in Jelly: \$a(n)=n^n\$
5. Try it in Gol><>: \$a(n)=-n\$
6. Try it in JavaScript: \$a(n)=1\$
7. Try it in Parenthetic: \$a(n)=1\text{ if }x^n+y^n=z^n\text{ has a nontrivial solution in integers, otherwise }a(n)=0\$
8. Try it in Whitespace: \$a(n)=3\$
9. Try it in 05AB1E: \$a(n)=0\$
10. Try it in Unreadable: \$a(n)=n\$
11. Try it in Grass: \$a(n) = \lfloor n/10^\left(\lfloor log_{10}(n)\rfloor\right)\rfloor\$
12. Try it in Width: \$a(n)=n+1\text{ with }n\geq2\$
13. Try it in AlphaBeta: \$a(n)=1\Vert n\$
14. Try it in Aheui: \$a(n)=2\$
15. Try it in Commentator. \$a(n)=2n+6\$
16. Try it in Java 8: \$a(n)=n^2\$
Explanation:
Let me start by saying that although I've heard from each of these languages before here on CGCC, I'm only skilled with Java, C#, 05AB1E, and Whitespace, and apart from that can read the JavaScript part of the code. The other languages are mostly unfamiliar for me, so I hoped after the changes I had in mind to make the Java interact with C#/JavaScript, most other languages would still work.
The first main thing to tackle was Java's n->
vs C#/JavaScript's n=>
. Java support unicode values as part of the code, so using the following:
//\u000A\u002F\u002A
n=>//\u002A\u002Fn->
Will be interpret as this in C#/JavaScript:
//\u000A\u002F\u002A
n=>//\u002A\u002Fn->
But as this in Java:
//
/*
n=>//*/n->
This is because \u000A
is a line-break, \u002F
is /
and \u002A
is *
in Java.
Then to differentiate the sequence between Java vs C#/JavaScript I added the following:
""+n==""+n?...:n*n
where ...
is the existing 5/2>2?1:40-n
, and n*n
is the Java part of the code for oeis sequence A000290 (squares a.k.a. \$a(n)=n^2\$).
Why does this work? In Java Strings are Objects, where ==
is used to check if references of objects are pointing to the same place (or to check if primitives are equal), and the actual Object.equals(Object)
has to be used to check if the values of these Objects are the same. So ""+n==""+n
will be falsey in Java, but truthy in C#/JavaScript.
After that was tackled (by re-using the existing newlines to not break the Whitespace program), some things had to be fixed. Four of the existing programs were failing now: Runic Enchantments, Jelly, Unreadable, and Commentator.
The fix for Unreadable was easy. We added four """"
before the first '
, so we simply put the '
somewhere earlier (I placed it at the end of the first line), and remove the leading '""""
from the Unreadable part of the code at the bottom.
After that came Jelly, which was giving an IndexError: pop from empty list
. I'm not too skilled in Jelly, so I don't exactly know why it gave this error. If I remember correctly the last line will be the main-link of a Jelly program, and because the code in that last line doesn't use any of the other links, everything else should be ignored. But somehow the part ""+n==""+n
still gave some issues. I was able to fix this by adding /**/
in front of that line.
As for Runic Enchantments, it didn't output anything anymore. @Draco18s pointed out to me that Runic Enchantments starts at all >
simultaneously, but only the >2?1:40-n/
and /ip@
were relevant. This was a huge help to understand the flow of the Runic Enchantments program, and I was able to fix the path by adding a /**/
at >2?1:40-/**/n:n*n
, and changing the positions of the //ip@
, //
, and space on the last line.
All that's left was Commentator. At that point I realized that my previous fixes of adding /**/
weren't such a good idea after all, since it would output a bunch of additional rubbish due to the builtins /*
(convert active to unicode character and output) and */
(output active as number).. >.> After a bit of fiddling around and trying some things, the fix turned out to be very easy: I've added an e
before the #
on the first line. e#
is the builtin to negate an active, fixing the issues caused by the code I added (apparently).
6. JavaScript (Node.js), A000012
//
n=>5/2>2?1:40-n//
//[>[-]<[>+<-],]>>+<[->[>>+<<-]>[<+>-]>[<+>-]<<<]>>>>++++++[<++++++++>-]<<[>+<-]>+.
//ip@
//
;/**/
//I01-* h
//
;/**/
C# (A022996): Since 5/2==2
the function returns 40-n
(Line 2)
BF (A000034): The added part only pushes the whole tape one cell to the right, others unchanged (Line 2-3)
Runic (A000302): The ?
after 2
skips the 1:
, and other operations follows from 4
(Line 2)
Jelly (A000312): Unchanged last line
Gol><> (A001489): Unchanged first column
JS(ES6) (A000012): Since 5/2>2
the function returns 1
(Line 2)
Sneaked the ternary 5/2>2?1:40-n
into the C# part. In C# since 5/2==2
the function returns 40-n
, while in JS 5/2>2
the functions returns 1. The C-style comments made it nearly impossible to add more practical languages (specifically C and Python). More spaces are added on lines 4-5 to ensure that the Runic part works.