Skip to content

Files

Latest commit

692455e · Jul 22, 2020

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jul 22, 2020
Jul 22, 2020

Strategy Coding Exercise

Consider the quadratic equation and its canonical solution - wiki:

ax^{2}+bx+c=0

The part b^2-4ac is called the discriminant. Suppose we want to provide an API with two different strategies for calculating the discriminant:

  1. In OrdinaryDiscriminantStrategy , If the discriminant is negative, we return it as-is. This is OK, since our main API returns Complex numbers anyway.

  2. In RealDiscriminantStrategy , if the discriminant is negative, the return value is NaN (not a number). NaN propagates throughout the calculation, so the equation solver gives two NaN values. In Python, you make such a number with float('nan').

Please implement both of these strategies as well as the equation solver itself. With regards to plus-minus in the formula, please return the + result as the first element and - as the second. Note that the solve() method is expected to return complex values.