Transpose quine

10

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
on
four lines

outputs

 yof
 ono
 u u
 r r
    
 p l
 r i
 o n
 g e
 r s
 a
 m

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.

Luke

Posted 2016-02-16T19:16:42.783

Reputation: 5 091

Does this need to be a true quine? – lirtosiast – 2016-02-16T20:51:58.583

2@ThomasKwa As opposed to? – Martin Ender – 2016-02-16T20:52:30.490

@MartinBüttner Maybe there's a language where literals are echoed transposed. Just in case. – lirtosiast – 2016-02-16T20:53:16.880

@ThomasKwa That's fine as long as it follows all the rules specified. – Luke – 2016-02-16T20:54:33.543

Is the use of external libraries (such as Lodash in Javascript) prohibited? – Mama Fun Roll – 2016-02-17T02:34:42.127

My gut says it's okay as long as you include the necessary code or flags to import the library in your solution, which I think means you'd have to change your Lodash answer a bit. – Luke – 2016-02-17T13:47:21.947

Answers

5

CJam, 14 bytes

{`"_~".+N*}
_~

Test it here.

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

Explanation

{       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.
}_~

Martin Ender

Posted 2016-02-16T19:16:42.783

Reputation: 184 808

10

Fission, 17 bytes

Still my favourite language for quines...

'"
!0
0+
;!
DN
"!

Try it online!

Explanation

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

'!0;D

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:

'!0;D"
"

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

'!0;D"
"0+!N!

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).

Martin Ender

Posted 2016-02-16T19:16:42.783

Reputation: 184 808

3

Stax, 23 bytes

"34bL:f2MMm
"34bL:f2MMm

Try it online!

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

Weijun Zhou

Posted 2016-02-16T19:16:42.783

Reputation: 3 396

3

Javascript ES6, 90 bytes

$=_=>[...(_=`$=${$};$()`.split`
`)[0]].map((x,y)=>_.map(v=>[...
v][y]).join``).join`
`;$()

Not bad, not bad.

Explanation

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.

Mama Fun Roll

Posted 2016-02-16T19:16:42.783

Reputation: 7 234

2

Befunge-93, 57 bytes

^
_^
,@
+,
5*
52
,+
*9
28
+|
9
8#
|!
 ,
##
!:
,^
#
:
^
""

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.

Kevin W.

Posted 2016-02-16T19:16:42.783

Reputation: 763

Could it be shorter to move the quote in the second column to the top like I did in my Fission answer? – Martin Ender – 2016-02-18T12:58:07.760

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 – Kevin W. – 2016-02-18T15:12:43.027

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. – Martin Ender – 2016-02-18T15:14:41.587

1

Python 2, 91 75 69 bytes

s='#%r;print"s#\\n="+"\\n".join(s%%s)';print"s#\n="+"\n".join(s%s)
##

Try it online

Explanation:

This uses a modification of the standard quine:

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

After modification:

s='s=%r;print"\\n".join(s%%s)';print"\n".join(s%s)

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.

mbomb007

Posted 2016-02-16T19:16:42.783

Reputation: 21 944