Это цепочка ответов, связанная с OEIS.
О, это оправдано тем, что компании нужна одна программа для распечатки своих последовательностей OEIS, и у них есть все языки.
Формат цепочки ответов работает следующим образом:
Кто-то отправляет первый ответ, из которого вытекают все дальнейшие решения. Этот ответ является программой, которая, учитывая число N, вводит N-е число в последовательности OEIS любого индекса, который они выбирают (мы будем называть его последовательностью 1), на любом языке, который они выбирают (язык 1)
Кто-то еще приходит и выбирает свою собственную последовательность (которая должна отличаться от предыдущей и от всех предыдущих последовательностей). Они составляют программу на другом языке (который должен отличаться от всех предыдущих языков), в которой задано число N на языке 1, выводится N-е число последовательности 1, а заданное число на языке 2 выводит N-е число последовательности. 2.
Этот процесс продолжается до бесконечности.
N-й член последовательности - это термин, который появляется n раз после первого, начиная с первого элемента. Здесь мы используем 0 и 1-индексацию, чтобы быть проще для кодеров!
Нет языка или последовательности повторного использования.
Входные данные должны быть целым числом или строковым представлением целого числа, а выходные данные должны быть правильными значениями последовательности. Обработка ошибок (не входной int) не требуется.
Вы не должны публиковать дважды подряд.
Вы должны подождать час или больше, прежде чем писать снова.
Кто бы ни был вторым последним, чтобы отправить после недели без ответов (человек, который не разорвал цепь) побеждает, хотя соревнование может продолжаться бесконечно. Если вы последний и можете показать, что можете добавить еще один язык, вы продолжите испытание до следующего победителя.
Вы можете предположить, что ввод или вывод не будут выходить за пределы числового диапазона вашего языка (например, предполагая, что предел IEEE не будет превышен какой-либо последовательностью), но не обманывайте и злоупотребляйте этим, используя язык, который имеет только 1.
Любая последовательность может быть выбрана, если она не использовалась ранее.
Ввод не может быть за пределами для последовательности, которую вы используете.
Две разные языковые версии - это разные языки (Python 2 и Python 3 считаются разными языками). Это не жестко, но, как правило, если оно отделено от другой версии того же языка в TIO, оно отличается.
Это не запрещено, но попробуйте один раз не использовать формулу, которую дает OEIS.
Если ваш полученный код имеет длину более 65536 символов, предоставьте ссылку для доступа к нему (например, Pastebin).
Вот и все, и все. Готовы? Поставил? ВЕСЕЛО!
Да, это «один OEIS за другим», но на мультиплеере. Я думал, что это будет круто.
Ответы:
15. Комментатор , A020739
Попробуйте онлайн!
C #
Brainfuck
Runic Enchantments
Jelly
Gol> <>
Javascript (Node.js) (Все 1s)
вводные
Пробелы (Все 3s)
05AB12 (Все 0s)
Unreadable
Grass
Ширина
AlphaBeta
Aheui (Все 2s)
У меня было несколько планов с Комментатором, но только один сохранился контакт со всеми остальными языками. Одна из них вызвала ошибки в Jelly (iirc), и я не смог ее устранить, потому что не знаю, почему Jelly интерпретировал байты так, как это было.
источник
/\
и его мана. Не могли бы вы дать краткое объяснение потока выполнения в этом последнем номере. 15 ответ для рунических чар?><^v
. The only time it starts at the top left is if the code contains none of those bytes and is only one line long. So this polyglot has a lot of IPs in Runic, but the only one that does anything (currently) is this one:>2?1:40-n/
. The2?
skips the1:
and so the first instructions arepush 4, push 0, subtract
(4-0 → 4). Then a lot of nothing happens until it gets to/ip@
which results intake input, pow(y,x), print-and-terminate
.4. Jelly, A000312
C# (Visual C# Interactive Compiler)
brainfuck
Runic Enchantments
Jelly
Explanation:
We only account for the last line, all of the other lines are ignored.
To make C# ignore the code, we're trying to put it in a comment. However, a line starting with2z=zz . 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).
/
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источник
16. Java 8, A000290
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 a(n)=1+n mod 2 a(n)=4n a(n)=nn a(n)=−n a(n)=1 a(n)=1 if xn+yn=zn has a nontrivial solution in integers, otherwise a(n)=0 a(n)=3 a(n)=0 a(n)=n a(n)=⌊n/10(⌊log10(n)⌋)⌋ a(n)=n+1 with n≥2 a(n)=1∥n a(n)=2 a(n)=2n+6 a(n)=n2
2. Try it in brainfuck:
3. Try it in Runic Enchantments:
4. Try it in Jelly:
5. Try it in Gol><>:
6. Try it in JavaScript:
7. Try it in Parenthetic:
8. Try it in Whitespace:
9. Try it in 05AB1E:
10. Try it in Unreadable:
11. Try it in Grass:
12. Try it in Width:
13. Try it in AlphaBeta:
14. Try it in Aheui:
15. Try it in Commentator.
16. Try it in Java 8:
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'sn=>
. Java support unicode values as part of the code, so using the following:Will be interpret as this in C#/JavaScript:
But as this in Java:
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:
wherea(n)=n2 ).
...
is the existing5/2>2?1:40-n
, andn*n
is the Java part of the code for oeis sequence A000290 (squares a.k.a.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 actualObject.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 ane
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
C# (A022996): Since
5/2==2
the function returns40-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
?
after2
skips the1:
, and other operations follows from4
(Line 2)Jelly (A000312): Unchanged last line
Gol><> (A001489): Unchanged first column
JS(ES6) (A000012): Since
5/2>2
the function returns1
(Line 2)Sneaked the ternary
5/2>2?1:40-n
into the C# part. In C# since5/2==2
the function returns40-n
, while in JS5/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.источник
The C-style comments made it nearly impossible to add more practical languages (specifically C and Python).
Such is the way of polyglot challenges.8. Whitespace, A010701
Try it online!
C#
Brainfuck
Runic
Jelly
Gol><>
Javascript
Paranthetic
I have no idea how Whitespace works. I tried super hard to multiply the input with another value, but it kept complaining about infix arithmetic, so as I had input working, output working, and push-value-to-stack working, so I just went with that.
The input value appears to get lost when pushing
3
to the stack, but oh well. Enjoy a sequence of 3s. The program does technically take input it just ends up discarding it.I also don't know how Paranthetic works, so I can't actually verify that submission as valid, but as far as I can tell the Whitespace code doesn't interfere.
Future answers: be aware that tabs in Runic are a single instruction wide and play havoc with code layout.
источник
[{10: input}]
. To make a cat program that reads and outputs immediately in Whitespace, you usually want to do something like: Push 0; duplicate 0; read STDIN; retrieve (this will pop the 0 we duplicated, and push the value from heap-address 0 to stack); pop and output to STDOUT. PS: Here a useful online debugger I always use.11. Grass, A000030
Try it online!
Grass ignores all characters except
w
,v
andW
; conveniently, these three characters are ignored by several of the previously used languages. Luckily, sequence A000030 (return the initial digit in base 10) was still available, as coding even slightly complicated functions in Grass is beyond my ability.C#
brainfuck
Runic
Jelly
Gol><>
JavaScript
Parenthetic
Whitespace
05AB1E
Unreadable
The relevant part for Grass is
wvWwwWWwwwwwwWwWWWw
. Here is my (probably flawed) understanding of how it works: the stack is initialized asOUT::SUCC::w::IN::ε
(thatw
is just the characterw
). Each instruction adds an element to the stack (they are never popped); the number ofw
s orW
s indicates how deep to go in the stack;v
separates instructions.If the input is
1234
, at the end, the stack probably looks like this:1::1::id IN::id OUT::id::OUT::SUCC::w::IN::ε
.It could be made shorter (don't need to define
id OUT
for example), but I stopped as soon as I found a version which worked.If someone who knows Grass wants to correct/improve the explanation, please edit my answer!
источник
17. Pepe, A000578
Online Interpreter
C#
Brainfuck
Runic Enchantments
Jelly
Gol><>
Javascript (Node.js) (All 1s)
Parenthetic
Whitespace (All 3s)
05AB12 (All 0s)
Unreadable
Grass
Width
AlphaBeta
Aheui (All 2s)
Commentator
Java
You'll have to excuse the Pepe link for not containing the full source: The interpreter disregards any code that is not Pepe (lit. any character not in the set
RE re
) and so its short link doesn't bother encoding it. Ditto input values.Computesa(n)=n3
The AlphaBeta has started throwing errors after writing output, but as a prior answer injected that issue I left it alone. I had planned on fixing it for this answer, but I need to spend some time digging into the jump offsets to resolve the issue. The error with inputs
>0
are easy to fix, but giving it0
will produce the same error and it will take time to relearn the code in order to fix the offset for it. I wish I could useW
instead ofUUUUUUUUUU
, but it plays havoc with the Grass code.источник
1. C# (Visual C# Interactive Compiler) A022996
Also works in C# (.NET Core), C# (Mono C# compiler), C# (Mono C# Shell), and C# (Visual C# Compiler)
Try it online!
источник
9. 05AB1E, A000004
C# (Visual C# Interactive Compiler)
brainfuck
Runic Enchantments
Jelly
Gol><>
JavaScript (Node.js)
Parenthetic
Whitespace
05AB1E
источник
7. Parenthetic, A019590
C# (A022996)
BF (A000034)
Runic (A000302)
Jelly (A000312)
Gol><> (A001489)
JS(ES6) (A000012)
Parenthetic (A019590)
Parenthetic ignores everything but the
(
and)
characters. I've had to insert1
s before every closing parenthesis to stop Jelly from freaking out though (EDIT: I left one)
unpreceded by a 1, so apparently not all of them need one, but it's too late to golf it down now). The actual code defines a lambda called((()))
, that can be called on a number to yield the result (1-indexed).источник
((()))
. The footer calls that function, with whatever argument you want. The set of parentheses under the number 2 means 2 in Parenthetic. Changing the final()()
to()
*n will call the function onn
.10. Unreadable, A001477
Try it online!
C#
Brainfuck
Runic
Jelly
Gol><>
Javascript
Paranthetic
Whitespace
05AB1E
Unreadable, as its name suggests, is unreadable. In order to program it I had to use a template and then convert from readable text to Unreadable code.
All it does is read each character in the input and output it. One of the more boring sequences, but good for a language that's difficult to work with. I also toyed with using the sequence A000030 before getting the loop to work.
Working via remote desktop is a pain, you think things work, do all the links, then realize that one of them broke and didn't notice.
источник
;/**/
in the middle area is not doing anything and could be removed. 99% sure. It was a Jelly chunk, but it got duplicated somewhere along the way and no longer serves a purpose.14. Aheui, A007395
Slightly changed to make AlphaBeta works.
Try it online!
Aheui dismiss any non-Korean character, so
박망희
excuted, which prints2
and terminates.C#
Brainfuck
Runic Enchantments
Jelly
Gol><>
Javascript (Node.js)
Parenthetic
Whitespace
05AB12
Unreadable
Grass
Width
AlphaBeta
Aheui
источник
/*
and it works now. And Aheui code is (slightly more) good to see.2. brainfuck, A000034
Try it online!
C#
источник
3. Runic Enchantments, A000302
Try it online!
C#
BF
If you need help keeping the Runic functional, there is the Esoteric IDE as well as my own IDE (built in Unity3D) in the master branch of Runic's git repo. Esoteric IDE doesn't handle displaying the IP directionality very well (primarily my own inability to add such to the existing framework).
All the BF creates a bunch of IPs that self terminate due to performing invalid actions (mainly due to stack underflow) while the
>
in the C# populates the stack with a4
, bounces of the comment makers (mirrors in Runic), reachingip@
to executex^4
on an input x and print the result.источник
5. Gol><>, A001489
Try it online!
C#
Brainfuck
Runic
Jelly
Use single-line comment markers in C# to redirect the Fish IP to the operative code,
I01-*h
, reading input, multiplying by -1, and outputting the result. Gol><> made reading input and dumping the stack as a number easy compared to raw ><>.Spaces inserted to insure the proper flow of the Fish and Runic IPs, where both C# and Jelly ignore the leading whitespace on the last line (and is a NOP cell in both fungoids).
источник
12. Width, A020725
1-indexed. Outputs by exit code.
Try it online!
The only relevant characters to Width are
a-zA-Z
. The code Width runs is the following:The first three characters,
qnn
, are no-ops.Ac
reads an integer from input,a
is a no-op, and thenAcAA
increments the integer by one.I
ends the program, and the top of the stack is becomes the exit code. All other letters in the program are ignored since the program terminated.C#
brainfuck
Runic Enchantments
Jelly
Gol><>
JavaScript
Parenthetic
Whitespace
05AB1E
Unreadable
Grass
источник
13. AlphaBeta, A162672
Try it online!
I had originally planned to use sequence A000030 and the code
JCL
, but that got yoinked (I don't blame them, its a good sequence for languages that take input as single bytes). The original code for this entry after having to pick a new sequence was:Sequences of
xxx
orxyzxyz
are useful spacers to make the jump-to targets easy values (46 is easier as "5*10-4"--9 instructions--than "4*10+6--ten instructions--but 50 is even simpler: only five). You'll see a fair few of those.But as there are other bytes on the first line, the jump-to codels needed some new values and that turned into:
Avoiding executing this code as Width code just involved wrapping it in
G
to make it a string literal (which does nothing important in AlphaBeta), a command to pop the top of the stack, and then some extraW
to make alpha beta not crash when exiting:To avoid conflicts with Grass, though, instead of popping the command with
w
C
is used instead. Then the "exit program" jump is replaced withUUUUUU
instead ofWWWWWW
This does leave the IP somewhere in the middle of the rest of the junk code, but far enough out that it doesn't print any errors. Any number of additionalU
s can be added in pairs if this becomes a problem.The additional
i
that Runic ends up executing is a NOP on valid inputs as no-input-left-to-read pushes nothing to the stack ("reading all input" is a pain in Runic).C#
brainfuck
Runic Enchantments
Jelly
Gol><>
JavaScript
Parenthetic
Whitespace
05AB1E
Unreadable
Grass
Width
источник
18. ]=[, A010716, the all 5's sequence
This language isn't on TIO and its only interpreter is written itself in another interpreted language, which is also not on TIO. And the one that didn't play nice with Brainfuck last week at the last minute, but I figured out what was wrong a few hours after posting the Pepe answer, so I saved it for this week. Being a language not on TIO I was considering this one an ace-in-the-hole that could easily be tacked onto just about ANY entry and continue the chain.
Put the interpretter code into the "code" box at the top, code from the answer in the input, and click run and get an output (plus some extra junk that is always printed).
The operational portion of the ]=[ is this at the end of the first line:
Its that trailing
[
that played havoc with the Brainfuck (the rest being ignored, due to how[
and]
are handled by Brainfuck) and once I looked at the Brainfuck spec again I realized the problem and that all I had to do was insert a]
somewhere after the first line (as the ]=[ interpreter does not read newlines) and before the Brainfuck. I chose the 2nd line.C#
Brainfuck
Runic
Jelly
Gol><>
JavaScript (Node.js)
Paranthetic
Whitespace
05AB1E
Unreadable
Grass
Width
AlphaBeta
Aheui (esotope)
Commentator
Java (OpenJDK 8)
Pepe
источник
19. Actually, A005843 (2*n)
Try it online!
Operational part:
,2*1z⌂
(first line)As
⌂
terminates the program, none of the code after it has any effect, and none of the symbols before it result in any output or pollute operational memory adversely. Section exists within a comment (C#, JS, Java), only contains ignored characters (Commentator, ]=[, Pepe, Aheui...), is not on the last line (Jelly), or otherwise in un-executed parts of the code (Gol><>, Runic, AlphaBeta).C#
Brainfuck
Runic
Jelly
Gol><>
JavaScript (Node.js)
Paranthetic
Whitespace
05AB1E
Unreadable
Grass
Width
AlphaBeta
Aheui (esotope)
Commentator
Java (OpenJDK 8)
Pepe
]=[ (link not possible, see #18 for instructions)
источник
]=[
can't be turned into a url.20. Neim, A008592 (10*n)
Try it online!
I have no idea how the heck Neim works. I know what the code here ends up doing, but I have no idea how the language itself works.
Also turns out I messed up the Brainfuck with #19. Due to command conflicts between multiple languages, changing Actually's input to
§
and then coercing it to an int with≈
was the optimal solution.C#
Brainfuck
Runic
Jelly
Gol><>
JavaScript (Node.js)
Paranthetic
Whitespace
05AB1E
Unreadable
Grass
Width
AlphaBeta
Aheui (esotope)
Commentator
Java (OpenJDK 8)
Pepe
]=[ (link not possible, see #18)
Actually
источник
21. Flobnar, A010709 (All 4s)
Try it online!
Flobnar starts at
@
and expands outwards evaluating items as the rules dictate (@
evaluates to whatever's on its left,4
evaluates to4
,+
evaluates to whatever's on the left summed with whatever's on the right, etc). As the placement of the@
only comes into contact with Runic, a simple!
prevents alteration of Runic's stack.Given that Flobnar's input metric is "one byte" and goes into an infinite loop if there are no bytes to read, I decided not to bother with anything more complex.
Previous languages
C#
Brainfuck
Runic
Jelly
Gol><>
JavaScript (Node.js)
Paranthetic
Whitespace
05AB1E
Unreadable
Grass
Width
AlphaBeta
Aheui (esotope)
Commentator
Java (OpenJDK 8)
Pepe ]=[ (link not possible, see #18)
Actually
Neim
источник
4@
worked easily enough that I just went with that.