in reply to Primes

I'm not sure if this goes in "Craft" or "Obfuscated", but it is cool.

I suppose it would be possible for some deranged individual to create a Math::Regexp module, that does all math calculations via regular expressions... First person to do so wins Stephen's Too Much Time On Their Hands Award (TMTOTH).

stephen

Replies are listed 'Best First'.
RE: RE: Primes
by japhy (Canon) on Apr 09, 2000 at 00:14 UTC
    Regular expressions can be made to solve diophantine equations! Please examine:
    # for the equation: 3x + 2y + 10z = 50 ($x,$y,$z,$ans) = (3,2,10,50); $xpat = 0 x $x; $ypat = 0 x $y; $zpat = 0 x $z; if ((0 x $ans) =~ /^ ((?:$xpat)+) ((?:$ypat)+) ((?:$zpat)+) $/x) { print "x = ", length($1)/$x, "\n"; print "y = ", length($2)/$y, "\n"; print "z = ", length($3)/$z, "\n"; }
    You can change this by making them * instead of +, or *? or +?. Isn't it sick?