aoc-2021-rust

Advent of Code 2021 Solutions in Rust
git clone https://git.sinitax.com/sinitax/aoc-2021-rust
Log | Files | Refs | README | sfeed.txt

part1 (4140B)


      1--- Day 4: Giant Squid ---
      2
      3You're already almost 1.5km (almost a mile) below the surface of the ocean, already so deep that you
      4can't see any sunlight. What you can see, however, is a giant squid that has attached itself to the
      5outside of your submarine.
      6
      7Maybe it wants to play bingo?
      8
      9Bingo is played on a set of boards each consisting of a 5x5 grid of numbers. Numbers are chosen at
     10random, and the chosen number is marked on all boards on which it appears. (Numbers may not appear
     11on all boards.) If all numbers in any row or any column of a board are marked, that board
     12wins. (Diagonals don't count.)
     13
     14The submarine has a bingo subsystem to help passengers (currently, you and the giant squid) pass the
     15time. It automatically generates a random order in which to draw numbers and a random set of boards
     16(your puzzle input). For example:
     17
     187,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
     19
     2022 13 17 11  0
     21 8  2 23  4 24
     2221  9 14 16  7
     23 6 10  3 18  5
     24 1 12 20 15 19
     25
     26 3 15  0  2 22
     27 9 18 13 17  5
     2819  8  7 25 23
     2920 11 10 24  4
     3014 21 16 12  6
     31
     3214 21 17 24  4
     3310 16 15  9 19
     3418  8 23 26 20
     3522 11 13  6  5
     36 2  0 12  3  7
     37
     38After the first five numbers are drawn (7, 4, 9, 5, and 11), there are no winners, but the boards
     39are marked as follows (shown here adjacent to each other to save space):
     40
     4122 13 17 11  0         3 15  0  2 22        14 21 17 24  4
     42 8  2 23  4 24         9 18 13 17  5        10 16 15  9 19
     4321  9 14 16  7        19  8  7 25 23        18  8 23 26 20
     44 6 10  3 18  5        20 11 10 24  4        22 11 13  6  5
     45 1 12 20 15 19        14 21 16 12  6         2  0 12  3  7
     46
     47After the next six numbers are drawn (17, 23, 2, 0, 14, and 21), there are still no winners:
     48
     4922 13 17 11  0         3 15  0  2 22        14 21 17 24  4
     50 8  2 23  4 24         9 18 13 17  5        10 16 15  9 19
     5121  9 14 16  7        19  8  7 25 23        18  8 23 26 20
     52 6 10  3 18  5        20 11 10 24  4        22 11 13  6  5
     53 1 12 20 15 19        14 21 16 12  6         2  0 12  3  7
     54
     55Finally, 24 is drawn:
     56
     5722 13 17 11  0         3 15  0  2 22        14 21 17 24  4
     58 8  2 23  4 24         9 18 13 17  5        10 16 15  9 19
     5921  9 14 16  7        19  8  7 25 23        18  8 23 26 20
     60 6 10  3 18  5        20 11 10 24  4        22 11 13  6  5
     61 1 12 20 15 19        14 21 16 12  6         2  0 12  3  7
     62
     63At this point, the third board wins because it has at least one complete row or column of marked
     64numbers (in this case, the entire top row is marked: 14 21 17 24  4).
     65
     66The score of the winning board can now be calculated. Start by finding the sum of all unmarked
     67numbers on that board; in this case, the sum is 188. Then, multiply that sum by the number that was
     68just called when the board won, 24, to get the final score, 188 * 24 = 4512.
     69
     70To guarantee victory against the giant squid, figure out which board will win first. What will your
     71final score be if you choose that board?
     72
     73