regular expressions
Regular Expression To Check For Prime Numbers
The code is in python, but the concept is the same for any language with regular expression support (perl, sed, awk, vim, etc..)
1 2 3 | import re def is_prime(n): return re.match(r'^1?$|^(11+?)\1+$', "1" * n) == None; |
That’s it
using a regular expression we can check if a number is prime or not.
Here is a short explanation of why it works (though it will ruin the magic part):
› Continue reading
About Me
Tags
Bash
Collaboration
Command Line Interface
Courses
Debug
Ebooks
Email
Facebook
Firefox
Gnome
Google
Hardware
Illusions
Linux
Linux Development
Macros
Manpages
Multimedia
Networks
Object Oriented Programming
Off-Topic
Open Knowledge
Operating Systems
Productivity
Programming
Religion
Science
Security
sed
Sharing
Shell Scripts
Short Posts
Small Code
Social Media
Studies
Terminal
TIps
Tools
Troubleshooting
Ubuntu
University
Vim
Web Development
Web Services
Websites
Categories
- Algorithms
- Bash
- BlackBerry
- Collaboration
- Command Line
- Cool Tricks
- Easter Eggs
- Ebooks
- Firefox
- Hardware
- Humor
- iPhone
- Linux
- Linux Development
- Linux Kernel
- Networks
- Open Knowledge
- Other
- Productivity
- Programming
- Regular Expressions
- Science
- Security
- Shell Scripts
- Short Posts
- Social Networks
- Thoughts
- Tools
- Vim
- Web Development
- Websites
Popular Posts
Calendar
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| « Sep | ||||||
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | |||
Archives
- September 2010 (2)
- August 2010 (2)
- July 2010 (5)
- June 2010 (1)
- May 2010 (1)
- April 2010 (3)
- March 2010 (1)
- January 2010 (1)
- December 2009 (2)
- September 2009 (13)
- July 2009 (1)
- June 2009 (6)
- May 2009 (4)
- March 2009 (18)
- February 2009 (10)
- January 2009 (10)
- December 2008 (7)
- November 2008 (8)
- October 2008 (1)
- August 2008 (1)
- July 2008 (1)
- June 2008 (1)
