isPrime in One Line of Perl
Tuesday, July 17th, 2007As a follow up to Finding the first 20 terms in the Fibonacci Series, next in the 3Monkey Golf series — Determining if a number is prime. The following is a fairly simple Perl one liner to do the trick. I’m interested in seeing implementations in other languages. I will be posting follow ups with the best submissions from both Golf challenges at the end of the week.
Perl Code
perl -wle'print(1)if(1xtarget_number)!~/^1?$|^(11+?)\1+$/'
Character count = 36
Golf Rules:
Please note that use og characters such as > and < require escaping as & lt; and & gt;
If you have difficulty posting your solution please email me the solution at stacy (at) 3monkeyweb (period) com and I will make sure it gets posted.
Good luck, and until next time.
-3Monkeys
Popularity: 28% [?]












