Algorithms · real, tested code

Find the Greatest Common Divisor (GCD) in Larzscript

Compute the greatest common divisor of two numbers with the Euclidean algorithm - and see every step.

mathx.explain_gcd() doesn't just return the answer, it returns the full division-by-division trace, the same way you'd work it out by hand.

larzscript pkg install mathx

Code

import "mathx" as mathx

print(mathx.explain_gcd(48, 18))
Output
48 = 2*18 + 12
18 = 1*12 + 6
12 = 2*6 + 0
gcd = 6