aboutsummaryrefslogtreecommitdiff
path: root/challenge-151/abigail/lua/ch-2.lua
blob: d8ac15c101ba3718164d941998740d2d225f0790 (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 https://theweeklychallenge.org/blog/perl-weekly-challenge-151
--

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

for line in io . lines () do
    local h = {}
    for val in line : gmatch ("%d+") do
        h [#h + 1] = val
    end

    h [#h + 1] = 0
    h [#h + 1] = 0

    for i = #h - 2, 3, -1 do
        h [i] = math . max (h [i] + h [i + 2], h [i + 1])
    end

    print (h [1] + h [3])
end