aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2023-02-12 09:00:06 +0000
committerGitHub <noreply@github.com>2023-02-12 09:00:06 +0000
commit3181b4e34bb0f61c08c4716d4400a3085fd23346 (patch)
tree989e9bdf59368ba64c7080606c1d5e39528e8ff0
parenta2c46c30a5aeac53c7fea81939ca17e8f4536e6e (diff)
downloadperlweeklychallenge-club-3181b4e34bb0f61c08c4716d4400a3085fd23346.tar.gz
perlweeklychallenge-club-3181b4e34bb0f61c08c4716d4400a3085fd23346.tar.bz2
perlweeklychallenge-club-3181b4e34bb0f61c08c4716d4400a3085fd23346.zip
Create ch-1.pl
-rw-r--r--challenge-203/james-smith/perl/ch-1.pl35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-203/james-smith/perl/ch-1.pl b/challenge-203/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..a4407f490a
--- /dev/null
+++ b/challenge-203/james-smith/perl/ch-1.pl
@@ -0,0 +1,35 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use feature qw(say);
+use Test::More;
+
+my @TESTS = (
+ [ [1,2,3,6], 1 ],
+ [ [1,1,1,3,5], 4 ],
+ [ [3,3,6,4,5], 0 ],
+);
+
+is( special( @{$_->[0]} ), $_->[1] ) for @TESTS;
+done_testing();
+
+## Nothing really to do here other than a bit of brute
+## force....
+
+sub special {
+ my $c = 0;
+ for my $i (0..$#_-3) {
+ for my $j ($i+1..$#_-2) {
+ next unless $_[$i]<=$_[$j];
+ my $t = $_[$i]+$_[$j];
+ for my $k ($j+1..$#_-1) {
+ next unless $_[$j]<=$_[$k];
+ for my $l ($k..$#_) {
+ $c++ if $t+$_[$k]==$_[$l];
+ }
+ }
+ }
+ }
+ $c;
+}