aboutsummaryrefslogtreecommitdiff
path: root/challenge-126/abigail/lua/ch-1.lua
blob: 59c1677759836bf26b9dcb1df9f3ebe7f203be4d (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
#!/opt/local/bin/lua

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

--
-- Run as: lua ch-1.lua < input-file
--

for line in io . lines () do
    local result   = 0
    local seen_one = false
    for c in line : gmatch ("[0-9]") do
        result = result * 9
        if seen_one then
            result = result + 8
        elseif c == "1" then 
            seen_one = true
        elseif not (c == "0") then
            result = result + tonumber (c) - 1
        end
    end
    print (result)
end