[S S S N
_Push_0][N
S S N
_Create_Label_LOOP][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 T T S T T S N
_Push_182][T S S T _Subtract][N
T S S N
_If_0_jump_to_Label_PRINT_AND_EXIT][S S S T N
_Push_1][T S S S _Add][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_PRINT_AND_EXIT][T N
S T _Print_to_STDOUT]
Letters S
(space), T
(tab), and N
(new-line) added as highlighting only.
[..._some_action]
added as explanation only.
Input requires a trailing ¶
, because Whitespace has no way to tell when the input-characters are complete. Whitespace only has two STDIN inputs: integer or character. A full string should be inputted one by one, but Whitespace doesn't know when it has all. So perhaps this answer is non-competing due to the restriction of Whitespace, but I've chosen a character outside the printable ASCII range to add as leading character for inputs, so the program knows when to stop and output the length.
Try it online (with raw spaces, tabs and new-lines only).
Explanation in pseudo-code:
Integer counter = 0
Start LOOP:
Integer input = STDIN as character
If(input == '¶')
Jump to function PRINT_AND_EXIT
counter = counter + 1
Jump to next iteration of LOOP
function PRINT_AND_EXIT:
Print counter as integer to STDOUT
Example input: acb¶
Command Explanation Stack HEAP STDIN STDOUT STDERR
SSSN Push 0 [0]
NSSN Create Label_LOOP [0]
SNS Duplicate top (0) [0,0]
SNS Duplicate top (0) [0,0,0]
TNTS Read STDIN as character [0,0] {0:97} 'a'
TTT Retrieve [0,97] {0:97}
SSSTSTTSTTSN Push 182 [0,97,182] {0:97}
TSST Subtract top two (97-182) [0,-85] {0:97}
NTSSN If 0: Jump to Label_EXIT [0] {0:97}
SSSTN Push 1 [0,1] {0:97}
TSSS Add top two (0+1) [1] {0:97}
NSNN Jump to Label_LOOP [1] {0:97}
SNS Duplicate top (1) [1,1] {0:97}
SNS Duplicate top (1) [1,1,1] {0:97}
TNTS Read STDIN as character [1,1] {0:97,1:99} 'c'
TTT Retrieve [1,99] {0:97,1:99}
SSSTSTTSTTSN Push 182 [1,99,182] {0:97,1:99}
TSST Subtract top two (99-182) [1,-83] {0:97,1:99}
NTSSN If 0: Jump to Label_EXIT [1] {0:97,1:99}
SSSTN Push 1 [1,1] {0:97,1:99}
TSSS Add top two (1+1) [2] {0:97,1:99}
NSNN Jump to Label_LOOP [2] {0:97,1:99}
SNS Duplicate top (2) [2,2] {0:97,1:99}
SNS Duplicate top (2) [2,2,2] {0:97,1:99}
TNTS Read STDIN as character [2,2] {0:97,1:99,2:98} 'b'
TTT Retrieve [2,98] {0:97,1:99,2:98}
SSSTSTTSTTSN Push 182 [2,98,182] {0:97,1:99,2:98}
TSST Subtract top two (98-182) [2,-84] {0:97,1:99,2:98}
NTSSN If 0: Jump to Label_EXIT [2] {0:97,1:99,2:98}
SSSTN Push 1 [2,1] {0:97,1:99,2:98}
TSSS Add top two (2+1) [3] {0:97,1:99,2:98}
NSNN Jump to Label_LOOP [3] {0:97,1:99,2:98}
SNS Duplicate top (3) [3,3] {0:97,1:99,2:98}
SNS Duplicate top (3) [3,3,3] {0:97,1:99,2:98}
TNTS Read STDIN as character [3,3] {0:97,1:99,2:98,3:182} '¶'
TTT Retrieve [3,182] {0:97,1:99,2:98,3:182}
SSSTSTTSTTSN Push 182 [3,182,182] {0:97,1:99,2:98,3:182}
TSST Subtract top two (182-182) [3,0] {0:97,1:99,2:98,3:182}
NTSSN If 0: Jump to Label_EXIT [3] {0:97,1:99,2:98,3:182}
NSSSN Create Label_EXIT [3] {0:97,1:99,2:98,3:182}
TNST Print as integer to STDOUT [] 3
error
Stops program with error: No exit defined.
and all printable ASCII chars count!
what do non-printable ones? \$\endgroup\$ – l4m2 May 28 '18 at 14:44""
on stdin is it an empty string, two characters or is it up to the language (in that case would"
be valid input)? \$\endgroup\$ – ბიმო May 28 '18 at 15:19