Turn Your Program into a Snake!

3

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

Steadybox

Posted 2018-02-22T19:01:42.760

Reputation: 15 798

Question was closed 2018-02-22T19:22:18.967

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. – FryAmTheEggman – 2018-02-22T19:04:38.237

@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. – Steadybox – 2018-02-22T19:08:27.227

3

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.

– Martin Ender – 2018-02-22T19:10:48.357

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? – FryAmTheEggman – 2018-02-22T19:13:07.167

@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. – Conor O'Brien – 2018-02-22T19:13:22.783

@MartinEnder Yeah, perhaps this should be closed. Had I not sandboxed this before posting, the horizontal snake would have been a duplicate of this. – Steadybox – 2018-02-22T19:14:16.097

@FryAmTheEggman The x does not refer to any absolute line, but a starting line relative to which the other lines are added. x+n is the first line of output, where n means how many lines above the starting line the highest part of the snake is. – Steadybox – 2018-02-22T19:17:41.673

@MartinEnder I fully agree, although not to the point where I'd use my hammer. – Erik the Outgolfer – 2018-02-22T19:18:58.097

@Steadybox That is indeed unfortunate, but my main point is that even without the other challenge this would have been better as just "given a string, turn it into a random horizontal snake". – Martin Ender – 2018-02-22T19:19:00.580

@MartinEnder Yeah, I guess so. I considered that version of this, but thought the quine thing might be more interesting. – Steadybox – 2018-02-22T19:26:32.393

@Steadybox The reason it's not interesting is simply that most quines are of the separated code and data form, with only a little bit being the "glue" between the two, for example the Python 2 quine s='s=%r;print s%%s';print s%s. – Erik the Outgolfer – 2018-02-22T19:28:15.730

@EriktheOutgolfer Yes, I didn't quite think it through far enough. – Steadybox – 2018-02-22T19:31:17.087

Answers

4

05AB1E, 47 bytes

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

Try it online!

Emigna

Posted 2018-02-22T19:01:42.760

Reputation: 50 798