9
\$\begingroup\$

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.

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

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.
}_~
\$\endgroup\$
9
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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.

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

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.

\$\endgroup\$
  • \$\begingroup\$ Could it be shorter to move the quote in the second column to the top like I did in my Fission answer? \$\endgroup\$ – Martin Ender Feb 18 '16 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. Feb 18 '16 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\$ – Martin Ender Feb 18 '16 at 15:14
0
\$\begingroup\$

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.

\$\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.