Friday, August 13, 2004

Fun With Perl

Came across this wonderful piece of code :
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$^(11+?)\1+$/'

It finds out whether the number that you passed is a prime number or not. All this by just string matching! This was posted by someone called Abigail.

To read an explanation, go to http://montreal.pm.org/tech/neil_kandalgaonkar.shtml

The Marketing guys would not like this though!

One of the shortcomings of this is that it would take large memory for big numbers, and would slow down too. But the idea is beautiful.

No comments: