6 kyu

Solving Quadratics

290 of 328wthit56
Description
Loading description...
Algebra
Fundamentals
  • Please sign in or sign up to leave a comment.
  • Cloud Walker Avatar

    Something's wrong here. Just truncate the solutions to like 3 decimal places. That would turn this into great kata.

  • akar-0 Avatar

    The problem has been pointed out but I could not see an issue raised so I do it: there are issues in Haskell tests:

    Falsifiable (after 2 tests and 7 shrinks):
      -0.1
      0.0
      0.0 expected Single 0.0 but got Single 0.0
    
    Falsifiable (after 2 tests and 5 shrinks):
      0.1
      0.0
      0.0 expected Single (-0.0) but got Single (-0.0)
    
    Falsifiable (after 3 tests and 11 shrinks):
      0.0
      0.1
      0.0 expected Single (-0.0) but got Single (-0.0)
    
  • WestwardLand968 Avatar

    If a = 0, then the equation is not a quadratic.

    This is not adding a layer of complexity to this task, it just makes it unneccessarily long and boring.

    Remove this fixed test.

  • FArekkusu Avatar

    The error messages formatting is broken in JavaScript.

  • FArekkusu Avatar

    The latex text in the description is broken.

  • FArekkusu Avatar

    This comment has been hidden.

  • FArekkusu Avatar

    No sample tests.

  • donaldsebleung Avatar

    [JavaScript] The random test cases do not seem to allow for any floating point errors whatsoever - for a while, my (perfectly valid and efficient) solution was failing, like, 30 tests only because the values returned in my array differed from the expected values by around 0.00000000001. Luckily for me, I was able to eventually guess the order in which the calculations should be performed which allowed my solution to return floating point values that matched the expected results exactly.

  • Iron Fingers Avatar

    Falsifiable (after 2 tests and 1076 shrinks): expected: Single (-0.0) but got: Single (-0.0)

    I see no difference at all between expected and actual. But the test seems to be thinking differently.

  • Daredevil Avatar

    Hey @wthit56, I'm trying to get into algorithms to sharpen my skills and use those abilities to solve more complex katas here, but what's the best articles/books out there you wold recommend me to look into for starters? You seem very knowledgeable on how you write things down, before coding. I'm studying math btw, but I'm not in the Trig/Calc just yet. I'm more in the Algebra 2 level. Unfortunately, I was trying to find a way to contact you a days ago, but I coudn't reach you anywhere outside of codewars. Sorry about that :)

  • mattbrendzel Avatar

    Can't access Math?

    TypeError: Property 'sqrt' of object #<Object> is not a function
       at solveQuadratic
                
    
  • Scopula Avatar

    I don't think you can call Ax^2+Bx+C=0 a quadratic if A = 0...

  • gafiatulin Avatar

    Haskell: Experiencing the same issue as BalinKingOfMoria and jhfung.

    Also:

    Falsifiable (after 3 tests and 1621 shrinks): 
    expected: Two (-8.707266183090575e161) 2.9056140599581754e160
     but got: Two 0.0 (-8.416704777094758e161)
    5.0e-324
    4.1584046815504265e-162
    0.0
    

    Meanwhile:

    ax^2 + bx = 0

    x(ax + b) = 0

    x = 0 or ax + b = 0

    x = 0 or x = -b/a

  • jhfung Avatar

    Haskell: I think there are some floating point issues. I'm experiencing the same problem as BalinKingOfMoria.

  • BalinKingOfMoria Avatar

    Haskell: "Falsifiable (after 2 tests and 1076 shrinks): expected: Single (-0.0) but got: Single (-0.0)" Huh?

  • bkaes Avatar

    The description should probably contain a sentence on what x is. After all, you're looking for a x with Ax² + Bx + C = 0.

  • BalinKingOfMoria Avatar

    Haskell: How can you pass the test "returns a Single solution if a is zero and b is non zero" if "a" being 0 would cause division by 0? Should it be a Single NaN?

  • MattWatt Avatar

    Having issues passing the minimum allowed number of Math.sqrt() calls. It's telling me I have 5, but it needs to be 4 or less. I'm at an impass on how to reduce the problem further. My code passes all of the tests, except for this one. I am checking the discriminants first and only computing sqrt() for the case of two real solutions. I thought perhaps it was the case of sqrt(1) that may be uncessary and easily bypassed, however, that doesn't seem to be the case. I'm now stuck trying to figure out how to satisfy this black box's issue with having an extra sqrt() call. Any suggestions?

  • xamvolagis Avatar

    For some reason Math.sqrt() is not working for me, I get

    TypeError: Property 'sqrt' of object #<Object> is not a function

  • jasonmenayan Avatar

    My code passed the first 6 tests but oddly doesn't pass the 7th (which seems identical to the first...) My error message: For the quadratic equation: 0x2 + 2x + 3, expected: x = -1.5 ([-1.5]); got: found values: x = undefined (-1.5)

    Not sure where I'm going wrong here... Thank you in advance for any help!

  • laoris Avatar

    Here's a type of quadratic equation I don't believe is explicitly tested, but could be to slightly increase difficulty: equations where B = √(4AC) and A, B, and C are nonzero. For instance, y = x² + 2x + 1 (i.e., A = 1, B = 2, C = 1). In this case, the value inside the quadratic formula's radical is zero, so we shouldn't really have to call sqrt.

    On the other hand, I guess this is sort of hard-coding a value in the solution (in that we know the square root of zero is itself), and opens the door to hard-coding other values in the solution, like substituting 1 for the radical when B² - 4AC = 1, or even substituting 2 when B² - 4AC = 4.

  • transGLUKator Avatar

    This comment has been hidden.

  • user2713389 Avatar

    This comment has been hidden.

  • ohwowle0js Avatar

    This comment has been hidden.

  • ohwowle0js Avatar

    For the quadratic equation: 0x2 + 0x + 0, expected: cannot find x; got: x = undefined

    How is this different?

  • bkaes Avatar

    There's something strange going on in the test cases. I use console.log to log my result before I return it, and my result is the expected result. But the test fails with "got x = undefined" in several cases.

  • xcthulhu Avatar

    Hey, here's a better image you could use...

    x = (-b ± √(b^2 - 4 a c)) / 2 a

  • suuuzi Avatar

    Hi,

    I'm getting "For the quadratic equation: 0x2 + 2x + 3, expected: x = -1.5; got: cannot find x" I'm coding to when a === 0, return undefined, because you cannot divide by 0 (to found x: (stuff) / 2 * a).

    The description confused me when said a, b, c could be 0.

  • tebatalla Avatar

    I'm getting a different number of passes and failures everytime I submit. Also getting my errors cut off at the end with "expected x = undefined, instead got x = u"

  • mlabrum Avatar

    I'm not sure if it's my code or something in the test cases, but I keep getting the following error:

    ReferenceError: input is not defined
        at test
        at resultingSQRTs
        at Array.forEach
    

    A random number of tests are passed each time before that error arises, and I have not yet discovered an association between the input values and that error message.