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/14 | |
| parent | 1bcc82c5bfbde87edd03c01ffdf9ee5934681592 (diff) | |
| download | aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.tar.gz aoc2018-python-87ab487d59fa85dbe2afa55cc841b02805ae42ca.zip | |
Reorder days into src
Diffstat (limited to 'src/14')
| -rw-r--r-- | src/14/input | 1 | ||||
| -rw-r--r-- | src/14/part1 | 70 | ||||
| -rw-r--r-- | src/14/part2 | 18 | ||||
| -rw-r--r-- | src/14/solve.py | 37 |
4 files changed, 126 insertions, 0 deletions
diff --git a/src/14/input b/src/14/input new file mode 100644 index 0000000..1c93252 --- /dev/null +++ b/src/14/input @@ -0,0 +1 @@ +110201 diff --git a/src/14/part1 b/src/14/part1 new file mode 100644 index 0000000..912c55a --- /dev/null +++ b/src/14/part1 @@ -0,0 +1,70 @@ +--- Day 14: Chocolate Charts --- + +You finally have a chance to look at all of the produce moving around. Chocolate, cinnamon, mint, +chili peppers, nutmeg, vanilla... the Elves must be growing these plants to make [1m[97mhot chocolate[0m! As +you realize this, you hear a conversation in the distance. When you go to investigate, you discover +two Elves in what appears to be a makeshift underground kitchen/laboratory. + +The Elves are trying to come up with the ultimate hot chocolate recipe; they're even maintaining a +scoreboard which tracks the quality [1m[97mscore[0m (0-9) of each recipe. + +Only two recipes are on the board: the first recipe got a score of 3, the second, 7. Each of the two +Elves has a [1m[97mcurrent recipe[0m: the first Elf starts with the first recipe, and the second Elf starts +with the second recipe. + +To create new recipes, the two Elves combine their current recipes. This creates new recipes from +the [1m[97mdigits of the sum[0m of the current recipes' scores. With the current recipes' scores of 3 and 7, +their sum is 10, and so two new recipes would be created: the first with score 1 and the second with +score 0. If the current recipes' scores were 2 and 3, the sum, 5, would only create one recipe (with +a score of 5) with its single digit. + +The new recipes are added to the end of the scoreboard in the order they are created. So, after the +first round, the scoreboard is 3, 7, 1, 0. + +After all new recipes are added to the scoreboard, each Elf picks a new current recipe. To do this, +the Elf steps forward through the scoreboard a number of recipes equal to [1m[97m1 plus the score of their +current recipe[0m. So, after the first round, the first Elf moves forward 1 + 3 = 4 times, while the +second Elf moves forward 1 + 7 = 8 times. If they run out of recipes, they loop back around to the +beginning. After the first round, both Elves happen to loop around until they land on the same +recipe that they had in the beginning; in general, they will move to different recipes. + +Drawing the first Elf as parentheses and the second Elf as square brackets, they continue this +process: + +(3)[7] +(3)[7] 1 0 + 3 7 1 [0](1) 0 + 3 7 1 0 [1] 0 (1) +(3) 7 1 0 1 0 [1] 2 + 3 7 1 0 (1) 0 1 2 [4] + 3 7 1 [0] 1 0 (1) 2 4 5 + 3 7 1 0 [1] 0 1 2 (4) 5 1 + 3 (7) 1 0 1 0 [1] 2 4 5 1 5 + 3 7 1 0 1 0 1 2 [4](5) 1 5 8 + 3 (7) 1 0 1 0 1 2 4 5 1 5 8 [9] + 3 7 1 0 1 0 1 [2] 4 (5) 1 5 8 9 1 6 + 3 7 1 0 1 0 1 2 4 5 [1] 5 8 9 1 (6) 7 + 3 7 1 0 (1) 0 1 2 4 5 1 5 [8] 9 1 6 7 7 + 3 7 [1] 0 1 0 (1) 2 4 5 1 5 8 9 1 6 7 7 9 + 3 7 1 0 [1] 0 1 2 (4) [1m[97m5 1 5 8 9 1 6 7 7 9[0m 2 + +The Elves think their skill will improve after making a few recipes (your puzzle input). However, +that could take ages; you can speed this up considerably by identifying [1m[97mthe scores of the ten +recipes[0m after that. For example: + + + - If the Elves think their skill will improve after making 9 recipes, the scores of the ten recipes +[1m[97mafter[0m the first nine on the scoreboard would be 5158916779 (highlighted in the last line of the +diagram). + + - After 5 recipes, the scores of the next ten would be 0124515891. + + - After 18 recipes, the scores of the next ten would be 9251071085. + + - After 2018 recipes, the scores of the next ten would be 5941429882. + + +[1m[97mWhat are the scores of the ten recipes immediately after the number of recipes in your puzzle +input?[0m + + diff --git a/src/14/part2 b/src/14/part2 new file mode 100644 index 0000000..1fc54ca --- /dev/null +++ b/src/14/part2 @@ -0,0 +1,18 @@ +--- Part Two --- + +After collecting ORE for a while, you check your cargo hold: [1m[97m1 trillion[0m ([1m[97m1000000000000[0m) units of +ORE. + +[1m[97mWith that much ore[0m, given the examples above: + + + - The 13312 ORE-per-FUEL example could produce [1m[97m82892753[0m FUEL. + + - The 180697 ORE-per-FUEL example could produce [1m[97m5586022[0m FUEL. + + - The 2210736 ORE-per-FUEL example could produce [1m[97m460664[0m FUEL. + + +Given 1 trillion ORE, [1m[97mwhat is the maximum amount of FUEL you can produce?[0m + + diff --git a/src/14/solve.py b/src/14/solve.py new file mode 100644 index 0000000..a6c63a3 --- /dev/null +++ b/src/14/solve.py @@ -0,0 +1,37 @@ +import sys
+sys.path.append("../common")
+import aoc
+
+data = aoc.data
+recipes = [3, 7]
+
+def solve1(args):
+ global recipes, data
+
+ end = int(data)
+ workers = [i for i in range(2)]
+ while len(recipes) < end + 10:
+ recipes += [int(c) for c in str(sum(recipes[workers[i]] for i in range(len(workers))))]
+ for i in range(len(workers)):
+ workers[i] = (workers[i] + recipes[workers[i]]+1) % len(recipes)
+ return "".join([str(x) for x in recipes[end:]])
+
+def solve2(args):
+ global recipes, data
+
+ ilen = len(data)
+ data = [int(c) for c in data]
+ workers = [i for i in range(2)]
+ stop = False
+ counter = 0
+ while not stop:
+ for v in [int(c) for c in str(sum(recipes[workers[i]] for i in range(len(workers))))]:
+ if recipes[-ilen:] == data:
+ stop = True
+ break
+ recipes.append(v)
+ for i in range(len(workers)):
+ workers[i] = (workers[i] + recipes[workers[i]]+1) % len(recipes)
+ return len(recipes) - ilen
+
+aoc.run(solve1, solve2, sols=["6107101544", 20291131])
|
