12 if (/value (\d+) goes to bot (\d+)/) {
13 push @{ $bot_has[$2] }, $1;
14 push @todo, $2 if @{ $bot_has[$2] } == 2;
15 } elsif (/bot (\d+) gives low to (\w+) (\d+) and high to (\w+) (\d+)/) {
16 $rule[$1] = [ $2, $3, $4, $5 ];
22 while (defined(my $bot = shift @todo)) {
23 my ($lo, $hi) = sort { $a <=> $b } @{ $bot_has[$bot] };
24 say "evaluating bot $bot which has $lo and $hi";
25 if ($lo == 17 && $hi == 61) {
28 my @r = @{ $rule[$bot] };
29 if ($r[0] eq 'output') {
31 say "output $r[1] => $lo";
33 push @{ $bot_has[$r[1]] }, $lo;
34 push @todo, $r[1] if @{ $bot_has[$r[1]] } == 2;
37 if ($r[2] eq 'output') {
39 say "output $r[3] => $hi";
41 push @{ $bot_has[$r[3]] }, $hi;
42 push @todo, $r[3] if @{ $bot_has[$r[3]] } == 2;
46 say $outp[0] * $outp[1] * $outp[2];