golf1-clean
#!/usr/bin/env php
<?php
$lines=file('input.txt');
// first letter of each color name, so we can use $$color
$r=12;
$g=13;
$b=14;
$total = 0;
foreach ($lines as $line){
preg_match_all('/(\d+) (.)/',$line, $cube_counts);
foreach($cube_counts[2] as $index=>$color){
if($cube_counts[1][$index]>$$color)continue 2;
}
preg_match('/\d+/',$line,$matches);
$total+=$matches[0];
}
// should be 2563
echo "Sum of Game IDs: $total\n";