Skip to content

Instantly share code, notes, and snippets.

@Zuza
Created December 6, 2015 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zuza/36b5ea4d199d14d8f22c to your computer and use it in GitHub Desktop.
Save Zuza/36b5ea4d199d14d8f22c to your computer and use it in GitHub Desktop.
This example tells you the story (I've coded it up, no idea how to solve it deductively):
(1, 37, 220)
(2, 36, 220)
(4, 36, 218)
(8, 32, 218)
(16, 32, 210)
(32, 32, 194)
(0, 64, 194)
It's always possible. Proof:
- Let our state be (A, B, C) where A <= B <= C.
- By the remainder theorem write B = A*x + r where r < A.
- It is enough to find a process that sets the minimum to r,
hence lowers the minimum of the state in each step.
- Let h be largest int such that 2^h <= x.
- We double A in each step (A, 2^1 A, 2^2 A, ..., 2^h A)
- the only question is where do the chips come from (B or C)
- if in step 2^k we have that (x>>k)&1 is set,
we substract it from B, otherwise from C
- what's the maximum amount of chips we take from C?
- answer: 1 + 2 + ... + 2^(h-1) < 2^h <= B <= C, so we won't take too much
- After the process A is replaced with r, so the minimum shrinks (strictly)
- Repeat process until A = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment