Skip to content

Instantly share code, notes, and snippets.

@aclissold
Created October 2, 2013 22:47
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 aclissold/6801645 to your computer and use it in GitHub Desktop.
Save aclissold/6801645 to your computer and use it in GitHub Desktop.
Awesome
-=-=-=- Andrew and Skye's Awesome Adventures: -=-=-=-
-=-=-=- Question 2: Counterfeit Coin Correctness -=-=-=-
Loop invariant:
At the beginning of each recursion, the real doubloon is either in pile
A, B, or C.
Initialization:
Since piles A, B, and C are collectively exhaustive and mutually
exclusive, it is trivial to see that the gold doubloon is amongst them.
Maintenance:
We will weigh piles A and B and return the heavier of them, unless they
are the same weight, in which case we will return pile C.
Termination:
The recursion ends when a pile of size 1 is returned, which must be the
real coin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment