aboutsummaryrefslogtreecommitdiff
path: root/challenge-252/e-choroba/perl/ch-1.pl
blob: 6b5022d0c3e8fab520ba8f27161229f33fce47a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/perl
use warnings;
use strict;
use experimental qw( signatures );

use List::Util qw{ sum };

sub special_numbers(@ints) {
    my @s = @ints[grep 0 == @ints % ($_ + 1), 0 .. $#ints];
    return sum(map $_ * $_, @s)
}

use Test::More tests => 2;

is special_numbers(1, 2, 3, 4), 21, 'Example 1';
is special_numbers(2, 7, 1, 19, 18, 3), 63, 'Example 2';