rohanverma.net
Checking if a number is prime using Regex
def is_prime(n): return not re.match(r'^.?$|^(..+?)1+$', '1'*n) This works by first converting the number to unary, i.e. 5 will be ‘11111’ and 3 will be ‘111’ and so on. First, …