aboutsummaryrefslogtreecommitdiff
path: root/challenge-116/abigail/lua/ch-2.lua
blob: f53ea72076e055b926eb94c8d9955199b6b7976f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/opt/local/bin/lua

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

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

for line in io . lines () do
    local sum_of_squares = 0
    for d in line : gmatch ("%d") do
        local number = tonumber (d)
        sum_of_squares = sum_of_squares + number * number
     end
     root = math . floor (.5 + math . sqrt (sum_of_squares))
     if   sum_of_squares == root * root
     then print (1)
     else print (0)
     end
end