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

use strict;
use warnings;
use feature 'say';
use experimental 'signatures';

sub main (@ints) {
    # The last value is '$k'
    my $k = pop(@ints);

    my $count = 0;
    foreach my $i ( 0 .. $#ints - 1 ) {
        foreach my $j ( $i + 1 .. $#ints ) {
            if ( $ints[$i] == $ints[$j] and $i * $j % $k == 0 ) {
                ++$count;
            }
        }
    }

    say $count;
}

main(@ARGV);