aoc

Advent of Code Solutions
git clone git://git.alexkarle.com.com/aoc
Log | Files | Refs | README | LICENSE

1.pl (515B) [raw]


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