Day 4
[advent-of-code-2021.git] / day04 / task.txt
1 --- Day 4: Giant Squid ---
2 You're already almost 1.5km (almost a mile) below the surface of the ocean, already so deep that you can't see any sunlight. What you can see, however, is a giant squid that has attached itself to the outside of your submarine.
3
4 Maybe it wants to play bingo?
5
6 Bingo is played on a set of boards each consisting of a 5x5 grid of numbers. Numbers are chosen at random, and the chosen number is marked on all boards on which it appears. (Numbers may not appear on all boards.) If all numbers in any row or any column of a board are marked, that board wins. (Diagonals don't count.)
7
8 The submarine has a bingo subsystem to help passengers (currently, you and the giant squid) pass the time. It automatically generates a random order in which to draw numbers and a random set of boards (your puzzle input). For example:
9
10 7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1
11
12 22 13 17 11  0
13  8  2 23  4 24
14 21  9 14 16  7
15  6 10  3 18  5
16  1 12 20 15 19
17
18  3 15  0  2 22
19  9 18 13 17  5
20 19  8  7 25 23
21 20 11 10 24  4
22 14 21 16 12  6
23
24 14 21 17 24  4
25 10 16 15  9 19
26 18  8 23 26 20
27 22 11 13  6  5
28  2  0 12  3  7
29
30 After the first five numbers are drawn (7, 4, 9, 5, and 11), there are no winners, but the boards are marked as follows (shown here adjacent to each other to save space):
31
32 22 13 17 11  0         3 15  0  2 22        14 21 17 24  4
33  8  2 23  4 24         9 18 13 17  5        10 16 15  9 19
34 21  9 14 16  7        19  8  7 25 23        18  8 23 26 20
35  6 10  3 18  5        20 11 10 24  4        22 11 13  6  5
36  1 12 20 15 19        14 21 16 12  6         2  0 12  3  7
37
38 After the next six numbers are drawn (17, 23, 2, 0, 14, and 21), there are still no winners:
39
40 22 13 17 11  0         3 15  0  2 22        14 21 17 24  4
41  8  2 23  4 24         9 18 13 17  5        10 16 15  9 19
42 21  9 14 16  7        19  8  7 25 23        18  8 23 26 20
43  6 10  3 18  5        20 11 10 24  4        22 11 13  6  5
44  1 12 20 15 19        14 21 16 12  6         2  0 12  3  7
45 Finally, 24 is drawn:
46
47 22 13 17 11  0         3 15  0  2 22        14 21 17 24  4
48  8  2 23  4 24         9 18 13 17  5        10 16 15  9 19
49 21  9 14 16  7        19  8  7 25 23        18  8 23 26 20
50  6 10  3 18  5        20 11 10 24  4        22 11 13  6  5
51  1 12 20 15 19        14 21 16 12  6         2  0 12  3  7
52 At this point, the third board wins because it has at least one complete row or column of marked numbers (in this case, the entire top row is marked: 14 21 17 24 4).
53
54 The score of the winning board can now be calculated. Start by finding the sum of all unmarked numbers on that board; in this case, the sum is 188. Then, multiply that sum by the number that was just called when the board won, 24, to get the final score, 188 * 24 = 4512.
55
56 To guarantee victory against the giant squid, figure out which board will win first. What will your final score be if you choose that board?
57
58 Your puzzle answer was 58412.
59
60 --- Part Two ---
61 On the other hand, it might be wise to try a different strategy: let the giant squid win.
62
63 You aren't sure how many bingo boards a giant squid could play at once, so rather than waste time counting its arms, the safe thing to do is to figure out which board will win last and choose that one. That way, no matter which boards it picks, it will win for sure.
64
65 In the above example, the second board is the last to win, which happens after 13 is eventually called and its middle column is completely marked. If you were to keep playing until this point, the second board would have a sum of unmarked numbers equal to 148 for a final score of 148 * 13 = 1924.
66
67 After the next six numbers are drawn (17, 23, 2, 0, 14, and 21), there are still no winners:
68
69 22 13 17 11  0         3 15  0  2 22        14 21 17 24  4
70  8  2 23  4 24         9 18 13 17  5        10 16 15  9 19
71 21  9 14 16  7        19  8  7 25 23        18  8 23 26 20
72  6 10  3 18  5        20 11 10 24  4        22 11 13  6  5
73  1 12 20 15 19        14 21 16 12  6         2  0 12  3  7
74 Finally, 24 is drawn:
75
76 22 13 17 11  0         3 15  0  2 22        14 21 17 24  4
77  8  2 23  4 24         9 18 13 17  5        10 16 15  9 19
78 21  9 14 16  7        19  8  7 25 23        18  8 23 26 20
79  6 10  3 18  5        20 11 10 24  4        22 11 13  6  5
80  1 12 20 15 19        14 21 16 12  6         2  0 12  3  7
81 At this point, the third board wins because it has at least one complete row or column of marked numbers (in this case, the entire top row is marked: 14 21 17 24 4).
82
83 The score of the winning board can now be calculated. Start by finding the sum of all unmarked numbers on that board; in this case, the sum is 188. Then, multiply that sum by the number that was just called when the board won, 24, to get the final score, 188 * 24 = 4512.
84
85 To guarantee victory against the giant squid, figure out which board will win first. What will your final score be if you choose that board?
86
87 Your puzzle answer was 58412.