Tell me more ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

This challenge is an extension of 'Golf a mutual quine'.

Using three languages of your choice, create a third order Ouroboros program.

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, which in turn outputs the original program pA in language A.

No two languages in A, B, and C can be the same or subsets or supersets of each other. None of pA, pB or pC may be identical.

For example, a Haskell program outputs a Perl program which outputs a java program which outputs the original Haskell program would be valid.

On the other hand, a C# 4 program which outputs a C# 3 program which outputs a C# 2 program is invalid. Even a Perl -> Ruby -> Bash combination would be invalid if, say, the Perl program and the Ruby program were identical.

This is code golf, so the shortest program pA wins.

share|improve this question
2  

2 Answers

Python -> Perl -> Ruby, 48 characters

Adaption of my previous answer. Running

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:

diff -s <(ruby <(perl <(python thirdorderquine.py))) thirdorderquine.py 
Files /dev/fd/63 and thirdorderquine.py are identical
share|improve this answer

Perl -> PHP -> HTML + JavaScript, 105 chars

I wanted to make the chain of languages somehow meaningful, so I figured I'd write a PHP script that generates a HTML page containing JavaScript. For the third language I chose Perl, just because I like Perl. :)

Some might consider this four languages, but I don't really count HTML as separate from JavaScript here — it's a markup language, not a programming language. Anyway, here are the three versions:

Perl (105 chars):

printf+(q(<script>alert(unescape("<?=urlencode(<<<E%sprintf+(q(%s),$/)x2,$/%sE%s)?>"))</script>),$/)x2,$/

PHP (165 chars):

<script>alert(unescape("<?=urlencode(<<<E
printf+(q(<script>alert(unescape("<?=urlencode(<<<E%sprintf+(q(%s),$/)x2,$/%sE%s)?>"))</script>),$/)x2,$/
E
)?>"))</script>

HTML + JavaScript (235 chars):

<script>alert(unescape("printf%2B%28q%28%3Cscript%3Ealert%28unescape%28%22%3C%3F%3Durlencode%28%3C%3C%3CE%25sprintf%2B%28q%28%25s%29%2C%24%2F%29x2%2C%24%2F%25sE%25s%29%3F%3E%22%29%29%3C%2Fscript%3E%29%2C%24%2F%29x2%2C%24%2F"))</script>

(Ps. Yes, I know I could've made the PHP step an almost-noop, e.g. just generating HTML + JS code in Perl and appending <?php to it, but that felt too much like cheating. In this solution, the code is actually processed in PHP instead of just being copied verbatim.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.