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
Related
larzmathSmall math helpers→FizzBuzz in LarzscriptThe classic interview warm-up: print 1 to N, but Fizz for multiples of 3, Buzz for multiples of 5, FizzBuzz for both.→Reverse a String in LarzscriptFlip a string end to end - one of the smallest real string algorithms, and a good first look at the str package.→Check if a String is a Palindrome in LarzscriptDetect whether a string reads the same forwards and backwards, ignoring case, spaces and punctuation.→