adventofcode/2020/07/part2.pl

30 lines
449 B
Perl
Raw Normal View History

2021-12-05 16:51:21 +00:00
package part2;
use 5.20.0;
use warnings;
use experimental qw/
signatures
postderef
/;
require './part1.pm';
sub contains($name, $bags) {
my $contained = 0;
while( my( $name, $qty ) = each $bags->{$name}->%* ) {
$contained += $qty * ( 1+ contains($name, $bags));
}
return $contained;
}
sub solution(@lines) {
my %bags = map { part1::parse_line($_) } @lines;
return contains('shiny gold', \%bags );
}