From 19b93408e95cd514003de1a1841aa0f73fd0ddb7 Mon Sep 17 00:00:00 2001 From: James Smith Date: Sun, 15 Jan 2023 09:46:13 +0000 Subject: Create ch-1.pl --- challenge-199/james-smith/perl/ch-1.pl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 challenge-199/james-smith/perl/ch-1.pl 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(); -- cgit