24
\$\begingroup\$

In this question I asked you to guess an anagram quine based on its output. However it looks like we don't have a question asking to golf an anagram quine yet. So your task will be to make the shortest anagram quine that you can.

What is an anagram quine?

An anagram quine is a non empty program that prints an anagram of its source code, other than its original source.

Here's an example of an anagram quine in Python 2:

print`'`print`*2'*2`

You should not read your own source for this challenge.

\$\endgroup\$
  • 2
    \$\begingroup\$ @LeakyNun No, It can't be a quine. \$\endgroup\$ – Sriotchilism O'Zaic Jun 7 '17 at 17:21
  • 2
    \$\begingroup\$ Does the outputted code have to be a valid program? \$\endgroup\$ – MD XF Jun 7 '17 at 17:43
  • 1
    \$\begingroup\$ @MDXF No it does not. \$\endgroup\$ – Sriotchilism O'Zaic Jun 7 '17 at 18:38
  • 2
    \$\begingroup\$ @Okx It should follow our standard requirements for a quine (other than it being a quine). \$\endgroup\$ – Sriotchilism O'Zaic Jun 7 '17 at 18:39
  • 1
    \$\begingroup\$ @LeakyNun Mind you, I don't think 0-byte programs have anagrams that differ from the original either! \$\endgroup\$ – Neil Jun 7 '17 at 19:52

38 Answers 38

29
\$\begingroup\$

Pyth, 2 bytes

)(

Outputs

()

Try it online!

)  # Ends statement, does nothing in this program
 ( # Create an empty tuple
   # Implicitly print the empty tuple
\$\endgroup\$
  • 3
    \$\begingroup\$ Does that mean that you discovered that () is a quine much shorter than the well known jN*2]"jN*2]? \$\endgroup\$ – Jim Jun 8 '17 at 8:24
  • 1
    \$\begingroup\$ @Jim no, because this isn't payload-capable :c \$\endgroup\$ – Rod Jun 8 '17 at 11:07
9
\$\begingroup\$

V, 4 bytes

2ii2

Outputs:

i2i2

Try it online!

\$\endgroup\$
  • \$\begingroup\$ 2x insert i2? \$\endgroup\$ – CalculatorFeline Jun 7 '17 at 19:06
  • 1
    \$\begingroup\$ Yep. 2 -> do the next thing twice i -> insert the following \$\endgroup\$ – Riley Jun 7 '17 at 19:07
  • \$\begingroup\$ Ah I see, I thought this was Vim. \$\endgroup\$ – Sriotchilism O'Zaic Jun 7 '17 at 19:35
  • \$\begingroup\$ @WheatWizard Nope, this is a trivial modification of the standard V quine. \$\endgroup\$ – Riley Jun 7 '17 at 19:47
  • 1
    \$\begingroup\$ @isaacg: no, in Vim you'd need to press ESC once you were finished, which is a problem because there's no ESC character in the output. \$\endgroup\$ – user62131 Jun 8 '17 at 0:04
9
\$\begingroup\$

><>, 9 8 7 bytes

Golfed 1 byte thanks to @WheatWizard by using ! and incrementing it to get "

Golfed 1 byte thanks to @ConorO'Brien by using # instead of <!

":1->o#

Try it online!

Outputs "#o>-1:.

Explanation

":1->o#"        Push this string (note that the IP wraps around)
:               Duplicate the top value of the stack (35 from the "#")
1-              Subtract one from it to get 34 ('"')
>o#             Print every character on the stack until the program cannot pop any more and still tries to pop a value from the stack afterwards
                The program exits with an error from not being able to pop a value from an empty stack
\$\endgroup\$
  • \$\begingroup\$ ":1+>o<! is a bit shorter. \$\endgroup\$ – Sriotchilism O'Zaic Jun 7 '17 at 17:32
  • \$\begingroup\$ @WheatWizard Thanks, that was a neat golf :) \$\endgroup\$ – Kritixi Lithos Jun 7 '17 at 17:33
  • 1
    \$\begingroup\$ You can get 7 bytes: ":1->o# \$\endgroup\$ – Conor O'Brien Jun 7 '17 at 19:02
  • \$\begingroup\$ @ConorO'Brien Thanks for the tip, that is really clever. \$\endgroup\$ – Kritixi Lithos Jun 7 '17 at 19:04
  • \$\begingroup\$ Thanks :) I'm pleasantly surprised that it works better here than in the actual quine \$\endgroup\$ – Conor O'Brien Jun 7 '17 at 19:13
9
\$\begingroup\$

Brainfuck, 158 bytes

>>--<<-[[<+>->+>->+++<<<]>-]<<<<<<[--->>.<<]>>++<<<[->>>.<<<]>>-<<<[--->>>.<<<]>>>--<<<<[++>>>>.<<<<]>>>>+++>--.[---<.>]>+.......++.......<<<>>>>>>>>>-----+++

Try it online!

It may not be the shortest version, but at least it works.

Fun fact, the output code can actually be executed (and it does terminate).

Output

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>--------------------------++++++++++++++++++<....................[[[[[[[]]]]]]]

Explanation

>>--<<-[[<+>->+>->+++<<<]>-]    Initializes the tape with the
                                help of a recurrence relation.
<<<<<<[--->>.<<]>>++<<<[->>>
.<<<]>>-<<<[--->>>.<<<]>>>--    Prints the characters using
<<<<[++>>>>.<<<<]>>>>+++>--.    classic loops.
[---<.>]>+.......++.......

<<<>>>>>>>>>-----+++            Junk to complete the anagram.
\$\endgroup\$
8
\$\begingroup\$

Python 3, 32 bytes

print("""p"r"i"n"t"2(")*"""*2)

Prints p"r"i"n"t"2(")*p"r"i"n"t"2(")*\n, sorted output: \n""""""""""""(())**22iinnpprrtt

\$\endgroup\$
  • \$\begingroup\$ Oops, old version :( \$\endgroup\$ – CalculatorFeline Jun 7 '17 at 20:20
  • 1
    \$\begingroup\$ @Downvoter Please undownvote. \$\endgroup\$ – CalculatorFeline Jun 7 '17 at 20:22
7
\$\begingroup\$

Ruby, 8 bytes

p"p*2"*2

Try it online!

This prints

"p*2p*2"

Explanation

This works similar to the python answer in the question. It will make the string p*2p*2 then using Ruby's p will print the representation of the string.

\$\endgroup\$
  • \$\begingroup\$ You can use p instead of puts?! So much wasted time... \$\endgroup\$ – Magic Octopus Urn Jun 7 '17 at 20:32
  • 4
    \$\begingroup\$ @carusocomputing It's not precisely the same thing as puts. p x is equivalent to puts x.inspect \$\endgroup\$ – Conor O'Brien Jun 7 '17 at 20:34
6
\$\begingroup\$

JavaScript (ES6), 40 32 bytes

f=($=`($)=>{$=$+"${"``"}$"}`)=>$+$

No messing around with Function.toString either. As a bonus, the code inside the string almost looks legal. Edit: Saved 8 bytes by using + instead of repeat(2).

\$\endgroup\$
  • 1
    \$\begingroup\$ Why not use *2 instead of .repeat(2), does that not work? \$\endgroup\$ – Magic Octopus Urn Jun 7 '17 at 20:08
  • 1
    \$\begingroup\$ @carusocomputing JavaScript does not overload * for strings \$\endgroup\$ – Conor O'Brien Jun 7 '17 at 20:09
  • 1
    \$\begingroup\$ @carusocomputing That gave me an idea, thanks! \$\endgroup\$ – Neil Jun 8 '17 at 8:11
4
\$\begingroup\$

Klein, 7 + 6 = 13 bytes

Here's an answer based on the ><> answer.

":1+@!

Try it online!

This outputs

:1+@!"

\$\endgroup\$
4
\$\begingroup\$

Japt, 10 9 bytes

Found a better way :-)

Q+2ç"Q+2ç

Outputs "Q+2çQ+2ç. Test it online!

Explanation

Q+2ç"Q+2ç    // Implicit: Q = quotation mark
    "Q+2ç    // Take this string.     Q+2ç
  2ç         // Repeat it twice.      Q+2çQ+2ç
Q+           // Prepend a quote.      "Q+2çQ+2ç
             // Implicit: output result of last expression

Could also be Qi2ç"Qi2ç, which prints Qi2çQi2ç". This one is closer to the standard Japt quine:

"iQ ²"iQ ²

But I do not believe there is any easy way to wedge the quotation mark in the middle of the string for a 9-byte quine.

\$\endgroup\$
  • \$\begingroup\$ Another 10-byter: Q+"+Q² " ² \$\endgroup\$ – Conor O'Brien Jun 7 '17 at 20:33
  • \$\begingroup\$ @ConorO'Brien Yep, and you can always arrange the 4 chars inside the string in each of the 24 possible permutations. Also I believe you can always replace both spaces with newlines \$\endgroup\$ – ETHproductions Jun 7 '17 at 20:39
3
\$\begingroup\$

Ruby, 20 bytes

$><<%q($><<%q()*2)*2

This outputs

$><<%q()*2$><<%q()*2

Taking advantage of Ruby's %q(...) string syntax, which supports nested parentheses.

\$\endgroup\$
3
\$\begingroup\$

Retina, 8 bytes


_

$nn$

Try it online!

Prints


n$_
n$

Both contain one _, two n, two $ and three linefeeds.

Note that a linefeed followed by almost any other character is a trivial solution, but it's questionable whether it's valid, because the second character only encodes itself and the linefeed doesn't really encode either output character.

Explanation


_

Replace the empty input with a _.


$nn$

Match an empty string, which happens both before or after the _ and insert a linefeed ($n), an n, and a $. Since we first inserted that _, this adds each of those characters twice, so the n and $ account for the $n, and we get two of the three linefeeds we need in the output. The third linefeed is printed because Retina prints a trailing linefeed by default.

We could also use n$n$ in this stage, which would then print:

n
$_n
$

\$\endgroup\$
3
\$\begingroup\$

Python Repl, 4 bytes

This is my first Code Golf solution, so I hope it meets the rules. In the Python 2 or 3 interactive interpreter:

>>> (1),
(1,)

The output is an anagram of the input.


Another:

>>> 2*'2*'
'2*2*'

In Python 2:

>>> type('rst <>'),
(<type 'str'>,)

In Python 3:

>> {1, 0}
{0, 1}

Update 2017-06-15: Yet another:

>>> 01.
1.0
\$\endgroup\$
  • 1
    \$\begingroup\$ I think the last answer here violates the quine rules (all the characters in the output serve the same purpose as the matching character in the input). The others are fine, though. \$\endgroup\$ – user62131 Jun 14 '17 at 22:04
2
\$\begingroup\$

Haskell, 38 39 bytes

main=print$[0,0]>>"main=print$[0,0]>>"

Try it online! Output:

"main=print$[0,0]>>main=print$[0,0]>>"

Edit: +1 byte because I previously forgot about the implicit trailing newline of print.


Alternative: (Same byte count but does not contain ASCII-owl)

main=print$e++e;e="main=print$e++e;e="

Try it online!

Output:

"main=print$e++e;e=main=print$e++e;e="

\$\endgroup\$
  • \$\begingroup\$ Just barely an anagram quine rather than a true quine.... \$\endgroup\$ – Feathercrown Jun 8 '17 at 14:16
2
\$\begingroup\$

Groovy, 24 20 bytes

{"""{""*""2""}"""*2}

-4 thanks to CalculatorFeline, the whitespace wasn't needed after all!

Output:

{""*""2""}{""*""2""}

Explanation:

Anonymous closure that, when called, returns {""*""2""} two times (concatenated).

\$\endgroup\$
  • 1
    \$\begingroup\$ Explanation please. Also, bytes can (probably) be saved by using the *2 as padding between quotes: {"""{""*""2""}"""*2} \$\endgroup\$ – CalculatorFeline Jun 7 '17 at 20:25
  • \$\begingroup\$ @CalculatorFeline it's pretty self explanatory. But yes, that is a <s>100%</s> 9% better idea than mine. \$\endgroup\$ – Magic Octopus Urn Jun 7 '17 at 20:28
  • 3
    \$\begingroup\$ Actually, it's only 9% better :P \$\endgroup\$ – CalculatorFeline Jun 7 '17 at 20:29
2
\$\begingroup\$

05AB1E, 10 bytes

'∞∞''∞'JJ∞

Try it online!

Output:

∞∞''JJ''∞∞

Explanation:

Code       | Explanation                | Stack
-----------+----------------------------+-------------------
'∞         | Push literal '∞'.          | ["∞"]
  ∞        | Mirror.                    | ["∞∞"]
   ''      | Push literal "'".          | ["∞∞","'"]
     ∞     | Mirror.                    | ["∞∞","''"]
      'J   | Push literal 'J'.          | ["∞∞","''","J"]
        J  | Join it all together.      | ["∞∞''J"]
         ∞ | Mirror.                    | ["∞∞''JJ''∞∞"]
-----------+----------------------------+-------------------
           | Implicit print.            | ∞∞''JJ''∞∞
\$\endgroup\$
2
\$\begingroup\$

CJam, 6 bytes

"_`"_`

Try it online!

Prints

_`"_`"

Explanation

"_`"   e# Push this string.
_      e# Duplicate.
`      e# Stringify it, which wraps it in quotes.
       e# Implicitly print stack contents.
\$\endgroup\$
  • \$\begingroup\$ I was about to post this... "`_"_` also works \$\endgroup\$ – Luis Mendo Jun 7 '17 at 23:07
1
\$\begingroup\$

Bash, 36 bytes

tee f<<<'tee f<<<""cat f'"''"
cat f

This outputs

tee f<<<""cat f''
tee f<<<""cat f''

(and creates the file f as a side effect, but that's allowed per meta.)

Both the program and output have a trailing newline.

Thought process: I figured that the easiest way to output a string two times, aside from assigning it to a variable, was to do

tee f<<<string
cat f

The string needs to be quoted because it will contain spaces and < characters, so then I had

tee f<<<'tee f<<<cat f'
cat f

which almost works, except it doesn't output the quotes. Fortunately, Bash supports string literal concatenation by simply placing them next to each other, so appending "''" to the herestring and inserting "" inside the single quote part yields this solution.

\$\endgroup\$
1
\$\begingroup\$

PHP, 44 bytes

<?=str_repeat('<?=\str_\repeat(\'\',2);',2);

Try it online!

\$\endgroup\$
1
\$\begingroup\$

CJam, 8 bytes

"2*`"2*`

Try it online!

Explanation

Similar to the Python example in the question

"2*`"     e# Push the string "2*`"
     2*   e# Repeat it twice
       `  e# Get its string representation (wrap in quotes)

The output is "2*`2*`".

\$\endgroup\$
1
\$\begingroup\$

Befunge, 11 bytes

' 2+">:#,_@

Prints:

+2 '@_,#:>"

Explanation:

' 2+"        Put a " on the stack (32 + 2)
    "        Put the rest of the code on stack (wrap-around string)
     >:#,_   Print stack
          @  End
\$\endgroup\$
  • \$\begingroup\$ Yes. but so does ". What is the restriction on that exactly? \$\endgroup\$ – MegaTom Jun 7 '17 at 19:07
  • \$\begingroup\$ I don't think that " is considered reading ones own source, its just a string literal. g however is pretty blatantly reading its own source. \$\endgroup\$ – Sriotchilism O'Zaic Jun 7 '17 at 19:09
  • \$\begingroup\$ @WheatWizard okay. I will change it. \$\endgroup\$ – MegaTom Jun 7 '17 at 19:09
  • \$\begingroup\$ ":1+>:#,_@! also works but its not shorter. \$\endgroup\$ – Sriotchilism O'Zaic Jun 7 '17 at 19:15
  • \$\begingroup\$ ' 2+"8k,@ for 9 bytes \$\endgroup\$ – ovs Jun 7 '17 at 20:30
1
\$\begingroup\$

QBIC, 8 bytes

?A+@?A@+

I just figured out how to do a proper quine in QBIC. Making an anagram out of it is done by simply switching around the characters in the string literal. There are 24 possible anagrams this way.

\$\endgroup\$
1
\$\begingroup\$

Befunge-98, 8 bytes

"'$<@,k7

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Ohm, 14 bytes

"æ3M.Cæ"æ3M."C

Try it online!

Output:

æ3M.CæC.M3æ"""

Explanation

"æ3M.Cæ"æ3M."C
"æ3M.Cæ"       # Pushes "æ3M.Cæ"
        æ      # Palindrone of that string
         3M    # 3 times...
           ."   # Push " on the stack
             C  # Concatenate with the string above
\$\endgroup\$
1
\$\begingroup\$

JavaScript (ES6), 15 bytes

f=(s='f=')=>f+s

Outputs:

(s='f=')=>f+sf= 

Snippet:

f=(s='f=')=>f+s

console.log(f());

\$\endgroup\$
1
\$\begingroup\$

Fission 2, 9 8 6 bytes

R"'!+O

Try it online!

Explanation

An atom is created at R, which moves right. This atom then comes across a ", which starts printing mode. In printing mode, all characters (until the matching ") are printed. This means it prints '!+OR in this case. Then, all that is left is printing ", which is done by the remaining characters. '! sets the atom's mass to the character code of !, and + increments it to the character code of ". Then, the character code is output by O and the atom is destroyed, ending the program.

(Actually, this is just a rotation of the shortest quine)

\$\endgroup\$
  • \$\begingroup\$ I believe you can just use the standard quine and shift it cyclically (so something like R"'!+O, untested). \$\endgroup\$ – Martin Ender Jun 7 '17 at 21:03
  • \$\begingroup\$ @MartinEnder: you're right. Updated. Thanks for helping. \$\endgroup\$ – Luke Jun 8 '17 at 4:41
1
\$\begingroup\$

Mathematica, 2 bytes

.0

Output:

0.

A number starting with a decimal point such as .123 is interpreted as 0.123, so .0 is interpreted as 0.0. Since the part of the number after the decimal point is zero, Mathematica does not print it.

\$\endgroup\$
  • 1
    \$\begingroup\$ I don't think this is valid. Our site definition requires that quines have an "encoder" and a "decoder", this bans literal only type quines. \$\endgroup\$ – Sriotchilism O'Zaic Jun 8 '17 at 14:52
  • \$\begingroup\$ All the rules for quines carry over to this challenge. \$\endgroup\$ – Sriotchilism O'Zaic Jun 11 '17 at 19:15
  • \$\begingroup\$ @WheatWizard: The . encodes itself, but I don't think the 0 does? A 0 beyond the decimal point can't sanely be seen as encoding a leading zero before the decimal point, the latter's a side effect of printing a float. So under the old quine rules, there's no problem here. (I'm not sure whether the new rules have come into force yet.) \$\endgroup\$ – user62131 Jun 14 '17 at 22:06
  • \$\begingroup\$ @ais523 I don't know. Perhaps this should be addressed by a meta question. \$\endgroup\$ – Sriotchilism O'Zaic Jun 14 '17 at 22:12
1
\$\begingroup\$

JavaScript (yet another one), 11 bytes

f=_=>'=f'+f

Called with f(), outputs

=f_=>'=f'+f

f=_=>'=f'+f

console.log(f());

\$\endgroup\$
1
\$\begingroup\$

Python 3, 31 bytes

a='a=%r;pritn(a%%a)';print(a%a)
\$\endgroup\$
1
\$\begingroup\$

Stax, 8 4 bytes

.S.S

Run and debug online!

A direct port of this answer.

Old version, 8 bytes

..b..LbL

Run and debug online!

Alternative version with a pretty cheap trick that can be applied to proper quines in almost any language.

"43bL"34bL

Run and debug online!

Because "34bL"34bL is a proper quine in Stax.

Yet another version, using only single-char string literals.

''c'Lc'cccLcLL

Run and debug online!

Explanation

.S.S        Generates powerset ["","S","S.","."]
            Implicit flatten and output

..b         Push string ".b"
   ..L      Push string ".L"
      b     Duplicate both strings
       L    Concatenate all 4 strings to a single one.
\$\endgroup\$
0
\$\begingroup\$

05AB1E, 13 bytes

"34çJ∞"34çJ∞

Outputs:

34çJ∞""∞Jç43

Try it online!

"34çJ∞"      # Push this string                 | [ 34çJ∞ ]
       34ç   # Push a quote (")                 | [ 34çJ∞, " ]
          J  # Join                             | [ 34çJ∞" ]
           ∞ # Mirror                           | [ 34çJ∞""∞Jç43 ]
             # Implicitly output with a newline
\$\endgroup\$

Your Answer

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

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