aboutsummaryrefslogtreecommitdiff
path: root/challenge-131
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-11-29 07:12:59 +0000
committerdrbaggy <js5@sanger.ac.uk>2021-11-29 07:12:59 +0000
commit5d92143764fb5c8fce90edd16f6938a8470622b3 (patch)
treeeb3645549aa1364f81ea6e314692010f305a1668 /challenge-131
parent2b768566060b5d403f2fd3730171f7087e93018a (diff)
downloadperlweeklychallenge-club-5d92143764fb5c8fce90edd16f6938a8470622b3.tar.gz
perlweeklychallenge-club-5d92143764fb5c8fce90edd16f6938a8470622b3.tar.bz2
perlweeklychallenge-club-5d92143764fb5c8fce90edd16f6938a8470622b3.zip
links in blogs < & >
Diffstat (limited to 'challenge-131')
-rw-r--r--challenge-131/james-smith/perl/ch-2.pl35
1 files changed, 24 insertions, 11 deletions
diff --git a/challenge-131/james-smith/perl/ch-2.pl b/challenge-131/james-smith/perl/ch-2.pl
index 5af21335e2..86096aac26 100644
--- a/challenge-131/james-smith/perl/ch-2.pl
+++ b/challenge-131/james-smith/perl/ch-2.pl
@@ -8,20 +8,33 @@ use Test::More;
use Benchmark qw(cmpthese timethis);
use Data::Dumper qw(Dumper);
-my @TESTS = (
- [ [ '""[]()', '"I like (parens) and the Apple ][+" they said.' ], [ '"(["','")]"' ] ],
- [ [ '**//<>', '/* This is a comment (in some languages) */ <could be a tag>' ], [ '/**/<','/**/>' ] ],
+my @player_ages = (
+ [20, "Alex" ],
+ [28, "Joe" ],
+ [38, "Mike" ],
+ [18, "Alex" ],
+ [25, "David" ],
+ [18, "Simon" ],
);
+my @player_names = (
+ ["Alex", "Stewart"],
+ ["Joe", "Root" ],
+ ["Mike", "Gatting"],
+ ["Joe", "Blog" ],
+ ["Alex", "Jones" ],
+ ["Simon","Duane" ],
+);
-is( join( ' - ', find_pairs( @{$_->[0]})), join( ' - ', @{$_->[1]} ) ) foreach @TESTS;
-
-done_testing();
+my $MAX = @ARGV ? $ARGV[0] : 4;
-sub find_pairs {
- map { join '', $_[1] =~m{$_}g }
- map { '['.quotemeta( $_ ).']' }
- map { join '', $_[0] =~ /$_/g }
- qr((.).?), qr(.(.?));
+my @res;
+while( my @pns = splice @player_names, 0, $MAX ) {
+ my %cache = ();
+ push @{$cache{$_->[0]}},$_->[1] foreach @pns;
+ foreach my $p (@player_ages) {
+ push @res, [$p->[0], $p->[1], $_] foreach @{$cache{$p->[1]}};
+ }
}
+printf "%4d\t%-20s\t%-20s\n", @{$_} foreach @res;