aboutsummaryrefslogtreecommitdiff
path: root/challenge-139/abigail/lua/ch-2.lua
blob: bc970a0db19cb0eef467f0faa91b0b78fe797d97 (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/opt/local/bin/lua

--
-- See ../README.md
--

--
-- Run as: lua ch-2.lua
--

local BASE  = 10
local COUNT =  5

function is_long (number)
    local rest = 0
    local seen = {}

    for _ = 2, number do
        rest = (rest * BASE + BASE - 1) % number
        if (seen [rest] ~= nil) then
            return (0)
        end
        seen [rest] = 1
    end

    return (1)
end


local number = 1
while COUNT > 0 do
    number = number + 1
    if BASE % number == 0 then
        goto end_loop
    end
    if is_long (number) == 1 then
        print (number)
        COUNT = COUNT - 1
    end
    ::end_loop::
end