AP Computer Science Quiz
In algebra, for polynomials of the form ax2 + bx + c = 0, the solutions for x are (-b ± sqrt(b2 - 4ac)) / 2a.
In Scheme, we can take two numbers and put them into a list by using the list function: (list num1 num2).
Write a function called quadratic which has three parameters, a, b, and c. It returns a list of all possible solutions to ax2 + bx + c = 0.
For this problem, assume that a solution means a real number, so if the discriminant (b2 - 4ac) is less than zero, your program should return an empty list. If the two solutions are the same, the list should contain the one solution, not two instances of the same solution.
> (quadratic 1 0 -1) ; x2 - 1 = 0 (1 -1) > (quadratic 1 5 6) ; x2 + 5x + 6 = 0 (-2 -3) > (quadratic 1 -2 1) ; x2 - 2x + 1 = 0 (1) > (quadratic 1 2 2) ; x2 + 2x + 2 = 0 ()
Note that the order of results does not matter. (quadratic 1 5 6) could just as easily have returned (-3 -2).
Hint: You might first wish to write a function called discriminant which returns b2 - 4ac.