aboutsummaryrefslogtreecommitdiff
path: root/challenge-108
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-04-16 09:54:24 +0100
committerdrbaggy <js5@sanger.ac.uk>2021-04-16 09:54:24 +0100
commit632bbcb73eb161176ef331234890d36ea1571e96 (patch)
tree34e221c0e152d0f39c975b373fe93c1dfd300e0a /challenge-108
parent682cacce268c58e46643ccbaad64a8353904881d (diff)
downloadperlweeklychallenge-club-632bbcb73eb161176ef331234890d36ea1571e96.tar.gz
perlweeklychallenge-club-632bbcb73eb161176ef331234890d36ea1571e96.tar.bz2
perlweeklychallenge-club-632bbcb73eb161176ef331234890d36ea1571e96.zip
added solutions
Diffstat (limited to 'challenge-108')
-rw-r--r--challenge-108/james-smith/perl/ch-1.pl24
-rw-r--r--challenge-108/james-smith/perl/ch-2.pl28
2 files changed, 52 insertions, 0 deletions
diff --git a/challenge-108/james-smith/perl/ch-1.pl b/challenge-108/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..8aa29eb291
--- /dev/null
+++ b/challenge-108/james-smith/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+
+my $scalar = 1;
+my @array = (1);
+my %hash = (1=>1);
+my $arrayref = \@array;
+my $hashref = \%hash;
+my $scalarref = \$scalar;
+
+say "Scalar ", get_loc( \$scalar );
+say "Scalarref ", get_loc( \$scalarref );
+say "Array ", get_loc( \@array );
+say "Arrayref ", get_loc( \$arrayref );
+
+sub get_loc {
+ return $_[0] =~ s{(?:.*\(|\))}{}rg;
+}
+
diff --git a/challenge-108/james-smith/perl/ch-2.pl b/challenge-108/james-smith/perl/ch-2.pl
new file mode 100644
index 0000000000..524cde283d
--- /dev/null
+++ b/challenge-108/james-smith/perl/ch-2.pl
@@ -0,0 +1,28 @@
+#!/usr/local/bin/perl
+
+use strict;
+
+use warnings;
+use feature qw(say);
+use Test::More;
+
+my $ANSWER_10 = '1 1 2 5 15 52 203 877 4140 21147';
+my $ANSWER_20 = '1 1 2 5 15 52 203 877 4140 21147 115975 678570 4213597 27644437 190899322 1382958545 10480142147 82864869804 682076806159 5832742205057';
+
+is( "@{ bell_numbers(10) }", $ANSWER_10 );
+is( "@{ bell_numbers(20) }", $ANSWER_20 );
+
+done_testing();
+
+sub bell_numbers {
+ my $N = shift;
+ my @res = my @a = 1;
+ while(1) {
+ push @res, my @b = $a[-1];
+ return \@res if @res >= $N;
+ push @b, $b[-1] + $_ foreach @a;
+ @a = @b;
+ }
+}
+
+