• + 2 comments

    Perl:

    sub pairs {
        my $k = shift;
        my $arr = shift;
        my $res = 0;
    
        my %h = map {$_ => 1} @$arr;
        foreach my $key (keys %h) {
            $res++ if (exists($h{$k + $key}));
        }
    
        return $res;
    }