Quine of orders

10

2

Write a program that, when run in different languages, outputs a different byte permutation of the code in each language. The exact source code is counted as one permutation.

Here "different language" can be different version(Py 2 and Py 3) or different standard flags. It's different output that forces different version.

Proper quine rules apply for the program in each language. Your score is calculated as (Language count)^6/(Code length in bytes), with a higher score being better.

Sample:

If your code is AAB and running in three different languages returns ABA, AAB and AAB, then its score is 2^6/3(only one of the two AAB count). It's fine if ABA is meaningless.

l4m2

Posted 2018-04-12T08:59:30.683

Reputation: 5 985

1What counts as a different language? – Laikoni – 2018-04-12T09:24:57.590

4

Which definition of a proper quine applies? (Martin's, or ais523's, or maybe some other definition in these meta threads?) Do the proper quine rules apply only to interpretations of the program that are actually quines? (For what it's worth, I don't think this challenge is improved much by enforcing proper quine rules.)

– Lynn – 2018-04-12T09:28:05.683

To clarify, working on your example — if my code AAB prints AAB in language-1 and ABA in language-2, I assume that it must be a proper quine when viewed as a language-1 program, and there are no further restrictions involving its interpretation as a language-2 program. Is that right? – Lynn – 2018-04-12T09:31:08.337

@Laikoni assume that, if it prints a different permutation then it is a different language – H.PWiz – 2018-04-12T09:54:54.637

1Is code length counted in characters or bytes? What should we do with different character encodings? – dylnan – 2018-04-12T19:34:20.863

None of the programs are required to be a quine, right? – dylnan – 2018-04-13T00:41:40.227

@dylnan True. Program 123 outputting 321 and 132 is allowed – l4m2 – 2018-04-13T03:36:46.137

1What about bytes vs. characters? – dylnan – 2018-04-13T03:41:20.543

Proper quine rule is to avoid some code like if(language1)output thiscode().permutation(5);else if(language2)output thiscode().permutation(6);else ... – l4m2 – 2018-04-14T15:36:56.150

Answers

10

Befunge-98, ><>, Gol><>, Fission, Wumpus, Cardinal, Beeswax and Alice Score: 86/88 = 2978.909

"65*4+059*$!#.39*0jp2+'Wk,@ ''5&.'\d&o@o&88#+\@ol?!,'.'0.6'!+Ox,++tttt=++%-$#}.6~.F4*`*R

Try it in Befunge! Try it in ><>! Try it in Gol><>! Try it in Fission! Try it in Wumpus! Try it in Cardinal! Try it in Beeswax! Try it in Alice!

Verification!

Lots of 2D languages, all abusing wrapping string literals. The difference in outputs are thus:

><>, Gol><> and Befunge-98 all print the code backwards (except for the "), with the last three characters in different positions, R*", O"* and "R* respectively. Beeswax also has the code backwards, but the last three characters are interspersed in the first section of the output. Alice is mostly backwards, except for all the escaped characters (',\ and ") moved to the front instead.

Wumpus is the only actual quine, Fission puts the " at the end of the code instead of the beginning, and Cardinal puts the " between the 0 and the 5 near the start.

Proof of different permutations

Explanations:

Befunge-98:

"  Wrapping string literal pushes all other characters + a space to the stack
 65*4+  Push " to the stack
      059*$!#.39*0j   Push 1,27 to the stack
                   p  Pops the top three values of the stack (27,1,34)
                    2+  Adds 2 to the space to make "
                      'Wk,@  Prints the top 88 characters of the stack and terminates

><> and Gol><>:

To be honest, I didn't do much here. The only difference between the execution of these two languages is the @ command, which rotates the top three values of the stack in different ways for each language.

"  Wrapping string literal pushes all other characters to the stack
 65*4+  Push 34 (") to the stack
      059*$!#.  Jump to cell 45,0
                                   \@  Rotate the top three values of the stack 
                                     ol?!,'.'0.  Output the whole stack, ending in a divide by 0/stack underflow error

Fission:

 "............R  Spawn a pointer going right

 "  Switch to printing mode and print every other character
 "  Switch off printing mode
  6  Teleport to other 6
 "........6'!+O   Print the "

Wumpus:

"  Bouncing string literal
 65*4+  Push a (")
      059*$!#.   Push 0 and jump to cell 0,45
                                        \  Reflect off mirror
                                       +   Add 0 to top of stack
                                 @o&88#    Print the top 88 characters of the stack

Cardinal:

                                 %   Spawn two pointer going left/right (up/down despawn immediately)
                                  -$  Right pointer jumps to cell -1,0
                      x,++tttt=++     Left pointer prints "
"  While right pointer switches to print mode and prints the code

Beeswax:

 "................*`*   Spawn pointers going in every direction
                        Every other * also spawns pointers, but they do nothing
                   `    Turn on print mode for two of the pointers going in different directions
                        This prints everything but the `
          #}.6~.F4*     Print a `

Alice:

"  Wrapping string literal pushes all other characters to the stack
   Except 's and mirrors
 65*4+  Push " to the stack
      059*$!#.  Does nothing
              39*0j  Jumps to cell 39,0
                         ''5&.    Push ' and duplicate it 5 times
                              '\  Push \
                                d&o@  Print the whole stack

Jo King

Posted 2018-04-12T08:59:30.683

Reputation: 38 234

6

Perl 5, Ruby, JavaScript (Chrome), PHP, Python 2, Python 3, 1206 bytes, score 66/1206 = 38.6865671641791

q=1//2;s=+0;s|0;"/.__id__;#";_="""q=1//2;s=+0;s|0;"/.__id__;#";_={0}{1}{0};R=chr((39,34)[1/2>0])*12;Q=chr((39,34)[1/2==0])*3;q={0}{2}{0};print(_.format(Q,_,q[0:-12]+R,"%"))""";R=chr((39,34)[1/2>0])*12;Q=chr((39,34)[1/2==0])*3;q="""|;#<?ob_end_clean();
eval($_='"$t"?0?[$q=37 .chr+113 .chr+38 .chr,$p=(96 .chr+39 .chr)*4,$n=10 .chr,$s=39 .chr*12,$S=34 .chr*3]:eval("printf=console.log;c=String.fromCharCode;$q=c(96);$p=c(37,113,38,39).repeat(4);$n=c(10);$s=c(39).repeat(12);$S=c(34,34,34)"):[]?[$q=q(!g)^PA,$p=HARHARHARHAR^od2od2od2od2,$n=R^X,$s=bbbbbbbbbbbb^EEEEEEEEEEEE,$S=hhh^JJJ]:[$q=O^h,$p=str_repeat(RHa3^w9GS,4),$n=R^X,$s=str_repeat(b^E,12),$S=HHH^jjj];//#');printf($x='q=1//2;s=+0;s|0;"/.__id__;#";_=%7$sq=1//2;s=+0;s|0;"/.__id__;#";_={0}{1}{0};R=chr((39,34)[1/2>0])*12;Q=chr((39,34)[1/2==0])*3;q={0}{2}{0};print(_.format(Q,_,q[0:-12]+R,"%8$s"))%7$s;R=chr((39,34)[1/2>0])*12;Q=chr((39,34)[1/2==0])*3;q=%7$s|;#<?ob_end_clean();%5$seval($_=%3$s%1$s%3$s);printf($x=%3$s%2$s%3$s,$_,$x,$q,$p,$n,$s,$S,"%8$s",![]||([]+[])?$n:"");//#%4$s%6$s%7$s;print(_.format(Q,_,q[0:-12]+R,"%8$s"))%9$s',$_,$x,$q,$p,$n,$s,$S,"%",![]||([]+[])?$n:"");//#`q&%`q&%`q&%`q&%''''''''''''""";print(_.format(Q,_,q[0:-12]+R,"%"))

Validate Perl, Ruby, PHP, Python 2 and Python 3 online!

Note: running the above program in the Inspector console in Chrome (which appears to support positional arguments to console.log) returns the correct program.

Explanation

This turned out a lot longer than I'd hoped and I made my life a little harder too, so I'm likely to keep tinkering with it. I'd like to add in more languages too, but I need to find something that doesn't mind a $ sigil...

This is pretty much a standard quine format where the calculation of the quote to use is a little different for each language: in Ruby %q& is used, PHP uses ', JavaScript (Node.js) makes use of ` and Perl 5 utilises q(...). Because only the quotes change, the rest of the program is still executable and valid syntax in each language. Python 2 and 3 are wrapped around the previous program using """ for Python 2 and ''' for Python 3.

The resultant Perl and Ruby programs aren't standard quines, additional q/%qs are added each iteration, but the first program returns correctly.

The results are:

  • Perl 5:
    eval($_=q&...q&);printf($x=q&...q&,...);//#'%`'%`'%`'%`''''''''''''"""...
  • Ruby:
    eval($_=%q&...%q&);printf($x=%q&...%q&,...);//#`'`'`'`'''''''''''''"""...
  • JavaScript (Chrome):
    eval($_=`...`);printf($x=`...`,...);//#%q&'%q&'%q&'%q&'''''''''''''"""...
  • PHP:
    eval($_='...');printf($x='...',...);//#`q&%`q&%`q&%`q&%''''''''''''"""...
  • Python 2:
    ..._="""...""";...q="""...''''''''''''""";print(_.format(Q,_,q[0:-12]+R,"%"))
  • Python 3:
    ..._='''...''';...q='''...""""""""""""''';print(_.format(Q,_,q[0:-12]+R,"%"))

I've re-worked this a lot, I hope I haven't missed anything key here. I still have quite a way to go to be anywhere near Jo King's score...

Dom Hastings

Posted 2018-04-12T08:59:30.683

Reputation: 16 415

2

Jelly, and M, 26/14 = 4.57

1Ɗṙ@“1Ɗṙ@ȮṾ”ȮṾ

Try it in Jelly!

Try it in M!

Ɗṙ@ȮṾ1“Ɗṙ@ȮṾ1” in Jelly

1Ɗṙ@ȮṾ“1Ɗṙ@ȮṾ” in M

dylnan

Posted 2018-04-12T08:59:30.683

Reputation: 4 993

I'm not sure that the Charcoal one counts as a proper quine – H.PWiz – 2018-04-12T17:13:48.520

@H.PWiz I was about to add a comment saying that. I'll ask OP – dylnan – 2018-04-12T17:15:45.930

@l4m2 do you consider the Charcoal program a proper quine? I will delete if not. – dylnan – 2018-04-12T17:16:22.270

I guess it's like Quine in PHP? – l4m2 – 2018-04-12T17:35:23.347

@l4m2 Not sure, I don't know PHP. It works for most ASCII text I think

– dylnan – 2018-04-12T17:38:54.427

@dylnan Yeah, that's how it works. As far as I remember, commands in charcoal are only unicode characters, but I might be wrong. – RedClover – 2018-04-12T18:13:26.510

@JoKing I've asked OP about Charcoal which is similar and they didn't really say whether it was valid. I'll just remove PHP. – dylnan – 2018-04-12T21:53:21.097

Printable ASCII text is treated as a string literal, and the default command is Print if no other command or function wants the string. – Neil – 2018-04-14T21:34:46.363

@Neil Thanks. I guess that means it's not a quine, right? – dylnan – 2018-04-15T02:36:14.900

There's no code, only data, so no, I don't think it does count as a quine. – Neil – 2018-04-15T08:46:04.423

2

Python 2 and Python 3, 26/61 =1.05

s='s=%r;print(s%%s[::(1/2>0)*2-1])';print(s%s[::(1/2>0)*2-1])

Try it in Python 2!

Try it in Python 3!

Saved 12 bytes thanks to Jo King.

Python 2 prints

s=')]1-2*)0>2/1(::[s%%s(tnirp;r%=s';print(s%s[::(1/2>0)*2-1])

Python 3 prints

s='s=%r;print(s%%s[::(1/2>0)*2-1])';print(s%s[::(1/2>0)*2-1])

This uses the fact that 1/2 is .5 in Python 3 and 0 in Python 2.

dylnan

Posted 2018-04-12T08:59:30.683

Reputation: 4 993

1

Bash/GolfScript, 72 bytes, score 26/72 = 8/9 (~0.888...)

.~0 () 
{ 
    declare "-f" @* ".~0" " ()
 "+@n.;
    echo '.~0;'
}
.~0;

Contains a single trailing space on the first two lines.

Try it online in Bash.
Try it online in GolfScript.

Simply modification of @jimmy23013's answer for the "Write a Polyquine" challenge. The modification that was done was removing the trailing space after the third line, and changing \n"+@n.; to \n "+@n;.

Bash will print lines 1 and 2 like this:

.~0 ()    <- Trailing space
{         <- Trailing space

And GolfScript will print lines 1 and 2 like this:

.~0 ()   <- No trailing space
 {       <- Both leading and trailing space

Here the base program, Bash output, and GolfScript outputs respectively with the new-lines replaced with \n:

.~0 () \n{ \n    declare "-f" @* ".~0" " ()\n "+@n.;\n    echo '.~0;'\n}\n.~0;
.~0 () \n{ \n    declare "-f" @* ".~0" " ()\n "+@n.;\n    echo '.~0;'\n}\n.~0;
.~0 ()\n { \n    declare "-f" @* ".~0" " ()\n "+@n.;\n    echo '.~0;'\n}\n.~0;

      ^^^ Note the difference here

Kevin Cruijssen

Posted 2018-04-12T08:59:30.683

Reputation: 67 575