http://qs1969.pair.com?node_id=1189419


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

Not sure what the advantage of Python is in this case. Your code is basically the same, except that it doesn't have any dollar signs or semicolons. I never liked Python's "x if cond else y" as a replacement for "cond ? x : y", it just doesn't seem right to put the condition in the middle of the expression. But I have to admit that Python's built-in multiple precision ints are a huge advantage for certain kinds of math programming.

Replies are listed 'Best First'.
Re^3: solve cubic equations (Python)
by vrk (Chaplain) on May 04, 2017 at 07:57 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,
Re^3: solve cubic equations (Python)
by Anonymous Monk on May 03, 2017 at 16:43 UTC
    "Your code is basically the same, except that it doesn't have any dollar signs or semicolons."

    Precisely why it looks more like MATHS. :)

      > > "Your code is basically the same, except that it doesn't have any dollar signs or semicolons."

      > Precisely why it looks more like MATHS. :)

      You don't like sigils?

      Try this

      use strict; use warnings; $,="\t"; my ($a,$b,$c); sub A() :lvalue { $a }; sub B() :lvalue { $b }; sub C() :lvalue { $c }; A = 1; B = A + 1; C = A + B; print A, B, C, B**3, sqrt(B);

      1    2    3    8    1.4142135623731

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      A reply falls below the community's threshold of quality. You may see it by logging in.