Skip to main content
Fixed an error in explanation
Source Link

dc, 29 bytes

[d1-d0<F]dsFx+p[npz1<G]sGz1<G

Try it online!

This is a good showing for dc because its printing capabilities are so limited, but line up perfectly with the challenge spec. Input is from the stack (and must be the only thing on the stack), output is to stdout. There's some duplication near the end I can't figure out how to get rid of without breaking the case n=1

Explanation

F will be the macro [d1-d0<F]
d        copy the top of the stack
 1-      decrement
   d0<F  repeat (tail recursion) until a 0 is on top

G will be the macro [npz1<G]
n        print the top (pop, but no newline)
 p       print the new top (newline, but no pop)
  z1<G   repeat (tail recursion) until only one number is on the stack

Full program (example input: 4)
[d1-d0<F]dsFx      Store F and run it: new stack is 0 1 2 3 4
+                  Drop the zero (can't just recurse to 1, or n=1 breaks)
p                  Print (no pop) the '1': stack is 1 2 3 4
[npz1<G]dsG[npz1<G]sG        Store G
z1<G               Run G if there's more than one number on the stack

dc, 29 bytes

[d1-d0<F]dsFx+p[npz1<G]sGz1<G

Try it online!

This is a good showing for dc because its printing capabilities are so limited, but line up perfectly with the challenge spec. Input is from the stack (and must be the only thing on the stack), output is to stdout. There's some duplication near the end I can't figure out how to get rid of without breaking the case n=1

Explanation

F will be the macro [d1-d0<F]
d        copy the top of the stack
 1-      decrement
   d0<F  repeat (tail recursion) until a 0 is on top

G will be the macro [npz1<G]
n        print the top (pop, but no newline)
 p       print the new top (newline, but no pop)
  z1<G   repeat (tail recursion) until only one number is on the stack

Full program (example input: 4)
[d1-d0<F]dsFx      Store F and run it: new stack is 0 1 2 3 4
+                  Drop the zero (can't just recurse to 1, or n=1 breaks)
p                  Print (no pop) the '1': stack is 1 2 3 4
[npz1<G]dsG        Store G
z1<G               Run G if there's more than one number on the stack

dc, 29 bytes

[d1-d0<F]dsFx+p[npz1<G]sGz1<G

Try it online!

This is a good showing for dc because its printing capabilities are so limited, but line up perfectly with the challenge spec. Input is from the stack (and must be the only thing on the stack), output is to stdout. There's some duplication near the end I can't figure out how to get rid of without breaking the case n=1

Explanation

F will be the macro [d1-d0<F]
d        copy the top of the stack
 1-      decrement
   d0<F  repeat (tail recursion) until a 0 is on top

G will be the macro [npz1<G]
n        print the top (pop, but no newline)
 p       print the new top (newline, but no pop)
  z1<G   repeat (tail recursion) until only one number is on the stack

Full program (example input: 4)
[d1-d0<F]dsFx      Store F and run it: new stack is 0 1 2 3 4
+                  Drop the zero (can't just recurse to 1, or n=1 breaks)
p                  Print (no pop) the '1': stack is 1 2 3 4
[npz1<G]sG        Store G
z1<G               Run G if there's more than one number on the stack
Source Link

dc, 29 bytes

[d1-d0<F]dsFx+p[npz1<G]sGz1<G

Try it online!

This is a good showing for dc because its printing capabilities are so limited, but line up perfectly with the challenge spec. Input is from the stack (and must be the only thing on the stack), output is to stdout. There's some duplication near the end I can't figure out how to get rid of without breaking the case n=1

Explanation

F will be the macro [d1-d0<F]
d        copy the top of the stack
 1-      decrement
   d0<F  repeat (tail recursion) until a 0 is on top

G will be the macro [npz1<G]
n        print the top (pop, but no newline)
 p       print the new top (newline, but no pop)
  z1<G   repeat (tail recursion) until only one number is on the stack

Full program (example input: 4)
[d1-d0<F]dsFx      Store F and run it: new stack is 0 1 2 3 4
+                  Drop the zero (can't just recurse to 1, or n=1 breaks)
p                  Print (no pop) the '1': stack is 1 2 3 4
[npz1<G]dsG        Store G
z1<G               Run G if there's more than one number on the stack