Rȯ1ĖŒṙ‘Ė’ḣµ;NµN0¦€U;
Ç+;ẋ2W$+⁸<3¤µFṀR,þ$e€€ị⁾# Y
Probieren Sie es online aus!
(Macht es mehr Platz , der von den endgültigen Ersetzen Y
mit G
, um einen Raum zwischen jeder Spalte hinzuzufügen).
Wie?
Erstellt eine Liste der #
Koordinaten eines Arms relativ zur Mitte. Transformiert dies in die Koordinaten der vier Arme von der oberen linken Ecke und fügt die Mittelkoordinate hinzu. Erstellt eine Tabelle mit allen Koordinaten im Raum und setzt die Arme #
und den Raum auf
und verbindet die Zeilen mit Zeilenumbrüchen.
Rȯ1ĖŒṙ‘Ė’ḣµ;NµN0¦€U; - Link 1, arm coordinates relative to centre: arm-length a
R - range: [1,2,...,a]
ȯ1 - or 1 (stops Œṙ erroring with arm-length 0; builds no redundant coordinates in the end)
Ė - enumerate: [[1,1],[2,2],...[a,a]] (or [[1,1]] if a=0)
Œṙ - run-length decode: [1,2,2,...,a,a,...,a] (or [1] if a=0)
‘ - increment: [2,3,3,...,a+1,a+1,...,a+1] (or [2] if a=0)
Ė - enumerate: [[1,2],[2,3],...,[T(a)-a,a+1],[T(a)-a+1,a+1],...,[T(a),a+1]] where T(a)=(a+1)*a/2 (or [[1,2]] if a=0)
’ - decrement: [[0,1],[1,2],...,[T(a)-a-1,a],[T(a)-a,a],...a[T(a)-1),a]] (or [[0,1]] if a=0)
ḣ - head to a (first a of those) - these are an arm's relative coordinates from the central `#` at [0,0])
µ - monadic chain separation (call that list r)
; - r concatenated with
N - negate r (gets the opposite arm)
µ - monadic chain separation (call that list s)
€ - for €ach coordinate pair in s:
0¦ - apply to index 0 (the right of the two values):
N - negate
U - upend (reverse each pair of that, gives the other two arms)
; - concatenate that list with s (gives all four arms)
Ç+;ẋ2W$+⁸<3¤µFṀR,þ$e€€ị⁾# Y - Main link: arm-length a
Ç - call the last link(1) as a monad (get centre-relative coordinates)
+ - add a (make the coordinates relative to the top-left)
$ - last two links as a monad:
ẋ2 - repeat a twice: [a,a]
W - wrap in a list: [[a,a]] (the centre coordinate)
; - concatenate (add the centre coordinate)
¤ - nilad followed by link(s) as a nilad:
⁸ - link's left argument, a
<3 - less than three?
+ - add (a in 0,1,2 are special cases requiring a grid one-by-one more than all the rest)
µ - monadic separation (call that c)
F - flatten c into one list
Ṁ - get the maximum (the side-length of the space)
$ - last two links as a monad:
R - range: [1,2,...,side-length]
,þ - pair table: [[[1,1],[1,2],...,[1,side-length]],[[2,1],[2,2],...,[2,side-length]],...,[[side-length,1],[side-length,2],[side-length, side-length]]]
e€€ - exists in c? for €ach for €ach (1 if a # coordinate, 0 otherwise)
⁾# - literal ['#',' ']
ị - index into
Y - join with new line characters
- implicit print