aboutsummaryrefslogtreecommitdiff
path: root/challenge-113/abigail/lua/ch-2.lua
blob: 5ba4c04ed9d0b74913c7b7a2b89b4a5e00a846f1 (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-2.lua < input-file
--

for line in io . lines () do
    local sum = 0
    for  n in line : gmatch ("-?[0-9]+")
    do   sum = sum + tonumber (n)
    end
    local c = 0
    for  n in line : gmatch ("-?[0-9]+")
    do   if   c > 0
         then io . write (" ")
         end
         c = c + 1
         io . write (sum - tonumber (n))
    end
    io . write ("\n")
end