aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2022-05-02 09:34:37 +0100
committerdrbaggy <js5@sanger.ac.uk>2022-05-02 09:34:37 +0100
commit1d90daab5c06100eebd541c96ea05601145fc713 (patch)
treea5dc955568c44fa5dcbade7ca6928a29d36c20cb
parentb13444bb5307ad7c7051ace6031dd063bac3cc32 (diff)
downloadperlweeklychallenge-club-1d90daab5c06100eebd541c96ea05601145fc713.tar.gz
perlweeklychallenge-club-1d90daab5c06100eebd541c96ea05601145fc713.tar.bz2
perlweeklychallenge-club-1d90daab5c06100eebd541c96ea05601145fc713.zip
solution to 2 with or without the table - need to look to see if there is a formulaic way of generating the sum
-rw-r--r--challenge-163/james-smith/perl/ch-1.pl22
-rw-r--r--challenge-163/james-smith/perl/ch-2.pl33
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-163/james-smith/perl/ch-1.pl b/challenge-163/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..2348c8b946
--- /dev/null
+++ b/challenge-163/james-smith/perl/ch-1.pl
@@ -0,0 +1,22 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+use Benchmark qw(cmpthese timethis);
+use Data::Dumper qw(Dumper);
+
+my @TESTS = (
+ [ 0, 1 ],
+);
+
+is( my_function($_->[0]), $_->[1] ) foreach @TESTS;
+
+done_testing();
+
+sub my_function {
+ return 1;
+}
+
diff --git a/challenge-163/james-smith/perl/ch-2.pl b/challenge-163/james-smith/perl/ch-2.pl
new file mode 100644
index 0000000000..8430c3609a
--- /dev/null
+++ b/challenge-163/james-smith/perl/ch-2.pl
@@ -0,0 +1,33 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+use Benchmark qw(cmpthese timethis);
+use Data::Dumper qw(Dumper);
+
+my @TESTS = (
+ [ [1..5], 42 ],
+ [ [1,3,5,7,9], 70 ],
+);
+
+say '';
+is( summation(@{$_->[0]}), $_->[1] ),say'' for @TESTS;
+is( summation_with_table(@{$_->[0]}), $_->[1] ),say'' for @TESTS;
+done_testing();
+say '';
+
+sub summation_with_table {
+ my $t;
+ say "@_";
+ shift, ($t=0), say "@{[ @_ = map { $t+=$_ } @_ ]}" while @_>1;
+ shift;
+}
+
+sub summation {
+ my $t;
+ shift, ($t=0), (@_ = map { $t+=$_ } @_) while @_>1;
+ shift;
+}