diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-07-04 21:10:19 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-07-04 21:10:19 +0100 |
| commit | 251b2bd8b0ff8d3b1262173c33a4e999cf37846a (patch) | |
| tree | e6d58a6a75f6a895cb07762b0183860f48096b9d /challenge-161 | |
| parent | 9a0e9aa937cd71b048889a57f68896e5187466ac (diff) | |
| download | perlweeklychallenge-club-251b2bd8b0ff8d3b1262173c33a4e999cf37846a.tar.gz perlweeklychallenge-club-251b2bd8b0ff8d3b1262173c33a4e999cf37846a.tar.bz2 perlweeklychallenge-club-251b2bd8b0ff8d3b1262173c33a4e999cf37846a.zip | |
new stuff
Diffstat (limited to 'challenge-161')
| -rw-r--r-- | challenge-161/james-smith/perl/ch-1.pl | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/challenge-161/james-smith/perl/ch-1.pl b/challenge-161/james-smith/perl/ch-1.pl index d2a8b2adb7..0729dbe48e 100644 --- a/challenge-161/james-smith/perl/ch-1.pl +++ b/challenge-161/james-smith/perl/ch-1.pl @@ -4,17 +4,39 @@ use strict; use warnings; use feature qw(say); +use Test::More; +use Benchmark qw(cmpthese timethis); +use Data::Dumper qw(Dumper); open my $d, q(<), 'dictionary.txt'; +my @list = map { chomp;$_ } <$d>; +close $d; -my %a; - -## Accept it - best film is "Hot Fuzz". -## Glory begins for forty deft aces! - -O:while( my $f = '', chomp( my $w = <$d> // '' ) ) { - $f gt $_ ? next O : ( $f = $_ ) for split //, $w; - push @{$a{ length $w }}, $w; +cmpthese( 5, { + 'mine' => 'mine', + 'colin' => 'colin', +}); +sub mine { + my @a; + ## Accept it - best film is "Hot Fuzz". + ## Glory begins for forty deft aces! + O:for my $w (@list) { + my $f=''; + $f gt $_ ? next O : ( $f = $_ ) for split //, $w; + push @a,$w; + } + warn 'mine', scalar @a; + return \@a; } -say "$_: ", join ', ', @{$a{$_}} for sort { $a<=>$b } keys %a; +sub colin { + my @a; + ## Accept it - best film is "Hot Fuzz". + ## Glory begins for forty deft aces! + O:for my $w (@list) { + (substr $w,$_-1,1 gt substr $w,$_,1 ) && (next O) for 1.. (length$w) - 1; + push @a,$w; + } + warn 'colin', scalar @a; + return \@a; +} |
