Pre-Calculus for Programmers
A factoring assistant
A homework tool is going to suggest a factorisation of . The step it needs help with is the search from the lesson on factoring: find two whole numbers whose sum is b and whose product is c, because those two numbers are what goes inside the brackets.
Given b and c, return the pair as a list of two numbers with the smaller first. If no pair of whole numbers works, return an empty list, which is the tool's way of saying the trinomial does not factor over the whole numbers.
Input: b = -5, c = 6
The product 6 is positive and the sum -5 is negative, so both numbers are negative.
Pairs multiplying to 6: (-1, -6) sums to -7, (-2, -3) sums to -5.
Output: [-3, -2] because -3 + -2 = -5 and -3 * -2 = 6,
and the smaller of the two comes firstInput: b = 1, c = 1 Output: [] nothing works
Input: b = -2, c = 1 Output: [-1, -1] the same number twice is allowed
Input: b = 5, c = 0 Output: [0, 5] 0 * 5 = 0 and 0 + 5 = 5b is from to 1000 and c is from to 10000.[-3, -2] and never [-2, -3].Run your code to see how it does on the examples. Submit also runs the hidden cases.