6
\$\begingroup\$

Write a proper quine containing at least one newline/linefeed whose every unfurling is either itself a proper quine or outputs the original quine. Your answer can mix and match outputting itself and outputting the original quine.

Unfurlings

Unfurlings consist of:

  1. Appending spaces to make the input a rectangle.
  2. Taking all lines above the bottom one and rotating them a quarter-turn clockwise about the lower-right corner so that the right edge is on the same level as the bottom edge.
  3. Repeat step (2) until the string is a single line to find all unfurlings.

For example, the first unfurling of

GFE
HID
ABC

is

   HG
   IF
ABCDE

and the rest are

   HG
   IF
ABCDE

     IH
ABCDEFG

       I
ABCDEFGH

ABCDEFGHI

This process is automated with this program adapted from Emigna's answer here,where each step of unfurling in the output is delimited by a dashed line.

Example

For example, if you have a program

K
AB

(no trailing spaces)

then it must be a proper quine and print itself('K\nAB', where \n represents a linefeed/newline). According to the output of the unfurling program, we see that the next step in unfurling is

  K
AB 

(note trailing space)

This must either print itself(' K\nAB ') or the original program ('K\nAB'). The next step in the unfurling is

AB K

This must either print itself ('AB K'), or the original program('K\nAB').

The byte-count of this program is 4 (K, \n, A, B).

Score

This is , so the shortest answer in bytes wins. Standard loopholes apply, as usual.

\$\endgroup\$
4
  • \$\begingroup\$ Related. \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 22, 2017 at 18:29
  • \$\begingroup\$ I think you could prevent easy answers by instead unfurling onto a new line instead of the last line of the program. However, I'm not sure the challenge is even possible at that point, but it may be. \$\endgroup\$
    – Shelvacu
    Commented Aug 23, 2017 at 5:52
  • \$\begingroup\$ If our answer has several unfurling steps, do they all have to print the original/themselves, or can some print themselves and some the original? \$\endgroup\$ Commented Aug 24, 2017 at 12:43
  • \$\begingroup\$ @MartinEnder The answer can mix and match printing the original and printing themselves. \$\endgroup\$ Commented Aug 24, 2017 at 16:08

4 Answers 4

10
\$\begingroup\$

Python 3, 48 bytes


_='\n_=%r;print(_%%_,end="")';print(_%_,end="")

Try it online!

I mean, it works :p

\$\endgroup\$
4
  • 16
    \$\begingroup\$ ಠ_____________ಠ \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 22, 2017 at 18:37
  • \$\begingroup\$ Can't you golf this down to just one line, _='_=%r;print(_%%_)';print(_%_) ? It contains "at least one newline/linefeed" (at the end) \$\endgroup\$
    – L3viathan
    Commented Aug 24, 2017 at 15:08
  • \$\begingroup\$ @L3viathan then the unfurlings go crazy :/ \$\endgroup\$
    – dzaima
    Commented Aug 24, 2017 at 15:44
  • \$\begingroup\$ @dzaima I see... \$\endgroup\$
    – L3viathan
    Commented Aug 24, 2017 at 15:48
6
\$\begingroup\$

Python 3, 42 bytes


_='\n_=%r;print(end=_%%_)';print(end=_%_)

Try it online!

\$\endgroup\$
2
  • 7
    \$\begingroup\$ Is this really distinct enough from dzaima's answer to warrant a new one? To me, this seems simply to be golfed a little. \$\endgroup\$ Commented Aug 22, 2017 at 19:22
  • \$\begingroup\$ @fireflame241 I think it deserves its own answer, plus I've written it on my own (not golfed his) \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 22, 2017 at 19:23
4
\$\begingroup\$

Ruby, 32 bytes


_="\n_=%p;print _%%_";print _%_

Try it online!

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

CJam, 11 bytes

OK, let's go with the obvious trivial solution. At least it's shorter than the Python and Ruby solutions that use the same trick.


{N\"_~"}_~

This code begins with a newline, which is ignored by the CJam interpreter. All the actual code is on the last line, which is not changed by the unfurling process. The extra spaces and newlines introduced by unfurling the empty first line are also ignored by the interpreter.

Otherwise this is just a trivial tweak of a (or perhaps the) standard CJam quine. {N\"_~"} defines a code block, _~ makes a copy of it and executes it. Inside the code block, N\ pushes a newline before the copy of the block on the stack and "_~" pushes the string _~ after it. When the program ends, the CJam interpreter automatically prints everything on the stack, i.e. the newline, the code block and the _~.

Try it online!

\$\endgroup\$

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.