Divisible pairs
Task 1 supplies us with a list of integers and asks us to count the pairs selected from the list whose sums are divisible by a supplied integer.
The obvious way to do this is to generate all the pairs and check their divisibility by the given divisor. All the examples given include only unique positive integers. The task is not significantly different if zero and negative integers are included, but if the same integer appears more than once (eg list = 1, 2, 3, 3, divisor = 4) do we count distinct pairings (1 and the first 3, 1 and the second 3) or merely distinct pairs (just 1 and 3).
Reduce to nothing
Task 2 as stated is impossible. Applying the supplied rules to any pair of starting x and y will never result in both x and y reaching zero, because:
- Each operation reduces either x and y and leaves the other unchanged
- So the values before the last operation would have to be (0, n) or (n, 0) where n > 0
- But that isn't possible because subtracting 0 from n cannot result in 0.
- After each operation, x + y always reduces, but cannot become negative
- There cannot therefore be more than x + y - 1 steps, even if each step only reduces x + y by 1
- Unless x or y is zero, it is always possible to make another step
No comments:
Post a Comment