
Famous Perl One-Liners Explained, Part III: Calculations - epi0Bauqu
http://www.catonmat.net/blog/perl-one-liners-explained-part-three/
======
mustpax
The prime number detector is quite clever. It reminds me of the number based
logic constructs from Godel's incompleteness theorem. It's essentially maps a
mathematical concept to a string and operates on it.

For any unary integer greater than 1, the regular expression /^(11+?)\1+$/
matches it iff the number is not a prime. In other words, if there exists no
integer less than the number itself and greater than one (first capturing
group) that is a divisor of the number. The non-greedy + is also a nice touch,
it will start out from the smallest factors and build from there.

~~~
nazgulnarsil
that impressed me the most as well. the least lines I could do it in was 4.

the others I wasn't necessarily able to think of the one liner before checking
the answer but I at least had a general idea of how it might be done. the
primes completely stumped me.

------
pkrumins
Today I am low on creativity and can't think of more cool calculations. Can
anyone help me out?

I just thought of one actually - sum up the size of files in a directory.

Can you think of more? ... Anything that comes to your mind.

~~~
JeremyStein
Somebody asked me today how to write a script that would find all phrases (1
or more sequential words) in a text that appear more than once.

