diff options
author | Igor <pashev.igor@gmail.com> | 2011-02-20 18:50:55 +0300 |
---|---|---|
committer | Igor <pashev.igor@gmail.com> | 2011-02-20 18:50:55 +0300 |
commit | 80a2e9adbbbf71a0acbb81ca6d8a708b5b79e7bd (patch) | |
tree | 5f0e93e75231418a9d4abdf0e840ce83d6ac89b1 | |
parent | 3166b45e610d6defacf66a67b850f978dd7f2634 (diff) | |
download | gcd-80a2e9adbbbf71a0acbb81ca6d8a708b5b79e7bd.tar.gz |
Lua
-rwxr-xr-x | gcd.lua | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -0,0 +1,25 @@ +#!/usr/bin/env lua + +-- SYNOSPSIS: +-- # chmod +x gcd.lua; ./gcd.lua 121 22 33 44 +-- # lua gcd.lua 121 33 22 + +-- http://www.lua.org/pil/6.3.html +function gcd2(a, b) + if b == 0 then + return a + else + return gcd2(b, a % b) + end +end + +function gcdn(ns) + r = ns[1] + for i = 2, table.maxn(ns) do + r = gcd2(r, ns[i]) + end + return r +end + +print(gcdn(arg)) + |