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

#
# See ../README.md
#

#
# Run as: python ch-2.py < input-file
#

import fileinput
from math import sqrt

for line in fileinput . input ():
    sum_of_squares = 0
    for char in line:
        if "1" <= char and char <= "9":
            sum_of_squares = sum_of_squares + int (char) * int (char)
    root = int (.5 + sqrt (sum_of_squares))
    if sum_of_squares == root * root:
        print (1)
    else:
        print (0)