aboutsummaryrefslogtreecommitdiff
path: root/challenge-089/ash/lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-089/ash/lua')
-rw-r--r--challenge-089/ash/lua/ch-1.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-089/ash/lua/ch-1.lua b/challenge-089/ash/lua/ch-1.lua
new file mode 100644
index 0000000000..8d9ff3bdda
--- /dev/null
+++ b/challenge-089/ash/lua/ch-1.lua
@@ -0,0 +1,24 @@
+-- How to run:
+-- $ lua ch-1.lua 100
+-- 13015
+
+function gcd(a, b)
+ while b > 0 do
+ t = b
+ b = a % b
+ a = t
+ end
+
+ return a
+end
+
+n = arg[1] and arg[1] or 3
+
+s = 0
+for x = 1, n do
+ for y = x + 1, n do
+ s = s + gcd(x, y)
+ end
+end
+
+print(s)