Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Double Prime Words

Consider a word/string of length \$n\$, only including the letters A-Z, a-z. A word/string is a double prime word if and only if n is prime and the sum of the letters, s, is also prime, using their numeric position in the alphabet (a=1, B=2, c=3, etc.).

Input can be any combination of upper or lower case alphabetic characters, as there is no numeric difference between a or A.

Output is any appropriate logical format related to your language. i.e. True or False, T or F, 1 or 0, etc. Specifying what format your output will appear is highly appreciated, but not required. (Output need not include n, s, but I include them below as demonstration and example)

Winning condition is shortest code in bytes able to detect if a string is a double prime, fitting both conditions for n and s to be prime. (I've now included cases from all 4 possible situations of n, s.)

Examples

Input -> Output (n, s)
Prime -> True (5, 61)
han -> True (3, 23)
ASK -> True (3, 31)
pOpCoRn -> True (7, 97)
DiningTable -> True (11, 97)
METER -> True (5, 61)
Hello -> False (5, 52)
SMILE -> False (5, 58)
frown -> False (5, 76)
HelpMe -> False (6, 59)
John -> False (4, 47)
TwEnTy -> False (6, 107)
HelloWorld -> False (10, 124)
Donald -> False (6, 50)
telePHONES -> False (10, 119)
A -> False (1, 1) 
C -> False (1, 3) {1 is not prime}
d -> False (1, 4)

Answer*

Draft saved
Draft discarded
Cancel
3
  • 1
    \$\begingroup\$ Everything except false and nil is truthy in Ruby. ruby-for-beginners.rubymonstas.org/conditionals/…. \$\endgroup\$ Commented Sep 13, 2020 at 6:11
  • 1
    \$\begingroup\$ 50 bytes \$\endgroup\$ Commented Sep 13, 2020 at 6:42
  • \$\begingroup\$ Thanks Razetime! That's a neat trick, I don't understand why that works, but it's good to learn! \$\endgroup\$ Commented Sep 13, 2020 at 6:52

AltStyle によって変換されたページ (->オリジナル) /