aboutsummaryrefslogtreecommitdiff
path: root/challenge-116/dave-jacoby/perl/ch-2.pl
blob: af368b69ca51618e3f72e6943dc2e53a9fa98627 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env perl

use strict;
use warnings;
use feature qw{ postderef say signatures state };
no warnings qw{ experimental };

use List::Util qw{sum0};

my @numbers = sort (34, 50, 52, 10 );

for my $n ( @numbers ) {
    my $b = sum_of_squares($n);
    say join "\t", $n,$b?'Yes':'No';
}

sub sum_of_squares ( $n ) {
    my $sum = sum0 map { $_ ** 2 } split //, $n;
    my $root = sqrt $sum;
    return int $root == $root ? 1 : 0 ;
}