[S S S N
_Push_0][S N
S _Duplicate_0][T N
T T _Read_STDIN_as_number][T T T _Retrieve][S S S T S N
_Push_2][T S S T _Subtract][S N
S _Duplicate_input-2][N
T T N
_If_negative_Jump_to_Label_-1][S S S T N
_Push_1][S N
S _Duplicate_1][T N
S T _Print_as_integer][S S T T N
_Push_-1][T N
S T _Print_as_integer][T S S T _Subtract][N
S S T N
_Create_Label_LOOP][S N
S _Duplicate][N
T T S N
_If_negative_Jump_to_EXIT][S S S T N
_Push_1][S N
S _Duplicate_1][T N
S T _Print_as_integer][T S S T _Subtract][N
S N
T N
_Jump_to_LOOP][N
S S N
_Create_Label_-1][T N
S T _Print_as_integer][N
S S S N
_Create_Label_EXIT]
Letters S
(space), T
(tab), and N
(new-line) added as highlighting only.
[..._some_action]
added as explanation only.
Prints 1
instead of C
and -
instead of E
.
-1 byte thanks to @JoKing by suggesting the use of 1
and -1
instead of 0
and 1
.
Explanation in pseudo-code:
Integer i = STDIN-input as integer - 2
If i is negative (-1):
Print i (so print "-1")
Else:
Print "1-1"
Start LOOP:
If i is negative:
EXIT program
Print "1"
i = i-1
Go to the next iteration of the LOOP
Example runs:
Input: 1
Command Explanation Stack Heap STDIN STDOUT STDERR
SSSN Push 0 [0]
SNS Duplicate top (0) [0,0]
TNTT Read STDIN as integer [0] {0:1} 1
TTT Retrieve heap at 0 [1] {0:1}
SSSTSN Push 2 [1,2] {0:1}
TSST Subtract top two [-1] {0:1}
SNS Duplicate input-2 [-1,-1] {0:1}
NTSN If neg.: Jump to Label_-1 [-1] {0:1}
NSSN Create Label_-1 [-1] {0:1}
TNST Print top as integer [] {0:1} -1
NSSSN Create Label_EXIT [] {0:1}
error
Try it online (with raw spaces, tabs and new-lines only).
Stops with error: Exit not defined.
Input: 4
Command Explanation Stack Heap STDIN STDOUT STDERR
SSSN Push 0 [0]
SNS Duplicate top (0) [0,0]
TNTT Read STDIN as integer [0] {0:4} 4
TTT Retrieve heap at 0 [4] {0:4}
SSSTSN Push 2 [4,2] {0:4}
TSST Subtract top two [2] {0:4}
SNS Duplicate input-2 [2,2] {0:4}
NTSN If neg.: Jump to Label_-1 [2] {0:4}
SSSTN Push 1 [2,1] {0:4}
SNS Duplicate top (1) [2,1,1] {0:4}
TNST Print as integer [2,1] {0:4} 1
SSTTN Push -1 [2,1,-1] {0:4}
TNST Print as integer [2,1] {0:4} -1
TSST Subtract top two [1] {0:4}
NSSTN Create Label_LOOP [1] {0:4}
SNS Duplicate top (1) [1,1] {0:4}
NTTSN If neg.: Jump to Label_EXIT [1] {0:4}
SSSTN Push 1 [1,1] {0:4}
SNS Duplicate top (1) [1,1,1] {0:4}
TNST Print as integer [1,1] {0:4} 1
TSST Subtract top two [0] {0:4}
NSNTN Jump to Label_LOOP [0] {0:4}
SNS Duplicate top (0) [0,0] {0:4}
NTTSN If neg.: Jump to Label_EXIT [0] {0:4}
SSSTN Push 1 [0,1] {0:4}
SNS Duplicate top (1) [0,1,1] {0:4}
TNST Print as integer [0,1] {0:4} 1
TSST Subtract top two [-1] {0:4}
NSNTN Jump to Label_LOOP [-1] {0:4}
SNS Duplicate top (-1) [-1,-1] {0:4}
NTTSN If neg.: Jump to Label_EXIT [-1] {0:4}
NSSSN Create Label_EXIT [-1] {0:4}
error
Try it online (with raw spaces, tabs and new-lines only).
Stops with error: Exit not defined.
C
andE
, but there are so many nice approaches possible for this challenge! Using mathematical operations forC=1
/E=2
orC=2
/E=3
like the top answer does; usingC=0
/E=1
with10^(n-1)
; usingC=0
/E=.
by decimal formatting0.0
; usingC=1
/E=-
by utilizing-1
; etc. etc. So many unique possibilities for a challenge that looked so to-the-point at first. Too bad I can only +1 once. ;) \$\endgroup\$