aboutsummaryrefslogtreecommitdiff
path: root/challenge-127/bruce-gray/perl/ch-1.pl
blob: fd835af593b8227566ec3551e3c127505478bef0 (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
25
26
27
28
use strict;
use warnings;
use 5.026;
use experimental qw<signatures>;
use List::Util   qw<uniq>;
use Test::More;

# Without uniq or input checking: my %s; return 0 + !grep { ++$s{$_} >= 2 } map { @{$_} } @_;

sub sets_are_disjoint ( $x_aref, $y_aref ) {
    my @x = @{$x_aref};
    my @y = @{$y_aref};
    die "Input set X was not unique" if @x != uniq(@x);
    die "Input set Y was not unique" if @y != uniq(@y);

    return 0 + ( @x + @y == uniq(@x, @y) );
}

my @tests = (
    [ 0 => [ [1, 2, 5, 3, 4], [4, 6, 7, 8, 9] ] ],
    [ 1 => [ [1, 3, 5, 7, 9], [0, 2, 4, 6, 8] ] ],
    [ 1 => [ [             ], [             ] ] ],
);
plan tests => 0+@tests;
for (@tests) {
    my ($expected, $input) = @{$_};
    is sets_are_disjoint(@{$input}), $expected;
}