[S S S T N
_Push_1][S N
S _Dupe_1][T N
T T _Read_STDIN_as_integer][T T T _Retrieve_input][S N
S _Dupe_input][N
S S N
_Create_Label_LOOP][S N
S _Dupe_top][N
T S S N
_If_0_Jump_to_Label_LOOP2][S S S T N
_Push_1][T S S T _Subtract][S N
T _Swap_top_two][S N
S _Dupe_top][S S S T S N
_Push_2][T S T T _Modulo][S N
T _Swap_top_two][S S S T S N
_Push_2][T S T S _Integer_divide][S T S S T S N
_Copy_0-based_2nd][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_LOOP2][S N
T _swap_top_two][S S S T N
_Push_1][S N
S _Dupe_1][T T T _Retrieve_input][T S S T _Subtract][T S S S _Add][N
T S T N
_If_0_Jump_to_Label_DONE][S S S T S T S N
_Push_10][T S S N
_Multiply][T S S S _Add][N
S N
S N
_Jump_to_Label_LOOP2][N
S S T N
_Create_Label_DONE][T N
S T _Print_as_integer_to_STDOUT]
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).
Funny thing is, is that I can use everything Whitespace has to offer for this challenge. So even if builtins were allowed, this would still be the approach to use, since Whitespace has none. ;)
Explanation in pseudo-code:
Integer input = read STDIN as integer
Integer index = input
Integer b = input
Start LOOP:
If(index == 0):
Jump to LOOP2
index = index - 1
Integer a[index] = b[previous_index] modulo-2
Integer b[index] = b[previous_index] integer-divided by 2
Go to next iteration of LOOP
Start LOOP2:
If(index+1 == input):
Jump to DONE
a = a + b*10
Go to next iteration of LOOP2
Label DONE:
Print a as integer to STDOUT
(stop program implicitly with an error)
Example run: input = 6
Command Explanation Stack Heap STDIN STDOUT
SSST Push 1 [1]
SNS Duplicate top (1) [1,1]
TNTT Read STDIN as integer [1] {1:6} 6
TTT Retrieve input from heap [6] {1:6}
SNS Duplicate top (6) [6,6] {1:6}
NSSN Create Label LOOP [6,6] {1:6}
SNS Duplicate top (6) [6,6,6] {1:6}
NTSSN If 0: Jump to Label LOOP2 [6,6] {1:6}
SSSTN Push 1 [6,6,1] {1:6}
TSST Subtract (6-1) [6,5] {1:6}
SNT Swap top two [5,6] {1:6}
SNS Duplicate top (6) [5,6,6] {1:6}
SSSTSN Push 2 [5,6,6,2] {1:6}
TSTT Modulo (6%2) [5,6,0] {1:6}
SNT Swap top two [5,0,6] {1:6}
SSSTSN Push 2 [5,0,6,2] {1:6}
TSTS Integer-divide (6//2) [5,0,3] {1:6}
STSSTSN Copy 0-based 2nd (5) [5,0,3,5] {1:6}
NSNN Jump to Label LOOP [5,0,3,5] {1:6}
SNS Duplicate top (5) [5,0,3,5,5] {1:6}
NTSSN If 0: Jump to Label LOOP2 [5,0,3,5] {1:6}
SSSTN Push 1 [5,0,3,5,1] {1:6}
TSST Subtract (5-1) [5,0,3,4] {1:6}
SNT Swap top two [5,0,4,3] {1:6}
SNS Duplicate top (3) [5,0,4,3,3] {1:6}
SSSTSN Push 2 [5,0,4,3,3,2] {1:6}
TSTT Modulo (3%2) [5,0,4,3,1] {1:6}
SNT Swap top two [5,0,4,1,3] {1:6}
SSSTSN Push 2 [5,0,4,1,3,2] {1:6}
TSTS Integer-divide (3//2) [5,0,4,1,1] {1:6}
STSSTSN Copy 0-based 2nd (4) [5,0,4,1,1,4] {1:6}
NSNN Jump to Label LOOP [5,0,4,1,1,4] {1:6}
SNS Duplicate top (4) [5,0,4,1,1,4,4] {1:6}
NTSSN If 0: Jump to Label LOOP2 [5,0,4,1,1,4] {1:6}
SSSTN Push 1 [5,0,4,1,1,4,1] {1:6}
TSST Subtract (4-1) [5,0,4,1,1,3] {1:6}
SNT Swap top two [5,0,4,1,3,1] {1:6}
SNS Duplicate top (1) [5,0,4,1,3,1,1] {1:6}
SSSTSN Push 2 [5,0,4,1,3,1,1,2] {1:6}
TSTT Modulo (3%2) [5,0,4,1,3,1,1] {1:6}
SNT Swap top two [5,0,4,1,3,1,1] {1:6}
SSSTSN Push 2 [5,0,4,1,3,1,1,2] {1:6}
TSTS Integer-divide (1//2) [5,0,4,1,3,1,0] {1:6}
STSSTSN Copy 0-based 2nd (3) [5,0,4,1,3,1,0,3] {1:6}
NSNN Jump to Label LOOP [5,0,4,1,3,1,0,3] {1:6}
SNS Duplicate top (3) [5,0,4,1,3,1,0,3,3] {1:6}
NTSSN If 0: Jump to Label LOOP2 [5,0,4,1,3,1,0,3] {1:6}
SSSTN Push 1 [5,0,4,1,3,1,0,3,1] {1:6}
TSST Subtract (3-1) [5,0,4,1,3,1,0,2] {1:6}
SNT Swap top two [5,0,4,1,3,1,2,0] {1:6}
SNS Duplicate top (0) [5,0,4,1,3,1,2,0,0] {1:6}
SSSTSN Push 2 [5,0,4,1,3,1,2,0,0,2] {1:6}
TSTT Modulo (0%2) [5,0,4,1,3,1,2,0,0] {1:6}
SNT Swap top two [5,0,4,1,3,1,2,0,0] {1:6}
SSSTSN Push 2 [5,0,4,1,3,1,2,0,0,2] {1:6}
TSTS Integer-divide (0//2) [5,0,4,1,3,1,2,0,0] {1:6}
STSSTSN Copy 0-based 2nd (2) [5,0,4,1,3,1,2,0,0,2] {1:6}
NSNN Jump to Label LOOP [5,0,4,1,3,1,2,0,0,2] {1:6}
SNS Duplicate top (2) [5,0,4,1,3,1,2,0,0,2,2] {1:6}
NTSSN If 0: Jump to Label LOOP2 [5,0,4,1,3,1,2,0,0,2] {1:6}
SSSTN Push 1 [5,0,4,1,3,1,2,0,0,2,1] {1:6}
TSST Subtract (2-1) [5,0,4,1,3,1,2,0,0,1] {1:6}
SNT Swap top two [5,0,4,1,3,1,2,0,1,0] {1:6}
SNS Duplicate top (0) [5,0,4,1,3,1,2,0,1,0,0] {1:6}
SSSTSN Push 2 [5,0,4,1,3,1,2,0,1,0,0,2] {1:6}
TSTT Modulo (0%2) [5,0,4,1,3,1,2,0,1,0,0] {1:6}
SNT Swap top two [5,0,4,1,3,1,2,0,1,0,0] {1:6}
SSSTSN Push 2 [5,0,4,1,3,1,2,0,1,0,0,2] {1:6}
TSTS Integer-divide (0//2) [5,0,4,1,3,1,2,0,1,0,0] {1:6}
STSSTSN Copy 0-based 2nd (1) [5,0,4,1,3,1,2,0,1,0,0,1] {1:6}
NSNN Jump to Label LOOP [5,0,4,1,3,1,2,0,1,0,0,1] {1:6}
SNS Duplicate top (1) [5,0,4,1,3,1,2,0,1,0,0,1,1] {1:6}
NTSSN If 0: Jump to Label LOOP2 [5,0,4,1,3,1,2,0,1,0,0,1] {1:6}
SSSTN Push 1 [5,0,4,1,3,1,2,0,1,0,0,1,1] {1:6}
TSST Subtract (1-1) [5,0,4,1,3,1,2,0,1,0,0,0] {1:6}
SNT Swap top two [5,0,4,1,3,1,2,0,1,0,0,0] {1:6}
SNS Duplicate top (0) [5,0,4,1,3,1,2,0,1,0,0,0,0] {1:6}
SSSTSN Push 2 [5,0,4,1,3,1,2,0,1,0,0,0,0,2] {1:6}
TSTT Modulo (0%2) [5,0,4,1,3,1,2,0,1,0,0,0,0] {1:6}
SNT Swap top two [5,0,4,1,3,1,2,0,1,0,0,0,0] {1:6}
SSSTSN Push 2 [5,0,4,1,3,1,2,0,1,0,0,0,0,2] {1:6}
TSTS Integer-divide (0//2) [5,0,4,1,3,1,2,0,1,0,0,0,0] {1:6}
STSSTSN Copy 0-based 2nd (0) [5,0,4,1,3,1,2,0,1,0,0,0,0,0] {1:6}
NSNN Jump to Label LOOP [5,0,4,1,3,1,2,0,1,0,0,0,0,0] {1:6}
SNS Duplicate top (1) [5,0,4,1,3,1,2,0,1,0,0,0,0,0,0] {1:6}
NTSSN If 0: Jump to Label LOOP2 [5,0,4,1,3,1,2,0,1,0,0,0,0,0] {1:6}
NSSSN Create Label LOOP2 [5,0,4,1,3,1,2,0,1,0,0,0,0,0] {1:6}
SNT Swap top two [5,0,4,1,3,1,2,0,1,0,0,0,0,0] {1:6}
SSSTN Push 1 [5,0,4,1,3,1,2,0,1,0,0,0,0,0,1] {1:6}
SNS Duplicate top (1) [5,0,4,1,3,1,2,0,1,0,0,0,0,0,1,1] {1:6}
TTT Retrieve input from heap [5,0,4,1,3,1,2,0,1,0,0,0,0,0,1,6] {1:6}
TSST Subtract (1-6) [5,0,4,1,3,1,2,0,1,0,0,0,0,0,-5] {1:6}
TSSS Add (0+-5) [5,0,4,1,3,1,2,0,1,0,0,0,0,-5] {1:6}
NTSTN If 0: Jump to Label DONE [5,0,4,1,3,1,2,0,1,0,0,0,0] {1:6}
SSSTSTSN Push 10 [5,0,4,1,3,1,2,0,1,0,0,0,0,10] {1:6}
TSSN Multiply (0*10) [5,0,4,1,3,1,2,0,1,0,0,0,0] {1:6}
TSSS Add (0+0) [5,0,4,1,3,1,2,0,1,0,0,0] {1:6}
NSNSN Jump to Label LOOP2 [5,0,4,1,3,1,2,0,1,0,0,0] {1:6}
SNT Swap top two [5,0,4,1,3,1,2,0,1,0,0,0] {1:6}
SSSTN Push 1 [5,0,4,1,3,1,2,0,1,0,0,0,1] {1:6}
SNS Duplicate top (1) [5,0,4,1,3,1,2,0,1,0,0,0,1,1] {1:6}
TTT Retrieve input from heap [5,0,4,1,3,1,2,0,1,0,0,0,1,6] {1:6}
TSST Subtract (1-6) [5,0,4,1,3,1,2,0,1,0,0,0,-5] {1:6}
TSSS Add (0+-5) [5,0,4,1,3,1,2,0,1,0,0,-5] {1:6}
NTSTN If 0: Jump to Label DONE [5,0,4,1,3,1,2,0,1,0,0] {1:6}
SSSTSTSN Push 10 [5,0,4,1,3,1,2,0,1,0,0,10] {1:6}
TSSN Multiply (0*10) [5,0,4,1,3,1,2,0,1,0,0] {1:6}
TSSS Add (0+0) [5,0,4,1,3,1,2,0,1,0] {1:6}
NSNSN Jump to Label LOOP2 [5,0,4,1,3,1,2,0,1,0] {1:6}
SNT Swap top two [5,0,4,1,3,1,2,0,0,1] {1:6}
SSSTN Push 1 [5,0,4,1,3,1,2,0,0,1,1] {1:6}
SNS Duplicate top (1) [5,0,4,1,3,1,2,0,0,1,1,1] {1:6}
TTT Retrieve input from heap [5,0,4,1,3,1,2,0,0,1,1,6] {1:6}
TSST Subtract (1-6) [5,0,4,1,3,1,2,0,0,1,-5] {1:6}
TSSS Add (1+-5) [5,0,4,1,3,1,2,0,0,-4] {1:6}
NTSTN If 0: Jump to Label DONE [5,0,4,1,3,1,2,0,0] {1:6}
SSSTSTSN Push 10 [5,0,4,1,3,1,2,0,0,10] {1:6}
TSSN Multiply (0*10) [5,0,4,1,3,1,2,0,0] {1:6}
TSSS Add (0+0) [5,0,4,1,3,1,2,0] {1:6}
NSNSN Jump to Label LOOP2 [5,0,4,1,3,1,2,0] {1:6}
SNT Swap top two [5,0,4,1,3,1,0,2] {1:6}
SSSTN Push 1 [5,0,4,1,3,1,0,2,1] {1:6}
SNS Duplicate top (1) [5,0,4,1,3,1,0,2,1,1] {1:6}
TTT Retrieve input from heap [5,0,4,1,3,1,0,2,1,6] {1:6}
TSST Subtract (1-6) [5,0,4,1,3,1,0,2,-5] {1:6}
TSSS Add (2+-5) [5,0,4,1,3,1,0,-3] {1:6}
NTSTN If 0: Jump to Label DONE [5,0,4,1,3,1,0] {1:6}
SSSTSTSN Push 10 [5,0,4,1,3,1,0,10] {1:6}
TSSN Multiply (0*10) [5,0,4,1,3,1,0] {1:6}
TSSS Add (1+0) [5,0,4,1,3,1] {1:6}
NSNSN Jump to Label LOOP2 [5,0,4,1,3,1] {1:6}
SNT Swap top two [5,0,4,1,1,3] {1:6}
SSSTN Push 1 [5,0,4,1,1,3,1] {1:6}
SNS Duplicate top (1) [5,0,4,1,1,3,1,1] {1:6}
TTT Retrieve input from heap [5,0,4,1,1,3,1,6] {1:6}
TSST Subtract (1-6) [5,0,4,1,1,3,-5] {1:6}
TSSS Add (3+-5) [5,0,4,1,1,-2] {1:6}
NTSTN If 0: Jump to Label DONE [5,0,4,1,1] {1:6}
SSSTSTSN Push 10 [5,0,4,1,1,10] {1:6}
TSSN Multiply (1*10) [5,0,4,1,10] {1:6}
TSSS Add (1+10) [5,0,4,11] {1:6}
NSNSN Jump to Label LOOP2 [5,0,4,11] {1:6}
SNT Swap top two [5,0,11,4] {1:6}
SSSTN Push 1 [5,0,11,4,1] {1:6}
SNS Duplicate top (1) [5,0,11,4,1,1] {1:6}
TTT Retrieve input from heap [5,0,11,4,1,6] {1:6}
TSST Subtract (1-6) [5,0,11,4,-5] {1:6}
TSSS Add (4+-5) [5,0,11,-1] {1:6}
NTSTN If 0: Jump to Label DONE [5,0,11] {1:6}
SSSTSTSN Push 10 [5,0,11,10] {1:6}
TSSN Multiply (11*10) [5,0,110] {1:6}
TSSS Add (1+10) [5,110] {1:6}
NSNSN Jump to Label LOOP2 [5,110] {1:6}
SNT Swap top two [110,5] {1:6}
SSSTN Push 1 [110,5,1] {1:6}
SNS Duplicate top (1) [110,5,1,1] {1:6}
TTT Retrieve input from heap [110,5,1,6] {1:6}
TSST Subtract (1-6) [110,5,-5] {1:6}
TSSS Add (5+-5) [110,0] {1:6}
NTSTN If 0: Jump to Label DONE [110] {1:6}
NSSTN Create Label DONE [110] {1:6}
TNST Print as integer to STDOUT [] {1:6} 110
Stops with an error after printing the result, because no exit is defined.
/
is integer (floored) division? When you say we can use conditional statements, can these include operators like==
and>
? \$\endgroup\$loop
? Doesmap
orreduce
? If I have an operator that takes a start point, transition and a condition and repeats the transition until the condition is met, is that a loop? I interpreted the spec as to mean bitwise operators, built-in methods or functions are banned, but everything else is fine, but other people have interpreted it as only arithmetic operators, conditional statements, loops and variables are allowed. Which one is it? \$\endgroup\$++
)? Are numeric literals banned? How can I do IO if I can't use the input/output commands? Are non-pure arithmetic operators (like+=
) allowed? Honestly, I think there's more than enough ambiguities to be reclosed as unclear. \$\endgroup\$