[S S S T S T S N
_Push_10][S N
S _Duplicate_10][S N
S _Duplicate_10][S N
S _Duplicate_10][T N
T T _Read_STDIN_as_integer][T T T _Retrieve_input][N
S S N
_Create_Label_LOOP][S S S T N
_Push_1][T S S T _Subtract][S N
S _Duplicate][N
T T S N
_If_negative_Jump_to_Label_EXIT][S N
T _Swap][S T S S T S N
_Copy_2st][T S S N
_Multiply][S N
T _Swap][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_EXIT][T S S S _Add][T N
S T _Print_as_integer]
Letters S
(space), T
(tab), and N
(new-line) added as highlighting only.
[..._some_action]
added as explanation only.
Try it online (with raw spaces, tabs and new-lines only).
Explanation in pseudo-code:
Integer i = STDIN as integer
Integer j = 10
Start LOOP:
i = i - 1
If i is negative (-1): Go to function PRINT_AND_EXIT
j = j * 10
Go to next iteration of LOOP
function PRINT_AND_EXIT:
j = j + i (Since i=-1 at this point, this is basically j = j - 1)
Print j as integer
Exit with error
Example run (n=4
):
Command Explanation Stack HEAP STDIN STDOUT STDERR
SSSTSTSN Push 10 [10]
SNS Duplicate top (10) [10,10]
SNS Duplicate top (10) [10,10,10]
SNS Duplicate top (10) [10,10,10,10]
TNTT Read STDIN as integer [10,10,10] {10:4} 4
TTT Retrieve [10,10,4] {10:4}
NSSN Create Label_LOOP [10,10,4] {10:4}
SSSTN Push 1 [10,10,4,1] {10:4}
TSST Subtract (4-1) [10,10,3] {10:4}
SNS Duplicate top (3) [10,10,3,3] {10:4}
NTTSN If neg.: Jump to Label_EXIT [10,10,3] {10:4}
SNT Swap top two [10,3,10] {10:4}
STSSTSN Copy 2nd [10,3,10,10] {10:4}
TSSN Multiply (10*10) [10,3,100] {10:4}
SNT Swap top two [10,100,3] {10:4}
NSNN Jump to Label_LOOP [10,100,3] {10:4}
SSSTN Push 1 [10,100,3,1] {10:4}
TSST Subtract (3-1) [10,100,2] {10:4}
SNS Duplicate top (2) [10,100,2,2] {10:4}
NTTSN If neg.: Jump to Label_EXIT [10,100,2] {10:4}
SNT Swap top two [10,2,100] {10:4}
STSSTSN Copy 2nd [10,2,100,10] {10:4}
TSSN Multiply (100*10) [10,2,1000] {10:4}
SNT Swap top two [10,1000,2] {10:4}
NSNN Jump to Label_LOOP [10,1000,2] {10:4}
SSSTN Push 1 [10,1000,2,1] {10:4}
TSST Subtract (2-1) [10,1000,1] {10:4}
SNS Duplicate top (1) [10,1000,1,1] {10:4}
NTTSN If neg.: Jump to Label_EXIT [10,1000,1] {10:4}
SNT Swap top two [10,1,1000] {10:4}
STSSTSN Copy 2nd [10,1,1000,10] {10:4}
TSSN Multiply (1000*10) [10,1,10000] {10:4}
SNT Swap top two [10,10000,1] {10:4}
NSNN Jump to Label_LOOP [10,10000,1] {10:4}
SSSTN Push 1 [10,10000,1,1] {10:4}
TSST Subtract (1-1) [10,10000,0] {10:4}
SNS Duplicate top (0) [10,10000,0,0] {10:4}
NTTSN If neg.: Jump to Label_EXIT [10,10000,0] {10:4}
SNT Swap top two [10,0,10000] {10:4}
STSSTSN Copy 2nd [10,0,10000,10] {10:4}
TSSN Multiply (10000*10) [10,0,100000] {10:4}
SNT Swap top two [10,100000,0] {10:4}
NSNN Jump to Label_LOOP [10,100000,0] {10:4}
SSSTN Push 1 [10,100000,0,1] {10:4}
TSST Subtract (0-1) [10,100000,-1] {10:4}
SNS Duplicate top (-1) [10,100000,-1,-1] {10:4}
NTTSN If neg.: Jump to Label_EXIT [10,100000,-1] {10:4}
NSSSN Create Label_EXIT [10,100000,-1] {10:4}
TSSS Add (10000+-1) [10,99999] {10:4}
TNST Print as integer [10] {10:4} 99999
error
Stops program with error: No exit defined.
Also can we output as a list ie
[9, 9, 9]
– Okx – 2018-04-29T19:10:04.9671@Okx no, it has to be a single number. So 3 => 9999 and cannot be [9,9,9,9]. – Script47 – 2018-04-29T19:10:42.810
15Top of Hot Network Questions with a score of one. I'm thinking the idea about preventing HNQ when number of answers > score is a decent one. – CAD97 – 2018-04-29T21:01:25.863
@CAD97 meta it? – Script47 – 2018-04-29T21:26:04.027
@Script47 It was brought up on Mother Meta but nothing was ever done about it.
– Esolanging Fruit – 2018-04-30T05:24:10.0433
Someone should write an answer in 99, although I'm not sure how to do multiply/power in that esolang. ;)
– Kevin Cruijssen – 2018-04-30T07:12:35.4203You're getting a lot of downvotes because of the overly complicated explanation for what is, essentially, either print
n+1
9
s or print10^n-1
– Jo King – 2018-04-30T12:41:06.9871
@KevinCruijssen challenge accepted
– Giuseppe – 2018-04-30T12:56:58.9873@Script47 It seems arbitrary to print N + 1 nines instead of just just N nines. – Adám – 2018-04-30T13:38:22.150