diff options
| author | E. Choroba <choroba@matfyz.cz> | 2020-11-19 08:16:02 +0100 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2020-11-19 08:16:02 +0100 |
| commit | e0ab01a77f0e63ee9e29c293db0797f6a915ee64 (patch) | |
| tree | d00ba411106077559582a50e3e7753537a0d510d | |
| parent | 8117c9db7918d9627a6920e88ef27cb469b81274 (diff) | |
| download | perlweeklychallenge-club-e0ab01a77f0e63ee9e29c293db0797f6a915ee64.tar.gz perlweeklychallenge-club-e0ab01a77f0e63ee9e29c293db0797f6a915ee64.tar.bz2 perlweeklychallenge-club-e0ab01a77f0e63ee9e29c293db0797f6a915ee64.zip | |
Handle duplicates in 087/1
| -rwxr-xr-x | challenge-087/e-choroba/perl/ch-1.pl | 8 |
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'; |
