A port of my other question: Double Prime Words
Consider a word/string of n
alphanumeric characters with sum of the characters, s
, using their numeric position in the alphabet (a=1, B=2, c=3,
etc.) or numeric value (0,1, 2, 3 - 9). Numeric characters should be taken at individual value. (66
is two 6
characters for a sum of 12
)
A word is a Length-Sum Multiple if and only if s
is a multiple of n
, specifically s/n
is a positive integer {1,2,3,4...}
. In the case of s=0
, and n={0,00,000,...}
, 0 is a multiple of any n
but it does not yield a positive integer. Hence an input of {0,00,000,...}
is False.
Input can be any combination of numbers and upper or lower case alphabetic characters, as there is no numeric difference between a
or A
. Handling empty input, n=s=0
, is not required.
Output is any appropriate logical format related to your language. i.e. True or False, T or F, 1 or 0, positive for truthy and 0 for falsy, etc. Specifying what format your output will appear is highly appreciated, but not required. (Output need not include n or s, but I include them below as demonstration and example)
Winning condition: In as few bytes as possible, write a function that is able to determine if a string is a Length-Sum Multiple.
Examples
Input -> Output (n,s)
hello -> False (5, 52)
MuLtIpLe -> False (8, 108)
Junct10n -> False (8, 83)
Order66 -> False (7, 72)
CodeGolf -> False (8, 67)
SUM -> False (3, 53)
ID -> False (2, 13)
25 -> False (2, 7)
0 -> False (1, 0) 0/1 = 0 which is not a positive integer
10 -> False (2, 1)
hello2 -> True (6, 54)
5um -> True (3, 39)
length -> True (6, 66)
Order64 -> True (7, 70)
Covid19 -> True (7, 63)
Word -> True (4, 60)
APPLE -> True (5, 50)
lawYER -> True (6, 84)
abc123 -> True (6, 12)
is -> True (2, 28)
television -> True (10, 130)
19 -> True (2, 10)
234 -> True (3, 9)
a -> True (1, 1)
b -> True (1, 2)
C -> True (1, 3)
Z -> True (1, 26)
1 -> True (1, 1)
9 -> True (1, 9)
.lower()
" at the beginning which doesn't add much interesting to solutions. Up to you though - I think there could definitely be some interesting approaches this way too! \$\endgroup\$0
falsey?0
IS divisible by 1.. \$\endgroup\$s mod n == 0
" compared with "s/n is a positive integer". The first two are true for \$s=0\$ and the third isn't. I'd recommend removing the first two and just use the third, which is rigorous enough to work by itself \$\endgroup\$