In this quine variant, your program must output its source code transposed across the diagonal from the top left to the bottom right. For example:

your program
four lines


 u u
 r r
 p l
 r i
 o n
 g e
 r s

The whitespace in the output is not arbitrary. Spaces appear in two situations: where there is a space in the original (e.g. between r and l in the fourth column) and where it's necessary to pad characters (e.g. all the spaces in the first column.) Both are required, and spaces cannot appear anywhere else in the output.

A single trailing newline in the output can optionally be ignored. Trailing newlines in the source code have no effect on the output, and leading newlines in the source code must be handled as in the example above. Assume that every character that is not a newline is one column wide and one row tall, even though for characters like tab this may lead to an ugly output.

Your solution must have at least two lines with at least two non-newline characters each, and must not be its own transpose (the output cannot be identical to the source.)

Cheating quines that read from the file that contains their source code, pull data from a URL, use quining built-ins, and so on are not permitted.

This is code golf: shortest code in bytes wins.

  • \$\begingroup\$ Does this need to be a true quine? \$\endgroup\$
    – lirtosiast
    Commented Feb 16, 2016 at 20:51
  • 2
    \$\begingroup\$ @ThomasKwa As opposed to? \$\endgroup\$ Commented Feb 16, 2016 at 20:52
  • \$\begingroup\$ @MartinBüttner Maybe there's a language where literals are echoed transposed. Just in case. \$\endgroup\$
    – lirtosiast
    Commented Feb 16, 2016 at 20:53
  • \$\begingroup\$ @ThomasKwa That's fine as long as it follows all the rules specified. \$\endgroup\$
    – Luke
    Commented Feb 16, 2016 at 20:54
  • \$\begingroup\$ Is the use of external libraries (such as Lodash in Javascript) prohibited? \$\endgroup\$ Commented Feb 17, 2016 at 2:34

6 Answers 6


Fission, 17 bytes

Still my favourite language for quines...


Try it online!


This quite similar to the basic Fission quine. In fact, if it wasn't for the "must have at least two lines with at least two non-newline characters each" rule, I simply could have transposed that and replace R with D. That rule makes things a bit more interesting though, because we need to print another line.

Control flow starts at the D with a single atom going south. Since it hits the " it will wrap around and print


to STDOUT, similar to how it would in the normal quine. '! then sets the atom's mass to the character code of !. The 0 is a teleporter which transports the atom to the second column, where it's still moving south.

With + we increment the atom's mass to the value of ". !N! the prints quote, linefeed, quote. STDOUT now looks like this:


After wrapping around, the atom hits another " and now prints the second line verbatim:


We're done now. The atom uses the teleporter once again, and lands in the ; which destroys it and thereby terminates the program.

I suppose the neatest bit here is putting one " at the bottom and the other at the top so that I can print them in one go without having to set the value of ! once more (because it would get overwritten by entering string mode again).


CJam, 14 bytes


Test it here.

While shorter, probably a bit less interesting than the Fission solution.


{       e# Quine framework. Runs the block while another copy of it is on the stack.
  `     e# Stringify the block.
  "_~"  e# Push the remaining code as a string.
  .+    e# Element-wise append... essentially puts the two strings in a grid and 
        e# transposes it.
  N*    e# Join with linefeeds.

Javascript ES6, 90 bytes


Not bad, not bad.


Here's the standard quine framework:


To modify, I just split the quine string along newlines and chars to create a matrix of chars, transposed using 2 map functions, and joined to create the output.


Stax, 23 bytes


Try it online!

Adaptation of the "34bL"34bL quine, which is based on an idea used in quines in many languages.


Befunge-93, 57 bytes


This works by putting each character in the first column on the stack (except the quote itself), then printing each item off of the stack. After that, it prints the quote, prints a newline, and then moves over to the second column. It does the same thing sans print a newline.

You can test it in the link in the title, but you'll need to copy-paste the code into the window yourself. If you hit the 'slow' button, it will show you the path the pointer takes and the stack at the time.

  • \$\begingroup\$ Could it be shorter to move the quote in the second column to the top like I did in my Fission answer? \$\endgroup\$ Commented Feb 18, 2016 at 12:58
  • \$\begingroup\$ I can move the quote to the top and rearrange the second column and have it still work, but it ends up still being 57 bytes since the first column still has to be the same height \$\endgroup\$
    – Kevin W.
    Commented Feb 18, 2016 at 15:12
  • \$\begingroup\$ Hm okay, I figured it might allow you to generate the " only once, so that you could shift some code from the first column to the second. \$\endgroup\$ Commented Feb 18, 2016 at 15:14

Python 2, 91 75 69 bytes


Try it online


This uses a modification of the standard quine:

s='s=%r;print s%%s';print s%s

After modification:


This would be enough if a single line was allowed. Then, I added two characters to the 2nd line to fulfill that requirement. The # chars on the second line can be replaced with anything, so long as you change them in the first line, too, and it makes the program syntactically valid.

To print it correctly now, I have to print # at the end of the first two lines. So I remove the first two characters from the string s, and print those with # before printing s%s. I put one of the # at the start of s to save some bytes by removing a newline literal.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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