2012 - Element Element
_+n;n~'[[3_+'[y~1+y;0[1+4:?!y~=|1+2"2:n~=|[N]![\'=1=|y~=|\ ]`"#]\[#N]`"#]\
`y~1+y;0]`]
Here, you will witness some stack manipulation. To make the explanation a little easier to format, I'll replace the newline with an L
and the space with an S
.
_+n;n~'[[3_+'[y~1+y;0[1+4:?!y~=|1+2"2:n~=|[N]![\ ]`"#]\L`y~1+y;0]'=1=|y~=|\S[#N]`"#]\L`]
_+n;_+' input ainput line, make sure it's in number format with "+"convert andto store#, itmove into nc-stack
n~'[ [ use this number to control a FOR loop
[ y~1+y; increment the y-pos
0 another FOR loop. We carefullyset makethe surex-pos that(the ntop remains# on top of the c-stack
3:) to zero
[ duplicate the top (maybeFOR empty)loop
item of1+4: the stack, ourincrement Xx-pos position,and make 3 times.additional copies (4 is total #)
?! "2:' make a ifcopy it'sof equalthe toN zerosize oron undefinedthe main stack
y~=| = or it's equal toif thex-pos Y== positionsize
1+2:n~=| or it's1= equal to n once incrementedor (duplicatingif savesx-pos it== for1
next iteration)
[N]y~=| of if x-pos push== Ny-pos
![\ ] \S else (always) push a space
` [ output whatever wasthe justIF pushed
"#body (technically a FOR loop)
discard#N the test results soif thattrue, nremove remainsthe onspace topand ofpush thean c-stackN
] ] end the X position FOR loopIF
\L` ` print a newline, butoutput the Lpushed shouldcharacter
be an"# actual newline
y~1+y; incrementremove the Y position
0result of the conditional
] put zero as the topend itemx-pos onFOR
the\L` stack, this is our resetoutput Xa positionnewline
] end the Y positiony-pos FOR loop