aboutsummaryrefslogtreecommitdiff
path: root/challenge-067
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-07-02 23:58:29 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-07-02 23:58:29 +0100
commit814d74f02c0b9f32acb4fc23f9fbf352c7d2511d (patch)
tree3054736ef34a203690899c06c4ac9d479487d089 /challenge-067
parentff28d260554a8b78ab0eb0b0ecbdf798c14d305a (diff)
downloadperlweeklychallenge-club-814d74f02c0b9f32acb4fc23f9fbf352c7d2511d.tar.gz
perlweeklychallenge-club-814d74f02c0b9f32acb4fc23f9fbf352c7d2511d.tar.bz2
perlweeklychallenge-club-814d74f02c0b9f32acb4fc23f9fbf352c7d2511d.zip
- Tidied up return value.
Diffstat (limited to 'challenge-067')
-rw-r--r--challenge-067/mohammad-anwar/perl/ch-1.pl4
-rw-r--r--challenge-067/mohammad-anwar/perl/ch-1a.pl35
2 files changed, 16 insertions, 23 deletions
diff --git a/challenge-067/mohammad-anwar/perl/ch-1.pl b/challenge-067/mohammad-anwar/perl/ch-1.pl
index 2763293426..40db68269d 100644
--- a/challenge-067/mohammad-anwar/perl/ch-1.pl
+++ b/challenge-067/mohammad-anwar/perl/ch-1.pl
@@ -49,9 +49,9 @@ sub comb {
foreach my $member (@combinations) {
my @uniq = uniq split //, $member;
next unless (@uniq == $n);
- $filter{ join ', ', sort @uniq } = 1;
+ $filter{ sprintf("[%s]", join ', ', sort @uniq) } = 1;
}
# return sorted result
- return (sort keys %filter);
+ return sprintf("[ %s ]", join ', ', (sort keys %filter));
}
diff --git a/challenge-067/mohammad-anwar/perl/ch-1a.pl b/challenge-067/mohammad-anwar/perl/ch-1a.pl
index ed3a93589c..b196cc039f 100644
--- a/challenge-067/mohammad-anwar/perl/ch-1a.pl
+++ b/challenge-067/mohammad-anwar/perl/ch-1a.pl
@@ -12,27 +12,20 @@ use strict;
use warnings;
use Test::More;
-use Test::Deep;
use List::Util qw(uniq);
-is_deeply( [ comb(5, 2) ],
- [ '1, 2', '1, 3', '1, 4', '1, 5',
- '2, 3', '2, 4', '2, 5',
- '3, 4', '3, 5',
- '4, 5' ],
- 'testing m=5; n=2' );
-is_deeply( [ comb(5, 3) ],
- [ '1, 2, 3', '1, 2, 4', '1, 2, 5', '1, 3, 4', '1, 3, 5', '1, 4, 5',
- '2, 3, 4', '2, 3, 5', '2, 4, 5',
- '3, 4, 5' ],
- 'testing m=5; n=3' );
-is_deeply( [ comb(5, 4) ],
- [ '1, 2, 3, 4', '1, 2, 3, 5', '1, 2, 4, 5', '1, 3, 4, 5',
- '2, 3, 4, 5' ],
- 'testing m=5; n=4' );
-is_deeply( [ comb(5, 5) ],
- [ '1, 2, 3, 4, 5' ],
- 'testing m=5; n=5' );
+is( comb(5, 2),
+ '[ [1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5] ]',
+ 'testing m=5; n=2' );
+is( comb(5, 3),
+ '[ [1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 3, 4], [1, 3, 5], [1, 4, 5], [2, 3, 4], [2, 3, 5], [2, 4, 5], [3, 4, 5] ]',
+ 'testing m=5; n=3' );
+is( comb(5, 4),
+ '[ [1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 4, 5], [1, 3, 4, 5], [2, 3, 4, 5] ]',
+ 'testing m=5; n=4' );
+is( comb(5, 5),
+ '[ [1, 2, 3, 4, 5] ]',
+ 'testing m=5; n=5' );
done_testing;
@@ -68,9 +61,9 @@ sub comb {
foreach my $member (@combinations) {
my @uniq = uniq split //, $member;
next unless (@uniq == $n);
- $filter{ join ', ', sort @uniq } = 1;
+ $filter{ sprintf("[%s]", join ', ', sort @uniq) } = 1;
}
# return sorted result
- return (sort keys %filter);
+ return sprintf("[ %s ]", join ', ', (sort keys %filter));
}