aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2023-01-26 10:51:11 +0000
committerGitHub <noreply@github.com>2023-01-26 10:51:11 +0000
commite3bad1d8b2361535c6200e76357307652e5a6432 (patch)
treec447ba48186a33c91dbbe3f4f5f39697ed42480a
parent27b88f614b9bb53872ef0da19a56087505836db0 (diff)
downloadperlweeklychallenge-club-e3bad1d8b2361535c6200e76357307652e5a6432.tar.gz
perlweeklychallenge-club-e3bad1d8b2361535c6200e76357307652e5a6432.tar.bz2
perlweeklychallenge-club-e3bad1d8b2361535c6200e76357307652e5a6432.zip
Create ch-1.pl
-rw-r--r--challenge-201/james-smith/perl/ch-1.pl26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-201/james-smith/perl/ch-1.pl b/challenge-201/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..3f215cc0ba
--- /dev/null
+++ b/challenge-201/james-smith/perl/ch-1.pl
@@ -0,0 +1,26 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use feature qw(say);
+use Test::More;
+use Benchmark qw(cmpthese timethis);
+use List::Util qw(sum0);
+
+my @TESTS = (
+ [ [0,1,3], 2 ],
+ [ [0,1], 2 ],
+ [ [0..99,101..199], 100 ],
+ [ [0..9999,10001..19999], 10000 ],
+ [ [0..999999,1000001..1999999], 1000000 ],
+ [ [0..9999999,10000001..19999999], 10000000 ],
+);
+is( missing( @{$_->[0]}), $_->[1] ) for @TESTS;
+is( missing_sum( @{$_->[0]}), $_->[1] ) for @TESTS;
+cmpthese( -10, {
+ 'missing' => sub { missing( @{$_}) for @TESTS },
+ 'missing_sub' => sub { missing_sub(@{$_}) for @TESTS },
+});
+
+sub missing { my $t = @_*(@_+1)/2; $t-=$_ for @_; $t }
+sub missing_sum { @_*(@_+1)/2 - sum0 @_ }