[N
S S N
_Create_Label_LOOP][S S S T T S S S T N
_Push_49][S N
S _Duplicate_49][S N
S _Duplicate_49][T N
T S _Read_STDIN_as_character][T T T _Retrieve][T S S T _Subtract][S N
S _Duplicate][N
T S S N
_If_0_Jump_to_Label_1][S S S T N
_Push_1][T S S T _Subtract][N
T S T N
_If_0_Jump_to_Label_0][N
N
N
_Exit][N
S S T N
_Create_Label_0][S S S T N
_Push_1][N
S S S N
_Create_Label_1][T N
S T _Print_integer_to_STDOUT][N
S N
N
_Jump_to_Label_LOOP]
Letters S
(space), T
(tab), and N
(new-line) added as highlighting only.
[..._some_action]
added as explanation only.
Since Whitespace can only take input as integer or character, we must add a trailing character (other than 0
or 1
; like a newline, space, a letter, etc.) to indicate we're done with the input-string after reading it character by character.
Try it online (with raw spaces, tabs and new-lines only).
Example run: input = 100
Command Explanation Stack Heap STDIN STDOUT
NSSN Create Label_LOOP []
SSSTTSSSTN Push 49 [49]
SNS Duplicate 49 [49,49]
SNS Duplicate 49 [49,49,49]
TNTS Read STDIN as character [49,49] {49:49} 1
TTT Retrieve [49,49] {49:49}
TSST Subtract (49-49) [0] {49:49}
SNS Duplicate 0 [0,0] {49:49}
NTSSN If 0: Jump to Label_1 [0] {49:49}
NSSSN Create Label_1 [0] {49:49}
TNST Print to STDOUT as integer [] {49:49} 0
NSNN Jump to Label_LOOP [] {49:49}
SSSTTSSSTN Push 49 [49]
SNS Duplicate 49 [49,49]
SNS Duplicate 49 [49,49,49]
TNTS Read STDIN as character [49,49] {49:48} 0
TTT Retrieve [49,48] {49:48}
TSST Subtract (49-49) [1] {49:48}
SNS Duplicate 0 [1,1] {49:48}
NTSSN If 0: Jump to Label_1 [1] {49:48}
SSSTN Push 1 [1,1] {49:48}
TSST Subtract (1-1) [0] {49:48}
NTSTN If 0: Jump to Label_0 [] {49:48}
NSSTN Create Label_0 [] {49:48}
SSSTN Push 1 [1] {49:48}
NSSSN Create Label_1 [1] {49:48}
TNST Print to STDOUT as integer [] {49:48} 1
NSNN Jump to Label_LOOP [] {49:48}
SSSTTSSSTN Push 49 [49]
SNS Duplicate 49 [49,49]
SNS Duplicate 49 [49,49,49]
TNTS Read STDIN as character [49,49] {49:48} 0
TTT Retrieve [49,48] {49:48}
TSST Subtract (49-49) [1] {49:48}
SNS Duplicate 0 [1,1] {49:48}
NTSSN If 0: Jump to Label_1 [1] {49:48}
SSSTN Push 1 [1,1] {49:48}
TSST Subtract (1-1) [0] {49:48}
NTSTN If 0: Jump to Label_0 [] {49:48}
NSSTN Create Label_0 [] {49:48}
SSSTN Push 1 [1] {49:48}
NSSSN Create Label_1 [1] {49:48}
TNST Print to STDOUT as integer [] {49:48} 1
NSNN Jump to Label_LOOP [] {49:48}
SSSTTSSSTN Push 49 [49]
SNS Duplicate 49 [49,49]
SNS Duplicate 49 [49,49,49]
TNTS Read STDIN as character [49,49] {49:10} \n
TTT Retrieve [49,10] {49:10}
TSST Subtract (49-10) [39] {49:10}
SNS Duplicate 39 [39,39] {49:10}
NTSSN If 0: Jump to Label_1 [39] {49:10}
SSSTN Push 1 [39,1] {49:10}
TSST Subtract (39-1) [38] {49:10}
NTSTN If 0: Jump to Label_0 [] {49:10}
NNN Exit program [] {49:10}