aboutsummaryrefslogtreecommitdiff
path: root/challenge-108
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2021-04-19 00:49:35 +1000
committerSimon Green <mail@simon.green>2021-04-19 00:49:35 +1000
commit29852f4c27e7c8eeaa93c5a36cc688e6722a3d8c (patch)
tree494b8482b9fdda5390622230216d4b16b1e448f2 /challenge-108
parent15e0afcd407b324158e261bca7b00fe85ba9dd57 (diff)
downloadperlweeklychallenge-club-29852f4c27e7c8eeaa93c5a36cc688e6722a3d8c.tar.gz
perlweeklychallenge-club-29852f4c27e7c8eeaa93c5a36cc688e6722a3d8c.tar.bz2
perlweeklychallenge-club-29852f4c27e7c8eeaa93c5a36cc688e6722a3d8c.zip
sgreen solution to challenge 108
Diffstat (limited to 'challenge-108')
-rw-r--r--challenge-108/sgreen/README.md4
-rw-r--r--challenge-108/sgreen/blog.txt1
-rwxr-xr-xchallenge-108/sgreen/perl/ch-1.pl15
-rwxr-xr-xchallenge-108/sgreen/perl/ch-2.pl30
4 files changed, 48 insertions, 2 deletions
diff --git a/challenge-108/sgreen/README.md b/challenge-108/sgreen/README.md
index 178687bc61..f23432ca89 100644
--- a/challenge-108/sgreen/README.md
+++ b/challenge-108/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 107
+# The Weekly Challenge 108
-Solution by Simon Green. [Blog](https://dev.to/simongreennet/weekly-challenge-107-hm2)
+Solution by Simon Green. [Blog](https://dev.to/simongreennet/weekly-challenge-108-3di2)
diff --git a/challenge-108/sgreen/blog.txt b/challenge-108/sgreen/blog.txt
new file mode 100644
index 0000000000..9dcd14316d
--- /dev/null
+++ b/challenge-108/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/weekly-challenge-108-3di2
diff --git a/challenge-108/sgreen/perl/ch-1.pl b/challenge-108/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..edb3bddab1
--- /dev/null
+++ b/challenge-108/sgreen/perl/ch-1.pl
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+sub main {
+ # Define a variable
+ my $var;
+
+ # Display its location
+ say \$var =~ /(0x[0-9a-f]+)/;
+}
+
+main();
diff --git a/challenge-108/sgreen/perl/ch-2.pl b/challenge-108/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..58d73f1260
--- /dev/null
+++ b/challenge-108/sgreen/perl/ch-2.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+sub main {
+ # How many numbers do we want
+ my $count = shift // 10;
+
+ # Seed the first row
+ my @bell = ( [1] );
+
+ while ( @bell < $count ) {
+ my $cols = $#{ $bell[-1] };
+
+ # Create a new row with the last number from the previous row
+ push @bell, [ $bell[-1][-1] ];
+
+ # Add each number with the same position from previous row
+ foreach my $col ( 0 .. $cols ) {
+ push @{ $bell[-1] }, $bell[-2][$col] + $bell[-1][$col];
+ }
+ }
+
+ # The last number of each row is what we want to show
+ say $_->[-1] foreach @bell;
+}
+
+main(@ARGV);