aboutsummaryrefslogtreecommitdiff
path: root/challenge-089/ash/lua/ch-1.lua
blob: 8d9ff3bdda0fe60201513ada1f0f3c896f64dba5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)