Skip to main content
1 of 2
Bubbler
  • 78.4k
  • 5
  • 149
  • 469

Stack Cats, 18 + 4 -nl = 22 bytes

*(>]>{<:_-!:]}[*)>

Try it online!

Flags:

  • -n to do integer I/O
  • -l to implicitly mirror to the left; the actual code is <(*]{[:!-_:>}<[<)*(>]>{<:_-!:]}[*)>.

Adapted from this answer for printing out 1 to 10. I had to fall back to the <(...)*(...)> structure to handle the input correctly. (I once tried _(...)_(...)_ instead, but I realized it is incorrect for n=1.)

How it works:

     [-1 n*]
<    [*] [-1 n]
(..) Skip
*    [1*] [-1 n]
(
>]>  [1] [-1] [n] [*]
{    Remember 0
<:   [1] [-1] [n 0*] [...]
_-!  [1] [-1] [n n-1*] [...]
:]   [1] [-1] [n-1] [... n*]
}    Exit if top is 0
[    Remove 0 at the top
*    Make the top positive
)    Top = 1; exit
>    Return to the stack of numbers
Bubbler
  • 78.4k
  • 5
  • 149
  • 469