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:
- Appending spaces to make the input a rectangle.
- 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.
- 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 code-golf, so the shortest answer in bytes wins. Standard loopholes apply, as usual.
-
\$\begingroup\$ Related. \$\endgroup\$Mr. Xcoder– Mr. Xcoder2017年08月22日 18:29:01 +00:00Commented 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– Shelvacu2017年08月23日 05:52:13 +00:00Commented 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\$Martin Ender– Martin Ender2017年08月24日 12:43:01 +00:00Commented Aug 24, 2017 at 12:43
-
\$\begingroup\$ @MartinEnder The answer can mix and match printing the original and printing themselves. \$\endgroup\$fireflame241– fireflame2412017年08月24日 16:08:07 +00:00Commented Aug 24, 2017 at 16:08
4 Answers 4
-
16\$\begingroup\$ ಠ_____________ಠ \$\endgroup\$Mr. Xcoder– Mr. Xcoder2017年08月22日 18:37:56 +00:00Commented 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– L3viathan2017年08月24日 15:08:58 +00:00Commented Aug 24, 2017 at 15:08 -
\$\begingroup\$ @L3viathan then the unfurlings go crazy :/ \$\endgroup\$dzaima– dzaima2017年08月24日 15:44:28 +00:00Commented Aug 24, 2017 at 15:44
-
\$\begingroup\$ @dzaima I see... \$\endgroup\$L3viathan– L3viathan2017年08月24日 15:48:39 +00:00Commented Aug 24, 2017 at 15:48
-
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\$fireflame241– fireflame2412017年08月22日 19:22:48 +00:00Commented 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– Mr. Xcoder2017年08月22日 19:23:54 +00:00Commented Aug 22, 2017 at 19:23
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 _~.