Hi, Thanks for the tip - I actually started with: use bigrat, but removed it because it made everything really slow - about 10 times slower than without (plus program still worked without on my test cases).
Any ideas for modules that will do the same (only faster) ? On 28 March 2012 23:52, Shlomi Fish <[email protected]> wrote: > Hi Ynon, > > On Wed, 28 Mar 2012 10:55:44 +0200 > ynon perek <[email protected]> wrote: > > > Hi All, > > > > A student asked me for a perl solution to the problem at the bottom. > > > [SNIPPED] > > > > Write a program that takes a list of numbers, a list of operators, and a > > goal; and tells the user which mathematical operations must be performed > to > > reach the goal. For example, given the input: > > numbers: 2, 4, 6, 8 > > operators: +, -, *, / > > goal: 25 > > > > Program should produce the output: > > sol = (((2 / 8) + 6) * 4) > > ---- > > Just a note - I hope here would be OK. You should use a rational numbers > package (a.k.a "fractions" - see for example > https://metacpan.org/module/Math::BigRat or > https://metacpan.org/module/Math::GMPq ) > instead of relying on floating-point numbers for solving such riddles, > because > otherwise, you might have some rounding errors. I recall facing a problem, > where I was trying to write a Perl program to brute force such a riddle > which > I had some problems with, and it did not yield the exact solution due to > this > issue. > > For more inforamation about why this is an issue, see: > > http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html > > «What Every Computer Scientist Should Know About Floating-Point Arithmetic» > > Regards, > > Shlomi Fish > > -- > ----------------------------------------------------------------- > Shlomi Fish http://www.shlomifish.org/ > What does "Zionism" mean? - http://shlom.in/def-zionism > > If his programming is anything like his philosophising, he would find ten > imaginary bugs in the “Hello World” program. > > Please reply to list if it's a mailing list post - http://shlom.in/reply . >
_______________________________________________ Perl mailing list [email protected] http://mail.perl.org.il/mailman/listinfo/perl
