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.

37 lines
810 B

1 year ago
  1. BEGIN {
  2. delete cards;
  3. delete counts;
  4. }
  5. {
  6. cardNo = substr($2, 1, length($2) - 1);
  7. delete winingNumbers;
  8. delete myNumbers;
  9. for (i = 3; $i != "|"; i++) {
  10. winingNumbers[i - 2] = $i;
  11. }
  12. for(c = 1;i+c <= NF;c++) {
  13. myNumbers[c] = $(i + c)
  14. }
  15. wins = 0;
  16. for (i = 1; i <= length(myNumbers); i++) {
  17. for (j = 1; j <= length(winingNumbers); j++) {
  18. if (myNumbers[i] == winingNumbers[j]) {
  19. wins = wins + 1;
  20. break;
  21. }
  22. }
  23. }
  24. cards[cardNo] = wins;
  25. counts[cardNo] = 1;
  26. }
  27. END {
  28. count = 0
  29. for (i = 1; i <= NR; i++) {
  30. count = count + counts[i];
  31. for(n = 1; n <= cards[i]; n++) {
  32. counts[i + n] = counts[i + n] + counts[i];
  33. }
  34. }
  35. print count;
  36. }