aboutsummaryrefslogtreecommitdiff
path: root/challenge-044
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2020-01-24 01:13:38 -0500
committerDave Jacoby <jacoby.david@gmail.com>2020-01-24 01:13:38 -0500
commit46516b7fc9e7248f2d82a83cda77848010d41a04 (patch)
treee33788a3474ffeefa72dbc89155b1691c5c174a1 /challenge-044
parentc8a4063059be057bd856a0539cb44ca8b96f3091 (diff)
downloadperlweeklychallenge-club-46516b7fc9e7248f2d82a83cda77848010d41a04.tar.gz
perlweeklychallenge-club-46516b7fc9e7248f2d82a83cda77848010d41a04.tar.bz2
perlweeklychallenge-club-46516b7fc9e7248f2d82a83cda77848010d41a04.zip
I'd like to revise and extend my submission
Diffstat (limited to 'challenge-044')
-rw-r--r--challenge-044/dave-jacoby/perl/ch-1a.pl33
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-044/dave-jacoby/perl/ch-1a.pl b/challenge-044/dave-jacoby/perl/ch-1a.pl
new file mode 100644
index 0000000000..a6c92a216a
--- /dev/null
+++ b/challenge-044/dave-jacoby/perl/ch-1a.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use utf8;
+use feature qw{ postderef say signatures };
+no warnings
+ qw{ experimental::postderef experimental::signatures };
+
+my $vals->@* = ( ' + ', ' - ', '' );
+my $source->@* = ( 1, '', 2, '', 3, '', 4, '', 5, '', 6, '', 7, '', 8, '', 9 );
+
+challenge( $source, $vals, 1 );
+
+sub challenge ( $source, $vals, $index ) {
+
+ # check to see if this is correct
+ if ( $index >= scalar $source->@* ) {
+ my $string = join '', $source->@*;
+ my $result = eval $string;
+ say qq{ $result = $string } if $result == 100;
+ return;
+ }
+
+ # recursively add to the array
+ my $next->@* = map { $_ } $source->@*;
+ for my $v ( $vals->@* ) {
+ $next->[$index] = $v;
+ challenge( $next, $vals, $index + 2 );
+ }
+ return;
+}
+exit;