PDA

View Full Version : Weird prime tests


Chruser
2024-12-24, 07:39 PM
What's your strangest way to check if a number is prime? Here's a Python one using regex:

import re
def is_prime(n):
return not re.match(r"^.?$|^(..+?)\1+$","\0"*n)

WetWired
2024-12-30, 09:21 AM
I find it hard to believe that a regex could identify primeness. My recollection is that encryption keys are usually not exhaustively proven but only proven “likely prime”