aoc-2018-python

Advent of Code 2018 Solutions in Python
git clone https://git.sinitax.com/sinitax/aoc-2018-python
Log | Files | Refs | README | sfeed.txt

part1 (4277B)


      1--- Day 9: Marble Mania ---
      2
      3You talk to the Elves while you wait for your navigation system to initialize. To pass the time,
      4they introduce you to their favorite marble game.
      5
      6The Elves play this game by taking turns arranging the marbles in a circle according to very
      7particular rules. The marbles are numbered starting with 0 and increasing by 1 until every marble
      8has a number.
      9
     10First, the marble numbered 0 is placed in the circle. At this point, while it contains only a single
     11marble, it is still a circle: the marble is both clockwise from itself and counter-clockwise from
     12itself. This marble is designated the current marble.
     13
     14Then, each Elf takes a turn placing the lowest-numbered remaining marble into the circle between the
     15marbles that are 1 and 2 marbles clockwise of the current marble. (When the circle is large enough,
     16this means that there is one marble between the marble that was just placed and the current marble.)
     17The marble that was just placed then becomes the current marble.
     18
     19However, if the marble that is about to be placed has a number which is a multiple of 23,
     20something entirely different happens. First, the current player keeps the marble they would have
     21placed, adding it to their score. In addition, the marble 7 marbles counter-clockwise from the
     22current marble is removed from the circle and also added to the current player's score. The marble
     23located immediately clockwise of the marble that was removed becomes the new current marble.
     24
     25For example, suppose there are 9 players. After the marble with value 0 is placed in the middle,
     26each player (shown in square brackets) takes a turn. The result of each of those turns would produce
     27circles of marbles like this, where clockwise is to the right and the resulting current marble is in
     28parentheses:
     29
     30[-] (0)
     31[1]  0 (1)
     32[2]  0 (2) 1 
     33[3]  0  2  1 (3)
     34[4]  0 (4) 2  1  3 
     35[5]  0  4  2 (5) 1  3 
     36[6]  0  4  2  5  1 (6) 3 
     37[7]  0  4  2  5  1  6  3 (7)
     38[8]  0 (8) 4  2  5  1  6  3  7 
     39[9]  0  8  4 (9) 2  5  1  6  3  7 
     40[1]  0  8  4  9  2(10) 5  1  6  3  7 
     41[2]  0  8  4  9  2 10  5(11) 1  6  3  7 
     42[3]  0  8  4  9  2 10  5 11  1(12) 6  3  7 
     43[4]  0  8  4  9  2 10  5 11  1 12  6(13) 3  7 
     44[5]  0  8  4  9  2 10  5 11  1 12  6 13  3(14) 7 
     45[6]  0  8  4  9  2 10  5 11  1 12  6 13  3 14  7(15)
     46[7]  0(16) 8  4  9  2 10  5 11  1 12  6 13  3 14  7 15 
     47[8]  0 16  8(17) 4  9  2 10  5 11  1 12  6 13  3 14  7 15 
     48[9]  0 16  8 17  4(18) 9  2 10  5 11  1 12  6 13  3 14  7 15 
     49[1]  0 16  8 17  4 18  9(19) 2 10  5 11  1 12  6 13  3 14  7 15 
     50[2]  0 16  8 17  4 18  9 19  2(20)10  5 11  1 12  6 13  3 14  7 15 
     51[3]  0 16  8 17  4 18  9 19  2 20 10(21) 5 11  1 12  6 13  3 14  7 15 
     52[4]  0 16  8 17  4 18  9 19  2 20 10 21  5(22)11  1 12  6 13  3 14  7 15 
     53[5]  0 16  8 17  4 18(19) 2 20 10 21  5 22 11  1 12  6 13  3 14  7 15 
     54[6]  0 16  8 17  4 18 19  2(24)20 10 21  5 22 11  1 12  6 13  3 14  7 15 
     55[7]  0 16  8 17  4 18 19  2 24 20(25)10 21  5 22 11  1 12  6 13  3 14  7 15
     56
     57The goal is to be the player with the highest score after the last marble is used up. Assuming the
     58example above ends after the marble numbered 25, the winning score is 23+9=32 (because player 5 kept
     59marble 23 and removed marble 9, while no other player got any points in this very short example
     60game).
     61
     62Here are a few more examples:
     63
     64
     65 - 10 players; last marble is worth 1618 points: high score is 8317
     66
     67 - 13 players; last marble is worth 7999 points: high score is 146373
     68
     69 - 17 players; last marble is worth 1104 points: high score is 2764
     70
     71 - 21 players; last marble is worth 6111 points: high score is 54718
     72
     73 - 30 players; last marble is worth 5807 points: high score is 37305
     74
     75
     76What is the winning Elf's score?
     77
     78