diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-05-17 10:59:12 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-05-17 10:59:12 +0100 |
| commit | 16edd6150b08e3247722843e8f9069eade984331 (patch) | |
| tree | 0633423e14335b5583822d28498b2a6f5449b53c /challenge-113/james-smith | |
| parent | 6edfec5322cf3245ceda4e2a8df176e09aa0360b (diff) | |
| download | perlweeklychallenge-club-16edd6150b08e3247722843e8f9069eade984331.tar.gz perlweeklychallenge-club-16edd6150b08e3247722843e8f9069eade984331.tar.bz2 perlweeklychallenge-club-16edd6150b08e3247722843e8f9069eade984331.zip | |
even faster with a tweak to logic
Diffstat (limited to 'challenge-113/james-smith')
| -rw-r--r-- | challenge-113/james-smith/perl/ch-1.pl | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/challenge-113/james-smith/perl/ch-1.pl b/challenge-113/james-smith/perl/ch-1.pl index 7a46da9b55..efb023fcf0 100644 --- a/challenge-113/james-smith/perl/ch-1.pl +++ b/challenge-113/james-smith/perl/ch-1.pl @@ -5,17 +5,19 @@ use strict; use warnings; use feature qw(say); use Test::More; -use Benchmark qw(cmpthese); +use Benchmark qw(timethis); my @ex = ( [25,8,0], [25,7,0], [24,7,1], [24,0,0], [10,0,1], [28,8,1], [26,8,1], [16,8,0], [441,9,1], [431,9,0] ); is( represent( $_->[0], $_->[1]), $_->[2] ) foreach @ex; done_testing(); - +say ''; +timethis( 1_000_000, sub { represent($_->[0],$_->[1]) for @ex } ); +say ''; sub represent { my($t,$n,$d) = (0,@_); - 1+($t+=$_*10+$d) && $n>=$t && ($n%10 == $t%10) && return 1 for 0..9; - return 0; + $n>=($t+=$_*10+$d) && ($n%10 == $t%10) && return 1 for 0..9; + 0; } |
