15
\$\begingroup\$

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
\$\endgroup\$
8
  • 10
    \$\begingroup\$ Relevant: a 50-language "Ouroboros". \$\endgroup\$ Sep 5, 2014 at 15:04
  • \$\begingroup\$ Very similar (closed): Create a chain of programs in different languages \$\endgroup\$
    – Ypnypn
    Sep 5, 2014 at 15:17
  • \$\begingroup\$ @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. \$\endgroup\$
    – user9206
    Sep 5, 2014 at 15:19
  • \$\begingroup\$ It's actually very similar to this one, but that didn't require the sequence to loop around, so there was no quine component. \$\endgroup\$ Sep 5, 2014 at 15:21
  • 4
    \$\begingroup\$ The 50 languages beast seems to be a winner before we even started. \$\endgroup\$
    – user16991
    Sep 6, 2014 at 19:48

1 Answer 1

8
\$\begingroup\$

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);}'
\$\endgroup\$
1
  • \$\begingroup\$ Very impressive! \$\endgroup\$
    – user9206
    Oct 3, 2014 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy