Back
Close

String primes

Statement

 Goal

Determine if the string s is prime, and if not, return its first divisor.

A string is said to be prime if none of the ascii values of its characters divide the sum of every ascii value in the string. Its first divisor is the first character from left to right that divides the sum.

Examples:
ab ------> prime (since nor 97 nor 98 divide 195)
a -------> a (since trivially 97 divides 97)
cab -----> b (since 98 divides 294)
L&r -----> L (L, & and r divide 228 but L comes in first)
!!! -----> !
753 -----> 5
Input
A string s.
Output
The string prime or a character representing the first divisor of s.
Constraints
0 < length s <= 10
The ascii value of every character is between 32 and 126 included.
Example
Input
abc
Output
b

Game modes
Fastest, Shortest

Test cases
Div 1 Test
Input
abc
Output
b

Div 1 val Validator
Input
bac
Output
b

Repeated Test
Input
aaa
Output
a

Repeated val Validator
Input
zzzzz
Output
z

Prime Test
Input
ab
Output
prime

Prime val Validator
Input
ba
Output
prime

Div 2 Test
Input
fgh
Output
g

Div 2 val Validator
Input
hgf
Output
g

Non letters and first div Test
Input
L&r
Output
L

Non letters and first div val Validator
Input
d22
Output
d

Non letters and first div 2 Test
Input
@ @
Output
@

Non letters and first div 2 val Validator
Input
cBc!c!cBc
Output
c

Random 1 Test
Input
[+kt?u/kP4
Output
prime

Random 1 val Validator
Input
yC0c03&lsx
Output
prime

Random 2 Test
Input
na9:Fr5h%p
Output
:

Random 2 val Validator
Input
ZixYEg$jA9
Output
i

Random 3 Test
Input
lr"!pY\Y@*
Output
prime

Random 3 val Validator
Input
'KLG/3O-y8
Output
prime

Random 4 Test
Input
012345678
Output
4

Random 4 val Validator
Input
ii]bb-& +?
Output
-

Solution language

Solution

Stub generator input