Mathematics
Algorithms
Logic
Numbers
Mathematics
Algorithms
Logic
Numbers
Fun with regexp
import re def prime_checker(n): return re.match(r'^1?$|^(11+?)\1+$', '1' * n) == None
from math import sqrtprimes = [2]- import re
- def prime_checker(n):
global primesfor p in primes:if n == p:return Trueif n % p == 0:return Falsefor c in range((l := primes[-1]) + l % 2 + 1, int(sqrt(n)), 2):if prime_checker(c):primes.append(c)if n % c == 0:return Falsereturn True- return re.match(r'^1?$|^(11+?)\1+$', '1' * n) == None