[S S S N
_Push_0][S N
S _Duplicate_0][S N
S _Duplicate_0][N
S S N
_Create_Label_LOOP][S N
S _Duplicate][S N
S _Duplicate][T N
T S _Read_STDIN_as_char][T T T _Retrieve_input][S N
S _Duplicate][S S S T S T S N
_Push_10][T S S T _Subtract][N
T S S N
_If_0_jump_to_Label_PRINT_RESULT][T S S S _Add][S N
T _Swap_top_two][S S S T N
_Push_1][T S S S _Add][S N
T _Swap_top_two][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_PRINT_RESULT][S N
N
_Discard_top][S N
T _Swap_top_two][T S T T _Modulo][N
T S T N
_If_0_Jump_to_Label_TRUTHY][S S T T N
_Push_-1][N
S S T N
_Create_Label_TRUTHY][S S S T N
_Push_1][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.
Since Whitespace can only read input one character at a time, the input must contain a trailing newline so we'll know when we're done reading characters.
Whitespace also lacks truthy/falsey values, so this program will output 1
for truthy and 0
for falsey (could be 28 bytes less with 0
as truthy and a positive integer as falsey).
Try it online (with raw spaces, tabs and new-lines only).
Explanation in pseudo-code:
Integer length = 0
Integer sum = 0
Start LOOP:
Integer input = STDIN as character
If(input == '\n'):
Jump to PRINT_RESULT
sum = sum + input
length = length + 1
Go to next iteration of LOOP
PRINT_RESULT:
Integer result = 0
Integer mod = sum modulo length
If(mod == 0):
Skip to TRUTHY
Else:
result = -1
TRUTHY:
result = result + 1
Print result as integer to STDOUT
0
for truthy and a non-consistent nonzero number for falsy? Any two values? Truthy and falsy swapped? @All: you may want to vote here \$\endgroup\$false
for a perfect number andtrue
for a non-perfect one allowed? What about1
for a perfect number and any other number otherwise, or positive for perfect and negative for non-perfect? \$\endgroup\$