You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Alfred Melch 5dceaa5e57 Solve 2021/04 3 years ago
..
input Solve 2021/04 3 years ago
src Solve 2021/04 3 years ago
Cargo.lock Solve 2021/04 3 years ago
Cargo.toml Solve 2021/04 3 years ago
README.md Solve 2021/04 3 years ago

README.md

https://adventofcode.com/2021/day/4

--- Day 4: Giant Squid ---

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.

Maybe it wants to play bingo?

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.)

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:

[code]

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

22 13 17 11  0
 8  2 23  4 24
21  9 14 16  7
 6 10  3 18  5
 1 12 20 15 19

 3 15  0  2 22
 9 18 13 17  5
19  8  7 25 23
20 11 10 24  4
14 21 16 12  6

14 21 17 24  4
10 16 15  9 19
18  8 23 26 20
22 11 13  6  5
 2  0 12  3  7

[/code]

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):

[code]

22 13 17 _11_  0         3 15  0  2 22        14 21 17 24  _4_
 8  2 23  _4_ 24         _9_ 18 13 17  _5_        10 16 15  _9_ 19
21  _9_ 14 16  _7_        19  8  _7_ 25 23        18  8 23 26 20
 6 10  3 18  _5_        20 _11_ 10 24  _4_        22 _11_ 13  6  _5_
 1 12 20 15 19        14 21 16 12  6         2  0 12  3  _7_

[/code]

After the next six numbers are drawn (17, 23, 2, 0, 14, and 21), there are still no winners:

[code]

22 13 _17_ _11_  _0_         3 15  _0_  _2_ 22        _14_ _21_ _17_ 24  _4_
 8  _2_ _23_  _4_ 24         _9_ 18 13 _17_  _5_        10 16 15  _9_ 19
_21_  _9_ _14_ 16  _7_        19  8  _7_ 25 _23_        18  8 _23_ 26 20
 6 10  3 18  _5_        20 _11_ 10 24  _4_        22 _11_ 13  6  _5_
 1 12 20 15 19        _14_ _21_ 16 12  6         _2_  _0_ 12  3  _7_

[/code]

Finally, 24 is drawn:

[code]

22 13 _17_ _11_  _0_         3 15  _0_  _2_ 22        _14_ _21_ _17_ _24_  _4_
 8  _2_ _23_  _4_ _24_         _9_ 18 13 _17_  _5_        10 16 15  _9_ 19
_21_  _9_ _14_ 16  _7_        19  8  _7_ 25 _23_        18  8 _23_ 26 20
 6 10  3 18  _5_        20 _11_ 10 _24_  _4_        22 _11_ 13  6  _5_
 1 12 20 15 19        _14_ _21_ 16 12  6         _2_  _0_ 12  3  _7_

[/code]

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_).

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_.

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?