Peteris Krumins personal blog
A Perl Regular Expression That Matches Prime Numbers
Take a look at this Perl regular expression: perl -lne '(1x$_) =~ /^(11+?)\1+$/ && print "$_ is composite"' This regular expression matches only the composite numbers (and doesn't match prime numbers). Can you figure out how it works? I'll give the explanation below but try to figure it…
- Points
- 123
- HN comments
- 27
- Submissions
- 1
- Cited by
- 0 commenters
Software EngineeringMath & Algorithms2011
On Hacker News
| Submitted | Title on HN | Points | Comments |
|---|---|---|---|
| Dec 25, 2011 | A Perl Regular Expression That Matches Prime Numbers by pkrumins | 123 | 27 |