↓ Skip to main content

“If there is no match, then the number is prime.”

Avinash Meetoonoulakaz.net ↗

Write the number as a string of ones, then ask the regex engine to split it into equal groups of two or more. If it can, the number is composite. It is trial division wearing a disguise, and backtracking makes it brutally slow on big numbers. Clever party trick. Never ship it.