Created
December 2, 2023 07:57
-
-
Save mb6ockatf/b0adeafbf94c59b88c35596b15c6c112 to your computer and use it in GitHub Desktop.
greatest common divisor by euclid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env lua | |
euclid_gcd = {} | |
function euclid_gcd.var1(m, n) | |
local r = 1 | |
while r ~= 0 do | |
r = m % n | |
m = n | |
n = r | |
end | |
return m | |
end | |
function euclid_gcd.var2(m, n) | |
while true do | |
m = m % n | |
if m == 0 then return n end | |
n = n % m | |
if n == 0 then return m end | |
end | |
end | |
return euclid_gcd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment