aboutsummaryrefslogtreecommitdiff
path: root/challenge-199
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2023-01-15 09:46:13 +0000
committerGitHub <noreply@github.com>2023-01-15 09:46:13 +0000
commit19b93408e95cd514003de1a1841aa0f73fd0ddb7 (patch)
tree83b47d2890dae0ea8fe500c8d14668d26e874f5d /challenge-199
parent13e4a2c007d7a0aac2bd1b8a48aa28003d772dc5 (diff)
downloadperlweeklychallenge-club-19b93408e95cd514003de1a1841aa0f73fd0ddb7.tar.gz
perlweeklychallenge-club-19b93408e95cd514003de1a1841aa0f73fd0ddb7.tar.bz2
perlweeklychallenge-club-19b93408e95cd514003de1a1841aa0f73fd0ddb7.zip
Create ch-1.pl
Diffstat (limited to 'challenge-199')
-rw-r--r--challenge-199/james-smith/perl/ch-1.pl23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-199/james-smith/perl/ch-1.pl b/challenge-199/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..2dbeb6a090
--- /dev/null
+++ b/challenge-199/james-smith/perl/ch-1.pl
@@ -0,0 +1,23 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use feature qw(say);
+use Test::More;
+use Benchmark qw(cmpthese timethis);
+
+my @TESTS = (
+ [ [1,2,3,1,1,3],4 ],
+ [ [1,2,3], 0 ],
+ [ [1,1,1,1], 6 ],
+);
+
+is( good_pairs(@{$_->[0]}), $_->[1] ) foreach @TESTS;
+
+sub good_pairs {
+ my($c,%f);
+ $f{$_}++ for @_;
+ $c+=$_*($_-1) for values %f;
+ $c/2;
+}
+done_testing();