Skip to main content
added 166 characters in body
Source Link
PhiNotPi
  • 29.1k
  • 10
  • 85
  • 157

After doing some extreme golfing of this answer, I found a 39 byte solution, although it is much more complicated.

_'1[y~+y;[#1+3:"2:'%2<y~=|\ [#N]`"]\
`]

After doing some extreme golfing of this answer, I found a 39 byte solution, although it is much more complicated.

_'1[y~+y;[#1+3:"2:'%2<y~=|\ [#N]`"]\
`]
deleted 138 characters in body
Source Link
PhiNotPi
  • 29.1k
  • 10
  • 85
  • 157

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

2012 - Element

_+n;n~'[[3:?!y~=|1+2:n~=|[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.

_+n;n~'[[3:?!y~=|1+2:n~=|[N]![\ ]`"#]\L`y~1+y;0]
_+n;     input a line, make sure it's in number format with "+" and store it in n
n~'[     use this number to control a FOR loop
[        another FOR loop.  We carefully make sure that n remains on top of the c-stack
3:       duplicate the top (maybe empty) item of the stack, our X position, 3 times.
?!       if it's equal to zero or undefined
y~=|     or it's equal to the Y position
1+2:n~=| or it's equal to n once incremented (duplicating saves it for next iteration)
[N]      push N
![\ ]    else push a space
`        output whatever was just pushed
"#       discard the test results so that n remains on top of the c-stack
]        end the X position FOR loop
\L`      print a newline, but the L should be an actual newline
y~1+y;   increment the Y position
0        put zero as the top item on the stack, this is our reset X position
]        end the Y position FOR loop

2012 - Element

_+'[y~1+y;0[1+4:"2:'=1=|y~=|\ [#N]`"#]\
`]

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.

_+'[y~1+y;0[1+4:"2:'=1=|y~=|\S[#N]`"#]\L`]
_+'      input line, convert to #, move to c-stack
[        FOR loop
 y~1+y;  increment the y-pos
 0       set the x-pos (the top # on the stack) to zero
 [       FOR loop
  1+4:   increment x-pos and make 3 additional copies (4 is total #)
  "2:'   make a copy of the N size on the main stack
  =      if x-pos == size
  1=     or if x-pos == 1
  y~=|   of if x-pos == y-pos
  \S     (always) push a space
  [      the IF body (technically a FOR loop)
   #N    if true, remove the space and push an N
  ]      end IF
  `      output the pushed character
  "#     remove the result of the conditional
 ]       end x-pos FOR
 \L`     output a newline
]        end y-pos FOR
deleted 14 characters in body
Source Link
PhiNotPi
  • 29.1k
  • 10
  • 85
  • 157

This answer

This answer

added 2 characters in body
Source Link
PhiNotPi
  • 29.1k
  • 10
  • 85
  • 157
Loading
deleted 143 characters in body
Source Link
PhiNotPi
  • 29.1k
  • 10
  • 85
  • 157
Loading
added 76 characters in body
Source Link
PhiNotPi
  • 29.1k
  • 10
  • 85
  • 157
Loading
added 259 characters in body
Source Link
PhiNotPi
  • 29.1k
  • 10
  • 85
  • 157
Loading
edited body
Source Link
PhiNotPi
  • 29.1k
  • 10
  • 85
  • 157
Loading
edited body
Source Link
PhiNotPi
  • 29.1k
  • 10
  • 85
  • 157
Loading
Source Link
PhiNotPi
  • 29.1k
  • 10
  • 85
  • 157
Loading