Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
18-liner: by primes for fun solution in 3rd party category for All Upper I by przemyslaw.daniel
from contextlib import suppress
from functools import reduce
from sympy import prime
from math import gcd
LOWER = 1384096573029127477274111072084485853924710240181310093982703945448241409
'''
LOWER = prime(ord('a')) * prime(ord('b')) * ... * prime(ord('z'))
therefore if non empty string doesn't contain any lower case then
gcd(ord(t[0])) * prime(ord(t[1])) * ... * prime(ord(t[-1]), LOWER) == 1
'''
def is_all_upper(text):
with suppress(TypeError):
product = reduce(int.__mul__, map(prime, map(ord, text+'A')))
return gcd(product, LOWER) == 1
return False
March 9, 2020
Comments: