blob: a4b697b0376b8729b26f3c8f219592f6efc7cb58 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/usr/bin/env perl
use Modern::Perl;
use Algorithm::Combinatorics 'combinations';
use List::Util 'all';
# Usage: perl ch-1.pl @N $k
# Example: perl ch-1.pl 2 7 9 2
# Output: 2,1
die "Usage: perl ch-1.pl \@N \$k" unless all { /\A\d+\z/ } @ARGV;
my $k = pop @ARGV;
my $combo = combinations([keys @ARGV], 2);
while (my $indices = $combo->next) {
my ($i, $j) = $indices->@*;
say "$j,$i" if $ARGV[$j] - $ARGV[$i] == $k;
}
|