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

1 year ago
  1. BEGIN {
  2. FS = ":"
  3. maxred = 12;
  4. maxgreen = 13;
  5. maxblue = 14;
  6. }
  7. {
  8. gamenum = substr($1, 6)
  9. split($2, games, ";");
  10. valid = 1;
  11. minred = 0;
  12. minblue = 0;
  13. mingreen = 1;
  14. for (i = 1; i <= length(games); i++) {
  15. split(games[i], game, ",");
  16. usedblue = 0;
  17. usedred = 0;
  18. usedgreen = 0;
  19. for (j = 1; j <= length(game); j++) {
  20. split(game[j], value, " ")
  21. if (value[2] == "blue")
  22. usedblue = usedblue + value[1];
  23. else if (value[2] == "red")
  24. usedred = usedred + value[1];
  25. else if (value[2] == "green")
  26. usedgreen = usedgreen + value[1];
  27. else
  28. print "Unknown color in `", game[j], "`";
  29. }
  30. if (usedblue > minblue) minblue = usedblue;
  31. if (usedred > minred) minred = usedred;
  32. if (usedgreen > mingreen) mingreen = usedgreen;
  33. valid = valid && usedred <= maxred && usedblue <= maxblue && usedgreen <= maxgreen;
  34. }
  35. if (valid)
  36. sum1 = sum1 + gamenum;
  37. sum2 = sum2 + (minred * mingreen * minblue);
  38. }
  39. END { print sum1, sum2; }