aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE. Choroba <choroba@matfyz.cz>2020-11-19 08:16:02 +0100
committerE. Choroba <choroba@matfyz.cz>2020-11-19 08:16:02 +0100
commite0ab01a77f0e63ee9e29c293db0797f6a915ee64 (patch)
treed00ba411106077559582a50e3e7753537a0d510d
parent8117c9db7918d9627a6920e88ef27cb469b81274 (diff)
downloadperlweeklychallenge-club-e0ab01a77f0e63ee9e29c293db0797f6a915ee64.tar.gz
perlweeklychallenge-club-e0ab01a77f0e63ee9e29c293db0797f6a915ee64.tar.bz2
perlweeklychallenge-club-e0ab01a77f0e63ee9e29c293db0797f6a915ee64.zip
Handle duplicates in 087/1
-rwxr-xr-xchallenge-087/e-choroba/perl/ch-1.pl8
1 files changed, 6 insertions, 2 deletions
diff --git a/challenge-087/e-choroba/perl/ch-1.pl b/challenge-087/e-choroba/perl/ch-1.pl
index 0ef7264ff3..d4d030716c 100755
--- a/challenge-087/e-choroba/perl/ch-1.pl
+++ b/challenge-087/e-choroba/perl/ch-1.pl
@@ -2,8 +2,10 @@
use warnings;
use strict;
+use List::Util qw{ uniq };
+
sub longest_consecutive_sequence {
- my @N = sort { $a <=> $b } @_;
+ my @N = sort { $a <=> $b } uniq(@_);
# To simplify the code, the last number will never be part of the
# sequence.
@@ -38,7 +40,7 @@ sub longest_consecutive_sequence {
return [ map [ $_->[0] .. $_->[1] ], @longest ];
}
-use Test::More tests => 6;
+use Test::More tests => 7;
is_deeply longest_consecutive_sequence(100, 4, 50, 3, 2),
[[2, 3, 4]], 'Example 1';
@@ -53,3 +55,5 @@ is_deeply longest_consecutive_sequence(1, 2, 3, 4, 6, 7, 8, 9, 10),
[[6, 7, 8, 9, 10]], 'Has shorter';
is_deeply longest_consecutive_sequence(1, 3, 4, 7, 8),
[[3, 4], [7, 8]], 'Length 2';
+is_deeply longest_consecutive_sequence(-2, -2, -1, -1, 0, 0, 1, 3),
+ [[-2, -1, 0, 1]], 'Duplicates';