diff options
| author | E7-87-83 <fungcheokyin@gmail.com> | 2021-08-28 14:54:25 +0800 |
|---|---|---|
| committer | E7-87-83 <fungcheokyin@gmail.com> | 2021-08-28 14:54:25 +0800 |
| commit | 45cb517f6f850e54d4479227ae35d8e1bf3ed20d (patch) | |
| tree | da914808bbfb8f2b9ab049fdde485a47dcfbf407 | |
| parent | 0b6e87cf1f36cec287f9e0946a112bb3f21ce740 (diff) | |
| download | perlweeklychallenge-club-45cb517f6f850e54d4479227ae35d8e1bf3ed20d.tar.gz perlweeklychallenge-club-45cb517f6f850e54d4479227ae35d8e1bf3ed20d.tar.bz2 perlweeklychallenge-club-45cb517f6f850e54d4479227ae35d8e1bf3ed20d.zip | |
week 127
| -rw-r--r-- | challenge-127/cheok-yin-fung/perl/ch-1.pl | 30 | ||||
| -rw-r--r-- | challenge-127/cheok-yin-fung/perl/ch-2.pl | 18 |
2 files changed, 41 insertions, 7 deletions
diff --git a/challenge-127/cheok-yin-fung/perl/ch-1.pl b/challenge-127/cheok-yin-fung/perl/ch-1.pl index 8a663a6a81..36fb6ab2df 100644 --- a/challenge-127/cheok-yin-fung/perl/ch-1.pl +++ b/challenge-127/cheok-yin-fung/perl/ch-1.pl @@ -1,11 +1,29 @@ #!/usr/bin/perl # The Weekly Challenge 127 # Task 1 Disjoint Sets -# Usage: $ ch-1.pl +# Usage: +# $ ch-1.pl $a1[0] $a1[1] ... $a1[$#a1] x $a2[0] ... $a2[$#a2] use v5.12.0; no warnings; use experimental qw/signatures/; -use Test::More tests => 5; +use Test::More tests => 6; + +my (@a, @a1, @a2); +@a = @ARGV; +@a = (1, 2, 3, 'x', 3, 5, 7) if !defined($ARGV[0]); +my $i = 0; + +while ($a[$i] ne 'x' && $i < scalar @a) { + push @a1, $a[$i]; + $i++; +} + +while ($i < scalar @a) { + push @a2, $a[$i]; + $i++; +} + +say disjoint( [@a1], [@a2]); sub disjoint ($s1 , $s2) { my @S1 = sort $s1->@*; @@ -41,9 +59,9 @@ ok disjoint( [1, 3, 5, 7, 9], [0, 2, 4, 6, 8] ) == 1, ok disjoint( [1, 3, 5, 7], [0, 2, 4, 6, 7] ) == 0, "Test case 1"; - -ok disjoint( [7], [0, 2, 4, 6, 7] ) == 0, +ok disjoint( [3, 11, 13, 27, 20], [0, 2, 4, 6, 7] ) == 1, "Test case 2"; - -ok disjoint( [2], [0, 2, 4, 6, 7] ) == 0, +ok disjoint( [ 29, 16, 23, 22, 25 ], [0, 2, 4, 6, 7] ) == 1, "Test case 3"; +ok disjoint( [14, 0, 29, 8, 22], [1, 14, 12, 11, 24]) == 0, + "Test case 4"; diff --git a/challenge-127/cheok-yin-fung/perl/ch-2.pl b/challenge-127/cheok-yin-fung/perl/ch-2.pl index 3a4a49c7f3..611ba5f202 100644 --- a/challenge-127/cheok-yin-fung/perl/ch-2.pl +++ b/challenge-127/cheok-yin-fung/perl/ch-2.pl @@ -6,7 +6,7 @@ use warnings; use v5.12.0; use List::Util qw/max min/; -use Test::More tests => 2; +use Test::More tests => 4; use Test::Deep; my @inp; @@ -91,3 +91,19 @@ cmp_deeply( [[6,9]], "Example 2" ); +cmp_deeply( + conflict_intervals( + [0, 2], [11, 15], [12, 19], [16, 23], [17, 18], + [15, 17], [19, 25], [7, 9], [1, 3], [3, 8] + ), + [ [12,19], [16,23], [17,18], [15,17], [19, 25], [1, 3], [3, 8]], + "Test 1" +); +cmp_deeply( + conflict_intervals( + [14, 28], [9, 13], [6, 16], [12, 15], [28, 36], + [6, 24], [15, 22], [13, 16], [1, 16], [8, 27] + ), + [[6,16], [12, 15], [6, 24], [15, 22], [13, 16], [1, 16], [8, 27]], + "Test 2" +); |
