2.pl (524B) [raw]
1 #!/usr/bin/env perl 2 use strict; 3 use warnings; 4 5 my $s = 0; 6 line: while (<ARGV>) { 7 chomp; 8 my %max = (red => 0, green => 0, blue => 0); 9 my ($game, $rounds) = ($_ =~ /Game (\d+): (.*)/); 10 my @rounds = split("; ", $rounds); 11 for my $r (@rounds) { 12 my @vals = split(", ", $r); 13 for my $v (@vals) { 14 my ($n, $c) = split(" ", $v); 15 if ($n > $max{$c}) { 16 $max{$c} = $n;; 17 } 18 } 19 } 20 $s += $max{red} * $max{green} * $max{blue}; 21 } 22 print("$s\n");