You will write three small functions that choose the boxes of a pigeonhole argument and test it.
The idea. For a difference divisible by , the box of a number is its remainder x % m. For a sum or a difference divisible by , the remainders and share a box. We can label that box by the smaller of the two.
Your tasks.
fewest_for_pair(colours). Return the fewest socks that make sure of two of one colour.same_remainder(numbers, m). Return a pair (a, b) of numbers from the list with the same remainder on division by m, or None if there is no such pair.pair_box(x, m). Return the box of x when and share a box: the smaller of x % m and (m - x % m) % m.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…