[S S S N
_Push_0][S N
S _Duplicate][S N
S _Duplicate][T N
T S _Read_STDIN_as_character][T T T _Retrieve][S S S T S S T N
_Push_9][T S S T _Subtract][S N
S _Duplicate][N
T S S T N
_If_0_Jump_to_Label_TAB][S S S T N
_Push_1][T S S T _Subtract][S N
S _Duplicate][N
T S S N
_If_0_Jump_to_Label_NEWLINE][S S S T S T T S N
_Push_22][T S S T _Subtract][N
T S T N
_If_0_Jump_to_Label_SPACE][N
S T N
_Jump_to_Label_PRINT][N
S S S T N
_Create_Label_TAB][S S S T S S T S T N
_Push_37][N
S T N
_Jump_to_Label_PRINT][N
S S S N
_Create_Label_NEWLINE][S S S T S S S S T N
_Push_33][N
S T N
_Jump_to_Label_PRINT][N
S S T N
_Create_Label_SPACE][S S S T S S S T T S N
_Push_70][N
S S N
_Create_Label_PRINT][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.
70 spaces, 37 tabs, and 33 new-lines used.
Usually I use the Create Labels in the order NSSN
, NSSSN
, NSSTN
, NSSSSN
, NSSSTN
, NSSTSN
, NSSTTN
, etc. But because printing a number where the binary S=0
/T=1
is used affects the number I need to output, I used the labels NSSN
, NSSSN
, NSSTN
, and NSSSTN
instead, which gave the perfect amount of spaces/tabs to be printed with the binary numbers SSSTSSSSTN
(33; amount of new-lines), SSSTSSTSTN
(37; amount of tabs), and SSSTSSSTTSN
(70; amount of spaces).
Explanation in pseudo-code:
Character c = STDIN-input as character
If c is a tab:
Print 37
Else if c is a new-line:
Print 33
Else if c is a space:
Print 70
Else
Print 0
Example runs:
Input: space
Command Explanation Stack Heap STDIN STDOUT STDERR
SSSN Push 0 [0]
SNS Duplicate top (0) [0,0]
SNS Duplicate top (0) [0,0,0]
TNTS Read STDIN as character [0,0] {0:32} \n
TTT Retrieve [0,32] {0:32}
SSSTSSTN Push 9 [0,32,9] {0:32}
TSST Subtract top two (32-9) [0,23] {0:32}
SNS Duplicate top (23) [0,23,23] {0:32}
NTSSTN If 0: Jump to Label_TAB [0,23] {0:32}
SSSTN Push 1 [0,23,1] {0:32}
TSST Subtract top two (23-1) [0,22] {0:32}
SNS Duplicate top (22) [0,22,22] {0:32}
NTSSN If 0: Jump to Label_NEWLINE [0,22] {0:32}
SSSTSTTSN Push 22 [0,22,22] {0:32}
TSST Subtract top two (22-22) [0,0] {0:32}
NTSTN If 0: Jump to Label_SPACE [0] {0:32}
NSSTN Create Label_SPACE [0] {0:32}
SSSTSSSTTSN Push 70 [0,70] {0:32}
NSTN Jump to Label_PRINT [0,70] {0:32}
NSSN Create Label_PRINT [0,70] {0:32}
TNST Print as integer [0] {0:32} 70
error
Program stops with an error: No exit defined.
Try it online (with raw spaces, tabs, and new-lines only).
Input: tab
STDIN will be \t
(9
) instead, in which case it will be 0
at the first If 0
check, goes to LABEL_TAB
/NSSSTN
, and will push and print 37
instead.
Try it online (with raw spaces, tabs, and new-lines only).
Input: new-line
STDIN will be \n
(10
) instead, in which case it will be 0
at the second If 0
check, goes to Label_NEWLINE
/NSSSN
, and will push and print 33
instead.
Try it online (with raw spaces, tabs, and new-lines only).
Input: anything else
Any other input-character will do NSTN
(Jump to Label_PRINT) after the third If 0
check, printing the 0
that was still on the stack (which we've duplicated at the very beginning).
Try it online (with raw spaces, tabs, and new-lines only).