Skip to content

Instantly share code, notes, and snippets.

@mb6ockatf
Created December 2, 2023 07:57
Show Gist options
  • Save mb6ockatf/b0adeafbf94c59b88c35596b15c6c112 to your computer and use it in GitHub Desktop.
Save mb6ockatf/b0adeafbf94c59b88c35596b15c6c112 to your computer and use it in GitHub Desktop.
greatest common divisor by euclid
#!/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