You will write the division algorithm yourself, test divisibility, and list the remainders that squares can leave.
The idea. For the quotient is the number of times you can take away from before you go below . For a negative you add instead, until you reach or more. The remainder is what is left, and .
Your tasks.
divide(a, b). Return the pair (q, r) with a == b * q + r and 0 <= r < b. Use a loop that adds or takes away b, not // or %.divides(d, n). Return True when d divides n. You may use divide from task 1.square_remainders(b). Return the sorted list of the different remainders of n * n on division by b, for n from 0 to b - 1.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…