Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use feature qw(say);
- sub recurse {
- my ($acc, $targ, @list) = @_;
- return ($acc == $targ) if (!@list || $acc > $targ);
- my $next = shift @list;
- return (&recurse( $acc + $next, $targ, @list )
- || &recurse( $acc * $next, $targ, @list )
- || &recurse( int($acc . $next), $targ, @list )); # remove for part 1
- }
- my $part2 = 0;
- foreach my $line (map {[map {int} m#(\d+)#g]} <>) {
- my $targ = shift @$line;
- $part2 += $targ if (&recurse( shift @$line, $targ, @$line ));
- }
- say "Part 2: ", $part2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement