I'll have to come back later and add a separate section explaining how the partition works as it's a difficult one - I'm not sure I fully understand it myself yet! After fixing the bug I now have no idea how or why the partitioning is working!!
ò!Í®n îZèÍg"- ="òìyÈû4 Ôû6'_ :Implicit input of string
ò!Í :Partition into the run length groups we need (See more detailed explanation below)
® :Map each Z
n : Convert to integer (the letter at the end is ignored)
î : Repeat and slice to that length
Zè : Count the occurrences in Z of
Í : "n" (see below for the why)
g : Index into
"- ="ò : Partitions of "- =" of length 2
à :End map
¬ :Join
y :Transpose
È :Pass each row through the following function and transpose back
û4 : Centre pad with spaces to length 4
Ô : Reverse ('cause centre padding is right-biased)
û6'_ : Centre pad with "_" to length 6
OK, I finally (think I) figured out how the partitioning is working! The ò
method partitions string between pairs of characters (X & Y) that return a truthy value when run through the method that's passed as an argument. We're using Í
here, which is the shortcut for n2<space>
. The space is used to close the ò
method and the n
and the 2
being split into two separate arguments, with the second being ignored as ò
only expects one argument. That means that we're currently testing XnY
but, by adding the !
, the elements get flipped giving us YnX
.
The possible combinations we can have (where L=[np]
& D=[0-9]
) are: DnL
, LnD
& DnD
and, in all cases, both elements are strings, which is important. The n
attempts to convert Y to an integer, run X on it as a method and convert it back to a string, with the following possible outcomes:
Dnp
squares the integer resulting in a non-empty string, which is truthy, creating a partition.
Dnn
negates the integer resulting in a non-empty string, which is truthy, creating a partition.
DnD
& LnD
, for some reason that I can't figure out, both result in 0
, which is falsey, so no partition is created.
Hopefully, that all made some sort of sense but, if it helps, here's a handy table.
And, as a final note: the Í
works exactly the same way as above when passed to the è
method, which only expects a single string argument.