XP is just a number PerlMonks

### Re^3: solve cubic equations (Python)

by vrk (Chaplain)
 on May 04, 2017 at 07:57 UTC ( #1189483=note: print w/replies, xml ) Need Help??

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

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 hackerrank.com 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.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1189483]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2023-02-05 13:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?