An explanation will follow based on following semi-golfed 148 byte version. This better showsBecause the interesting part of this answer is wrapping it in the blocksV
shape, here is an explanation that conforms to it is composed of. We use following line-numbered version for reference.
1. l:2*01p84*>2*01 $ p84*/v
2. !@:$-1 /!?v~~v:$<
3. ~ 1.v/ ^ v\~~>a
4. ;vv\}o< ^>ao /
5. @ 1\/84/ :}o:$-1</ <
6. v^ \\!?<: l;!?\v
7. p10-1:g10rg10r\
8. <oa <
\ l>> :>?!v1\vv
9. v:$-\1/~
10. </r+*
11. }o :$\ </~
12. \ }o l
Sometimes arrows (→↓←) are used to indicate the direction in which a snippet is reached.
Initialisation
1.→l:2*01 p84*/v 2. !@:$-1 X /!?:$< 3. 1. \~~>a
The first line will push 2n to [0,1], leave n on the stack and append one space. Next, we go up and wrap around to the second line on the right, where we will start going left. There is a loop for appending n + 1 spaces. This works as follows.
Initial: "ppcg4 "
!@:$-1 /84*r~l>!?:$<
$ Swap. "ppcg 4"
: Duplicate. "ppcg 44"
?!v1 If more spaces to add:
-/1 Subtract 1. "ppcg 3"
$ \~ Swap. "ppcg3 "
: Duplicate. "ppcg3 "
@ Rotate top 3. "ppcg 3 "
! Jump over stored value
and wrap around.
Else:
/ Go to next part.
Coming soon! After this is finished, it bounces down to line 3. There the top two stack elements (0 and a space) are removed (~~
) and we jump to the X
at location [10,1] (a1.
), continuing rightwards. We bump up at the /
, wrap around to line 7 and start the main program loop.
Main loop (2n times do)
6. ;!?\ 7. p10-1:g10r\ ←
This is the loop condition. At first, the stack is reversed for printing. Then we get the counter from [1,0] (01g
) and store a decremented version (:1-01p
). By wrapping around and bumping up and right, we encounter the conditional for terminating the program. If we don't terminate, we jump into the first printing loop.
First printing loop (left half)
5. 1\ / :}o:$- 6. \\!?<: l ← We start with the length on top of the stack and execute the following code as long as the top element is not 0. 1-$:o} 1- Subtract 1. "ppcg3" $ Swap. "ppc3g" : Duplicate. "ppc3gg" o Output. "ppc3g" } Rotate right. "gppc3" This will print the stack without discarding it. If the loop terminates, we jump to the right on line 5, preparing for the next printing loop.
Preparation of right half
5. → /84/ 6. \ 7. : 8. > 9. v:$-1/~ 10. </r+* 11. </~ 12. l This was one of the hardest parts to fit. Below is a version stripped of all direction wrapping to indicate what happens. Initial stack: " gcpp0" 84*+r~ 84* Push 32 == " ". " gcpp0 " + Add 32 and 0. " gcpp " r Reverse. " gcpp " ~ Remove top. " gcpp " We then push the length of what is to be printed and start the second printing loop (with an initial duplicate not part of the loop).
Second printing loop (right half)
3. / ^ 4. \}o< 5. 6. ↓ 7. 8. > :>?\vv 9. v:$-1/~ The code being executed is completely the same as in the first printing loop, with the `o}` being placed a bit further because there were available locations. Upon finishing, we have a few things left to do before we can verify the main loop invariant again. After the `~` on line 9 is executed we wrap around vertically, ending up at the following piece of code. ↓ 2. X / 3. 1.v/ >a 4. >ao / First `ao` will print a newline. Then we bounce up and arrive at exactly the same spot from after the initialisation, namely jumping to the `X`.