V , 54 , 50 byte
¬ ~9ñ9É 11|á
ñ2ñ20lá
ñ$18é 9ñ^y|Ehé
Pf xxywk$hP>ñd
Provalo online!
A differenza del solito, questo programma non contiene caratteri non stampabili.
Spiegazione:
¬ ~ " Insert the entire printable ASCII range
9ñ ñ " 9 times:
9É " Insert 9 spaces at the beginning of this line
11| " Move to the 11'th column on this line
á<CR> " And append a newline after the 11'th column
Ora il buffer è simile al seguente:
!
"#
$%
&'
()
*+
,-
./
01
23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
Ora costruiamo il centro:
2ñ ñ " Two times:
20l " Move 20 characters to the right (because 'l' == 'right', duh)
á<CR> " Append a newline
Ecco dove diventa un po 'strano.
$ " Move to the end of this line
18é " Insert 18 spaces before the last character
9ñ " Repeat the following 9 times:
^ " Move to the first non-whitespace character
y| " Yank all the whitespace before the current character.
" We'll call this the "Leading whitespace register"
E " Move to the end of the current WORD (up to before a space)
h " Move back one character
é<CR> " And insert a newline before the current character
P " Paste the leading whitespace for indentation
f " Move forward to a space
xx " Delete two characters
" (Note how we are inbetween the two bottom branches right now)
yw " Yank everything upto the next branch (all spaces)
" We'll paste this on the line up so that we can yank it again later
" To keep track of how far apart the branches are
k$ " Move up a line and to the end of that line
hP " Move back a character and paste the whitespace we yanked
> " Indent this line by one space
ñ " End the loop
Ecco una nota importante. Il >comando è in realtà un operatore , il che significa che non fa nulla senza un argomento, il testo su cui operare. Per esempio,
>_ "Indent the current line
>> "Indent the current line
>j "Indent the current and next line
>G "Indent every line
Ma poiché questo comando è in un ciclo, possiamo salvare un personaggio non dando un operatore. Alla fine di un ciclo, se un operatore è in sospeso, riempirà _(la riga corrente) come argomento implicitamente.
Ora ammetto che questo ciclo è un po 'strano, e può essere difficile tenere traccia di come dovrebbe apparire tutto il testo in un dato momento. Quindi puoi usare questo programma più semplice per vedere come apparirà dopo N loop.
Se lo imposti su 9, puoi vedere che abbiamo un po 'di testo extra da eliminare. (Solo la riga corrente).
Quindi eliminiamo la riga corrente con dd. Ma aspetta! Sai come ho detto che gli operatori devono prendere una discussione che a volte è implicitamente compilata? Gli argomenti sono anche implicitamente riempiti alla fine del programma. Quindi piuttosto che ddo d_(che sono equivalenti), possiamo semplicemente de lasciare che V compili il testo _per noi.