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

#
# See ../README.md
#
 
#
# Run as: ruby ch-2.rb < input-file
#

ARGF . each_line do
    |line|
    sum_of_squares = 0
    line . split('') . each do
        |char|
        if   "1" <= char && char <= "9"
        then sum_of_squares += (char . to_i) ** 2
        end
    end
    puts (sum_of_squares == (Math . sqrt (sum_of_squares) . round) ** 2 ? 1 : 0)
end