Just another Perl shrine  
PerlMonks 
The Oldest Plays the Pianoby casiano (Pilgrim) 
on Sep 21, 2009 at 16:53 UTC ( #796576=perlmeditation: print w/replies, xml )  Need Help?? 
According to the legend, it was abigail the first who started to
solve Diophantine equations using regular expressions. A Diophantine equation is an indeterminate polynomial equation that allows the variables to be integers only. Perl5.10 regexes provide extensions that make much easier to begin to deal with nonlinear Diophantine equations. The following story sets a mathematical challenge that leads to a system of two Diophantine equations:
The problem is to know the ages of the three daughters. The following code uses the matching ('1'x72) =~ /^((1+)\2+)(\1+)$(?{ f($1, $2, $3) })(*FAIL)/ to produce all the solutions of the Diophantine equation x*y*z = 72: When executed, this program produces the set of triples whose product is 72. The second column contains the potential number on the mentioned building: Only if the number on that building is 14 there is more than one solution. All other cases produce a single solution. But the first math grad, in spite of having access to the two equations still says: "Right, ok... Oh wait... Hmm, I still don't know."Thus the number of the building was 14 and the solution is one of:
... but we know the "oldest one just started to play the piano". Do you know of other "freak" examples of using regexes to solve combinatorial problems?
Back to
Meditations

