Skip to content

Commit

Permalink
I'd like to revise and extend my submission
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoby committed Jan 24, 2020
1 parent c8a4063 commit 46516b7
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions challenge-044/dave-jacoby/perl/ch-1a.pl
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 46516b7

Please sign in to comment.