3
\$\begingroup\$

This question already has an answer here:

...or "snakes but not too long".

Inspired by this challenge and this comment.

Task

Write a program or a function that takes no input and outputs its own source code formatted as a snake according to the rules below:

  1. If your code has any whitespace, it will not be output; it will just be skipped.
  2. There will be one character on each column in the output.
  3. The first character in the code is placed on the first column of line x.
  4. The second character is placed on the second column of either line x, x-1, or x+1. More generally, the nth character (excluding whitespace) goes to the nth column on a line that is one above, one below, or the same as the line on which the previous character went.
  5. The character on the highest line will be on the first line in the output; that is, there are no extraneous leading lines. A single, empty trailing line is allowed.

For example, if the code was from python import snake, the output should look like:

      th
     y  o       s  ke
f  mp    ni po t na
 ro        m  r

or

                    e
                   k
f                 a
 r               n
  om    o im    s
    p  h n  po t
     yt       r

All valid forms of snake should have a nonzero probability of occurring. Your program's source code should contain at least two non-whitespace characters.

This is , so the shortest answer in bytes wins.

\$\endgroup\$

marked as duplicate by Steadybox code-golf Feb 22 '18 at 19:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ I assume the initial choice of x should also be random? You might want to clarify that a bit in the initial rules - I don't think you say anything about it until almost the very end. \$\endgroup\$ – FryAmTheEggman Feb 22 '18 at 19:04
  • \$\begingroup\$ @FryAmTheEggman Actually the x depends on the sequence of random numbers on each step. For example, if no character goes on a line above line x, then x is the first line. If characters go at most two lines above x, x will be the third line. \$\endgroup\$ – Steadybox Feb 22 '18 at 19:08
  • 3
    \$\begingroup\$ I'm tempted to close this as a dupe of the horizontal ASCII snake challenge. This is the kind of generalised quine which can only be solved by a) obtaining a string representation of your code, and b) slapping the string processing task on top of that. There's really no way avoid the generic payload capable quine or to make the quine part save anything on the basic string processing task, so replacing the input with the source code doesn't really add much to the problem, I'm afraid. \$\endgroup\$ – Martin Ender Feb 22 '18 at 19:10
  • \$\begingroup\$ I'm sorry, but I don't understand what you are saying at all (or where it appears in your question body). Could you try to explain again what row the first character should appear on? Currently I agree with Martin, but if the placement lets you control something of the output then maybe this will be more than just a generalised quine? \$\endgroup\$ – FryAmTheEggman Feb 22 '18 at 19:13
  • \$\begingroup\$ @MartinEnder I could see a program which generates the quine character-by-character (e.g. the standard data--decompresser quine) do both the generation and the special output simultaneously. Outside of that, I think you are correct. \$\endgroup\$ – Conor O'Brien Feb 22 '18 at 19:13
4
\$\begingroup\$

05AB1E, 47 bytes

4"D34çýSDεXD<X>ŸΩU}W-úζ»"D34çýSDεXD<X>ŸΩU}W-úζ»

Try it online!

\$\endgroup\$

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