diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-04-07 17:18:18 -0400 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-04-07 17:19:39 -0400 |
| commit | 87ab487d59fa85dbe2afa55cc841b02805ae42ca (patch) | |
| tree | cd90ab715e1b5b5803674045dbafd6d51d27ac90 /src/09 | |
| parent | 1bcc82c5bfbde87edd03c01ffdf9ee5934681592 (diff) | |
| download | aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.tar.gz aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.zip | |
Reorder days into src
Diffstat (limited to 'src/09')
| -rw-r--r-- | src/09/input | 1 | ||||
| -rw-r--r-- | src/09/part1 | 78 | ||||
| -rw-r--r-- | src/09/part2 | 15 | ||||
| -rw-r--r-- | src/09/solve.py | 43 |
4 files changed, 137 insertions, 0 deletions
diff --git a/src/09/input b/src/09/input new file mode 100644 index 0000000..29b93ef --- /dev/null +++ b/src/09/input @@ -0,0 +1 @@ +418 players; last marble is worth 71339 points diff --git a/src/09/part1 b/src/09/part1 new file mode 100644 index 0000000..d9bccb0 --- /dev/null +++ b/src/09/part1 @@ -0,0 +1,78 @@ +--- Day 9: Marble Mania --- + +You talk to the Elves while you wait for your navigation system to initialize. To pass the time, +they introduce you to their favorite marble game. + +The Elves play this game by taking turns arranging the marbles in a [1m[97mcircle[0m according to very +particular rules. The marbles are numbered starting with 0 and increasing by 1 until every marble +has a number. + +First, the marble numbered 0 is placed in the circle. At this point, while it contains only a single +marble, it is still a circle: the marble is both clockwise from itself and counter-clockwise from +itself. This marble is designated the [1m[97mcurrent marble[0m. + +Then, each Elf takes a turn placing the [1m[97mlowest-numbered remaining marble[0m into the circle between the +marbles that are 1 and 2 marbles [1m[97mclockwise[0m of the current marble. (When the circle is large enough, +this means that there is one marble between the marble that was just placed and the current marble.) +The marble that was just placed then becomes the [1m[97mcurrent marble[0m. + +However, if the marble that is about to be placed has a number which is a multiple of 23, +[1m[97msomething entirely different happens[0m. First, the current player keeps the marble they would have +placed, adding it to their [1m[97mscore[0m. In addition, the marble 7 marbles [1m[97mcounter-clockwise[0m from the +current marble is [1m[97mremoved[0m from the circle and [1m[97malso[0m added to the current player's score. The marble +located immediately [1m[97mclockwise[0m of the marble that was removed becomes the new [1m[97mcurrent marble[0m. + +For example, suppose there are 9 players. After the marble with value 0 is placed in the middle, +each player (shown in square brackets) takes a turn. The result of each of those turns would produce +circles of marbles like this, where clockwise is to the right and the resulting current marble is in +parentheses: + +[-] [1m[97m(0)[0m +[1] 0[1m[97m (1)[0m +[2] 0[1m[97m (2)[0m 1 +[3] 0 2 1[1m[97m (3)[0m +[4] 0[1m[97m (4)[0m 2 1 3 +[5] 0 4 2[1m[97m (5)[0m 1 3 +[6] 0 4 2 5 1[1m[97m (6)[0m 3 +[7] 0 4 2 5 1 6 3[1m[97m (7)[0m +[8] 0[1m[97m (8)[0m 4 2 5 1 6 3 7 +[9] 0 8 4[1m[97m (9)[0m 2 5 1 6 3 7 +[1] 0 8 4 9 2[1m[97m(10)[0m 5 1 6 3 7 +[2] 0 8 4 9 2 10 5[1m[97m(11)[0m 1 6 3 7 +[3] 0 8 4 9 2 10 5 11 1[1m[97m(12)[0m 6 3 7 +[4] 0 8 4 9 2 10 5 11 1 12 6[1m[97m(13)[0m 3 7 +[5] 0 8 4 9 2 10 5 11 1 12 6 13 3[1m[97m(14)[0m 7 +[6] 0 8 4 9 2 10 5 11 1 12 6 13 3 14 7[1m[97m(15)[0m +[7] 0[1m[97m(16)[0m 8 4 9 2 10 5 11 1 12 6 13 3 14 7 15 +[8] 0 16 8[1m[97m(17)[0m 4 9 2 10 5 11 1 12 6 13 3 14 7 15 +[9] 0 16 8 17 4[1m[97m(18)[0m 9 2 10 5 11 1 12 6 13 3 14 7 15 +[1] 0 16 8 17 4 18 9[1m[97m(19)[0m 2 10 5 11 1 12 6 13 3 14 7 15 +[2] 0 16 8 17 4 18 9 19 2[1m[97m(20)[0m10 5 11 1 12 6 13 3 14 7 15 +[3] 0 16 8 17 4 18 9 19 2 20 10[1m[97m(21)[0m 5 11 1 12 6 13 3 14 7 15 +[4] 0 16 8 17 4 18 9 19 2 20 10 21 5[1m[97m(22)[0m11 1 12 6 13 3 14 7 15 +[5] 0 16 8 17 4 18[1m[97m(19)[0m 2 20 10 21 5 22 11 1 12 6 13 3 14 7 15 +[6] 0 16 8 17 4 18 19 2[1m[97m(24)[0m20 10 21 5 22 11 1 12 6 13 3 14 7 15 +[7] 0 16 8 17 4 18 19 2 24 20[1m[97m(25)[0m10 21 5 22 11 1 12 6 13 3 14 7 15 + +The goal is to be the [1m[97mplayer with the highest score[0m after the last marble is used up. Assuming the +example above ends after the marble numbered 25, the winning score is 23+9=[1m[97m32[0m (because player 5 kept +marble 23 and removed marble 9, while no other player got any points in this very short example +game). + +Here are a few more examples: + + + - 10 players; last marble is worth 1618 points: high score is [1m[97m8317[0m + + - 13 players; last marble is worth 7999 points: high score is [1m[97m146373[0m + + - 17 players; last marble is worth 1104 points: high score is [1m[97m2764[0m + + - 21 players; last marble is worth 6111 points: high score is [1m[97m54718[0m + + - 30 players; last marble is worth 5807 points: high score is [1m[97m37305[0m + + +[1m[97mWhat is the winning Elf's score?[0m + + diff --git a/src/09/part2 b/src/09/part2 new file mode 100644 index 0000000..f521c4d --- /dev/null +++ b/src/09/part2 @@ -0,0 +1,15 @@ +--- Part Two --- + +[1m[97mYou now have a complete Intcode computer.[0m + +Finally, you can lock on to the Ceres distress signal! You just need to boost your sensors using the +BOOST program. + +The program runs in sensor boost mode by providing the input instruction the value 2. Once run, it +will boost the sensors automatically, but it might take a few seconds to complete the operation on +slower hardware. In sensor boost mode, the program will output a single value: [1m[97mthe coordinates of +the distress signal[0m. + +Run the BOOST program in sensor boost mode. [1m[97mWhat are the coordinates of the distress signal?[0m + + diff --git a/src/09/solve.py b/src/09/solve.py new file mode 100644 index 0000000..f0aa4bf --- /dev/null +++ b/src/09/solve.py @@ -0,0 +1,43 @@ +import sys
+sys.path.append("../common")
+import aoc
+
+from collections import deque
+
+words = aoc.data.split(" ")
+playercount = int(words[0])
+lastworth = int(words[6])
+
+def highscore(playercount, lastworth):
+ lastworth = lastworth - lastworth % 23
+
+ players = [0 for x in range(playercount)]
+ marbles = deque([0])
+ pos = 0
+ for i in range(1, lastworth+1):
+ if i % 23 == 0:
+ cp = (i-1) % playercount
+ players[cp] += i + marbles[(len(marbles) + pos - 7) % len(marbles)]
+ marbles.rotate((len(marbles) - 1 - pos) + 7)
+ marbles.pop()
+ pos = 0
+ else:
+ if i < 3:
+ pos = 1
+ marbles.rotate(1)
+ marbles.append(i)
+ else:
+ marbles.rotate((len(marbles)- 1 -pos) - 1)
+ marbles.append(i)
+ pos = len(marbles)-1
+
+ return max(players)
+
+
+def solve1(args):
+ return highscore(playercount, lastworth)
+
+def solve2(args):
+ return highscore(playercount, lastworth * 100)
+
+aoc.run(solve1, solve2, sols=[412127, 3482394794])
|
