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 print "\t$count\t$color.\n";
16 push @{ $graph{$color} }, $bag;
21 my %seen = ('shiny gold' => 1);
22 my @todo = 'shiny gold';
24 while (my $color = shift @todo) {
25 for my $next (@{ $graph{$color} }) {
26 next if $seen{ $next };
32 print "Seen ", keys(%seen)-1, " nodes\n";