How long is your (language) snake?

14

3

Following on from the third order quine challenge, your task is to write an Ouroboros program that uses as many languages as possible.

That is, in language A, write a program pA which outputs program pB in language B. Program pB should output program pC in language C, and so on until eventually a program outputs the original program pA in language A.

No two languages in your loop can be the same or subsets or supersets of each other. None of the programs in the loop may be identical.

The longest chain of languages win. The length of the source code will be the tie-breaker.

Here is an example solution of length 3 given by Ventero.

s='print q<puts %%q{s=%r;print s%%s}>';print s%s

with Python generates this Perl snippet

print q<puts %q{s='print q<puts %%q{s=%r;print s%%s}>';print s%s}>

which generates the following Ruby code

puts %q{s='print q<puts %%q{s=%r;print s%%s}>';print s%s}

which then prints the original Python snippet:

s='print q<puts %%q{s=%r;print s%%s}>';print s%s

user9206

Posted 2014-09-05T14:49:10.787

Reputation:

Yusuke Endoh created a quine of length 50! Details and git are found here: Quine Relay

– Jordan – 2014-10-10T03:28:35.320

10

Relevant: a 50-language "Ouroboros".

– algorithmshark – 2014-09-05T15:04:15.177

Very similar (closed): Create a chain of programs in different languages

– Ypnypn – 2014-09-05T15:17:56.353

@Ypnypn It's not a duplicate of that is it? I mean this is to make the loop as long as possible with a tie-breaker of the source code length. No one has ever had the chance to post a length 4 Ouroborous before :) Also a loop is different from a chain. – None – 2014-09-05T15:19:44.780

It's actually very similar to this one, but that didn't require the sequence to loop around, so there was no quine component.

– Martin Ender – 2014-09-05T15:21:39.560

4The 50 languages beast seems to be a winner before we even started. – None – 2014-09-06T19:48:29.883

@kuroineko He hasn't entered it and we have no idea how he did it. I think we can safely ignore it (and it would be cheating to copy it). I suspect an entry with 4 languages would probably win here. – None – 2014-09-06T19:50:07.757

And did you notice that the 50-language Ouroboros is in alphabetical order? – justhalf – 2014-09-26T02:21:31.250

Answers

8

Here's a loop of 4 languages:

C -> Bash -> Batch -> Python -> C

C

main(){char *c="echo %cecho print %cmain(){char *c=%c%c%s%c%c;printf(c,34,39,92,34,c,92,34,39,34);}%c%c";printf(c,34,39,92,34,c,92,34,39,34);}

Bash

echo "echo print 'main(){char *c=\"echo %cecho print %cmain(){char *c=%c%c%s%c%c;printf(c,34,39,92,34,c,92,34,39,34);}%c%c\";printf(c,34,39,92,34,c,92,34,39,34);}'"

Batch

echo print 'main(){char *c="echo %cecho print %cmain(){char *c=%c%c%s%c%c;printf(c,34,39,92,34,c,92,34,39,34);}%c%c";printf(c,34,39,92,34,c,92,34,39,34);}'

Python

print 'main(){char *c="echo %cecho print %cmain(){char *c=%c%c%s%c%c;printf(c,34,39,92,34,c,92,34,39,34);}%c%c";printf(c,34,39,92,34,c,92,34,39,34);}'

Josh

Posted 2014-09-05T14:49:10.787

Reputation: 2 783

Very impressive! – None – 2014-10-03T08:58:39.603