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

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

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

local a = {}
local b = {}

local a_line = io . read ("*l")
local b_line = io . read ("*l")

for n in a_line : gmatch ("-?[0-9]+") do
    a [#a + 1] = tonumber (n)
end
for n in b_line : gmatch ("-?[0-9]+") do
    b [#b + 1] = tonumber (n)
end

local sum = 0

for i = 1, #a do
    sum = sum + a [i] * b [i]
end

print (sum)