You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
BEGIN {
|
|
FS = ":"
|
|
maxred = 12;
|
|
maxgreen = 13;
|
|
maxblue = 14;
|
|
}
|
|
{
|
|
gamenum = substr($1, 6)
|
|
split($2, games, ";");
|
|
valid = 1;
|
|
minred = 0;
|
|
minblue = 0;
|
|
mingreen = 1;
|
|
for (i = 1; i <= length(games); i++) {
|
|
split(games[i], game, ",");
|
|
usedblue = 0;
|
|
usedred = 0;
|
|
usedgreen = 0;
|
|
|
|
for (j = 1; j <= length(game); j++) {
|
|
split(game[j], value, " ")
|
|
if (value[2] == "blue")
|
|
usedblue = usedblue + value[1];
|
|
else if (value[2] == "red")
|
|
usedred = usedred + value[1];
|
|
else if (value[2] == "green")
|
|
usedgreen = usedgreen + value[1];
|
|
else
|
|
print "Unknown color in `", game[j], "`";
|
|
}
|
|
if (usedblue > minblue) minblue = usedblue;
|
|
if (usedred > minred) minred = usedred;
|
|
if (usedgreen > mingreen) mingreen = usedgreen;
|
|
valid = valid && usedred <= maxred && usedblue <= maxblue && usedgreen <= maxgreen;
|
|
}
|
|
if (valid)
|
|
sum1 = sum1 + gamenum;
|
|
sum2 = sum2 + (minred * mingreen * minblue);
|
|
}
|
|
END { print sum1, sum2; }
|