 ### new example for balance

parent 37162168
 ... ... @@ -50,3 +50,67 @@ module Balance if balls < balls then 6 else 7 end module Balance12 use import int.Int use import array.Array (* All values in balls[lo..hi[ are equal to [w], apart from balls[lb] which is of a different weight (lighter or heavier) . *) predicate spec (balls: array int) (lo hi j: int) (w: int) (b: bool) = 0 <= lo <= j < hi <= length balls && (forall i: int. lo <= i < hi -> i <> j -> balls[i] = w) && (if b then balls[j] < w else balls[j] > w) (* j : the index of the different ball, b : the status (lighter or heavier) of the different ball False True meaning heavier and True meaining lighter *) let solve12 (balls: array int) (ghost w j: int) (ghost b: bool) : (int, bool) requires { spec balls 0 12 j w b } ensures { result = (j, b) } = if balls + balls + balls + balls = balls + balls + balls + balls then if balls + balls = balls + balls then if balls < balls then (11, False) else (11, True) else if balls + balls < balls + balls then if balls = balls then (8, True) else if balls < balls then (10, False) else (9, False) else if balls = balls then (8, False) else if balls < balls then (9, True) else (10, True) else if balls + balls + balls + balls < balls + balls + balls + balls then if balls + balls + balls = balls + balls + balls then if balls = balls then (3, True) else if balls < balls then (7, False) else (6, False) else if balls + balls + balls < balls + balls + balls then if balls = balls then (5, False) else if balls < balls then (0, True) else (1, True) else if balls = balls then (2, True) else (4, False) else if balls + balls + balls = balls + balls + balls then if balls = balls then (3, False) else if balls < balls then (6, True) else (7, True) else if balls + balls + balls < balls + balls + balls then if balls = balls then (4, True ) else if balls < balls then (5, False) else (2, False) else if balls = balls then (5, True) else if balls < balls then (1, False) else (0, False) end \ No newline at end of file
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!