You will write three functions for the number pigeonholes of this lesson: prefix sums, a block with a sum divisible by the length of the list, and the odd part of a number.
The idea. The prefix sums of a list of numbers are . Two of them share a remainder on division by , and the numbers between them form the block. The odd part of a number is what is left after dividing out every factor .
Your tasks.
prefix_sums(numbers). Return the list , starting with 0.divisible_block(numbers). Return a pair (i, j) with i < j such that sum(numbers[i:j]) is divisible by len(numbers).odd_part(n). Divide n by 2 while it is even, and return what is left.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…