You will list every candidate for a polynomial with integer coefficients and keep the ones that are roots. Use exact fractions, so that no rounding can hide a root.
The idea. runs over the divisors of the constant term and over the divisors of the leading coefficient, with both signs. Test each candidate with Horner's rule.
Your tasks.
divisors(n). Return the positive divisors of abs(n), in increasing order.candidates(coeffs). Return the sorted list of different fractions .rational_roots(coeffs). Return the candidates that are roots.Run your code once to unlock the worked solution.
Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…