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 (3026B)


      1--- Day 21: Dirac Dice ---
      2
      3There's not much to do as you slowly descend to the bottom of the ocean. The submarine computer
      4challenges you to a nice game of Dirac Dice.
      5
      6This game consists of a single die, two pawns, and a game board with a circular track containing ten
      7spaces marked 1 through 10 clockwise. Each player's starting space is chosen randomly (your puzzle
      8input). Player 1 goes first.
      9
     10Players take turns moving. On each player's turn, the player rolls the die three times and adds up
     11the results. Then, the player moves their pawn that many times forward around the track (that is,
     12moving clockwise on spaces in order of increasing value, wrapping back around to 1 after 10). So, if
     13a player is on space 7 and they roll 2, 2, and 1, they would move forward 5 times, to spaces 8, 9,
     1410, 1, and finally stopping on 2.
     15
     16After each player moves, they increase their score by the value of the space their pawn stopped on.
     17Players' scores start at 0. So, if the first player starts on space 7 and rolls a total of 5, they
     18would stop on space 2 and add 2 to their score (for a total score of 2). The game immediately ends
     19as a win for any player whose score reaches at least 1000.
     20
     21Since the first game is a practice game, the submarine opens a compartment labeled
     22deterministic dice and a 100-sided die falls out. This die always rolls 1 first, then 2, then 3, and
     23so on up to 100, after which it starts over at 1 again. Play using this die.
     24
     25For example, given these starting positions:
     26
     27Player 1 starting position: 4
     28Player 2 starting position: 8
     29
     30This is how the game would go:
     31
     32
     33 - Player 1 rolls 1+2+3 and moves to space 10 for a total score of 10.
     34
     35 - Player 2 rolls 4+5+6 and moves to space 3 for a total score of 3.
     36
     37 - Player 1 rolls 7+8+9 and moves to space 4 for a total score of 14.
     38
     39 - Player 2 rolls 10+11+12 and moves to space 6 for a total score of 9.
     40
     41 - Player 1 rolls 13+14+15 and moves to space 6 for a total score of 20.
     42
     43 - Player 2 rolls 16+17+18 and moves to space 7 for a total score of 16.
     44
     45 - Player 1 rolls 19+20+21 and moves to space 6 for a total score of 26.
     46
     47 - Player 2 rolls 22+23+24 and moves to space 6 for a total score of 22.
     48
     49
     50...after many turns...
     51
     52
     53 - Player 2 rolls 82+83+84 and moves to space 6 for a total score of 742.
     54
     55 - Player 1 rolls 85+86+87 and moves to space 4 for a total score of 990.
     56
     57 - Player 2 rolls 88+89+90 and moves to space 3 for a total score of 745.
     58
     59 - Player 1 rolls 91+92+93 and moves to space 10 for a final score, 1000.
     60
     61
     62Since player 1 has at least 1000 points, player 1 wins and the game ends. At this point, the losing
     63player had 745 points and the die had been rolled a total of 993 times; 745 * 993 =
     64739785.
     65
     66Play a practice game using the deterministic 100-sided die. The moment either player wins,
     67what do you get if you multiply the score of the losing player by the number of times the die was
     68rolled during the game?
     69
     70