 new example (in progress)

parent 4161b62b
 (* 8 balls, one is lighter than the others Given a Roberval balance, use it only twice to find the lighter ball *) module Balance use import int.Int use import array.Array let solve3 (balls: array int) (s: int) (ghost lb: int) (ghost w: int) : int requires { 0 <= s && s+3 <= length balls } requires { s <= lb < s+3 } requires { forall i: int. s <= i < s+3 -> i <> lb -> balls[i] = w } requires { balls[lb] < w } ensures { result = lb } = absurd let solve8 (balls: array int) (ghost lb: int) (ghost w: int) : int requires { length balls = 8 } requires { 0 <= lb < 8 } requires { forall i: int. 0 <= i < 8 -> i<> lb -> balls[i] = w } requires { balls[lb] < w } ensures { result = lb } = if balls + balls + balls < balls + balls + balls then solve3 balls 0 lb w else if balls + balls + balls > balls + balls + balls then solve3 balls 3 lb w else if balls < balls then 6 else 7 end
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!