Build provably correct software using formal methods like Hoare Logic, Weakest Preconditions, and Design-by-Contract.
99
Quality
100%
Does it follow best practices?
Impact
99%
1.45xAverage score across 5 eval scenarios
The following algorithm calculates the Greatest Common Divisor (GCD) for two positive integers:
def calculate_gcd(a, b):
x = a
y = b
while x != y:
if x > y:
x = x - y
else:
y = y - x
return xRequirements:
Produce a Python file gcd_verified.py with the provided algorithm and the full formal verification documented in the comments.