aboutsummaryrefslogtreecommitdiff
path: root/challenge-196
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2022-12-19 12:43:11 +0000
committerGitHub <noreply@github.com>2022-12-19 12:43:11 +0000
commitf115a156a59806f35b0e0066618b1d7b4082d58c (patch)
tree72b07837109be25e964894bd399b99ff40c151d3 /challenge-196
parent18f23b62347cdee6ae4a78c96d68efed17a67b8a (diff)
downloadperlweeklychallenge-club-f115a156a59806f35b0e0066618b1d7b4082d58c.tar.gz
perlweeklychallenge-club-f115a156a59806f35b0e0066618b1d7b4082d58c.tar.bz2
perlweeklychallenge-club-f115a156a59806f35b0e0066618b1d7b4082d58c.zip
Update ch-2.pl
Diffstat (limited to 'challenge-196')
-rw-r--r--challenge-196/james-smith/perl/ch-2.pl10
1 files changed, 9 insertions, 1 deletions
diff --git a/challenge-196/james-smith/perl/ch-2.pl b/challenge-196/james-smith/perl/ch-2.pl
index fe42f2b8b2..9f01f6aba5 100644
--- a/challenge-196/james-smith/perl/ch-2.pl
+++ b/challenge-196/james-smith/perl/ch-2.pl
@@ -13,7 +13,8 @@ my @TESTS = (
[ [1,3,5], '( )' ],
);
-is( dmp( range( @{$_->[0]} ) ), $_->[1] ) for @TESTS;
+is( dmp( range( @{$_->[0]} ) ), $_->[1] ) for @TESTS;
+is( dmp( range_v2( @{$_->[0]} ) ), $_->[1] ) for @TESTS;
done_testing();
sub range {
@@ -23,4 +24,11 @@ sub range {
@r
}
+sub range_v2 {
+ my@r=[(shift)x 2];
+ $_==$r[-1][1]+1?$r[-1][1]=$_:push@r,[$_,$_]for@_;
+ grep{$_->[1]!=$_->[0]}@r
+}
+
+
sub dmp { sprintf '( %s )', join ', ', map { sprintf '[%s]', join ',', @{$_} } @_ }