in reply to Re^2: solve cubic equations (Python)
in thread solve cubic equations

use bignum;

Replies are listed 'Best First'.
Re^4: solve cubic equations (Python)
by no_slogan (Deacon) on May 04, 2017 at 13:37 UTC
    Try and solve a few problems on that way. Their cpu time restrictions are usually too stringent for Math::BigInt, even with a "fast" backend. Python ints are built-in, bignum is an afterthought.
      Show me a hackerrank problem that can't be solved in Perl because of time restrictions.

      The only one I haven't been able to solve in Perl was PRNG Sequnce Guessing, so I solved it in Java. But the problem wasn't the time constraint, but the different behaviour of bit operators on big numbers.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
        Now that I've had some time to kick it around, this is actually a great example. My Python program solves the sample problem in 1 second. In Perl, using Math::BigInt with the default backend, it takes 10 seconds. With the GMP backend, 5 seconds. With Math::GMP, 1 second, same as Python. By resorting to vile trickery, I was able to get the Perl to run in 0.5 seconds with no modules at all. Here's the kicker, though: the Python program runs in 0.1 second under PyPy (basically JIT compiled Python).

        Oh look, it's basically the same problem I solved in my old node, Predict Random Numbers. Fifteen years ago. Back then, there wasn't so much information available online, so I actually had to get on my bike and ride to the Stanford math department library to find that algorithm.

        That problem involves 48-bit numbers, which really aren't all that big. Maybe try something in the Number Theory category.

        Update: Haha, we didn't have youtube back then either.