9 my ($bag, $rest) = /\A(.*) bags? contain (.*)./;
10 if ($rest eq 'no other bags') {
11 $graph{$bag} = []; # ale neprojevi se
13 for my $contain (split /, /, $rest) {
14 my ($count, $color) = ($contain =~ /\A(\d+) (.*) bag/);
15 push @{ $graph{$bag} }, [ $color => $count ];
20 my %seen = ('shiny gold' => 1);
27 if defined $total{$color};
30 for my $next (@{ $graph{$color} }) {
31 my ($ncol, $ncount) = @$next;
32 $total{$color} += $ncount*walk($ncol);
35 return $total{$color};
38 print "Result is ", walk('shiny gold') - 1, "\n";