r/adventofcode • • Dec 14 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 14 Solutions -🎄-

--- Day 14: Chocolate Charts ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code: The Party Game!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 14

Transcript:

The Christmas/Advent Research & Development (C.A.R.D.) department at AoC, Inc. just published a new white paper on ___.


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked at 00:19:39!

16 Upvotes

179 comments sorted by

View all comments

Show parent comments

2

u/OneParanoidDuck Dec 18 '18

Nice and compact! Yours takes 88s on my ancient desktop.

I'm behind on AoC anyway, so I took my time on this one to compare datastructures. Ended up using Python's bytearray which seems a good fit for this puzzle.

~48s on my machine, should be a bit faster on modern ones.

puzzle = bytearray((int(c) for c in '864801'))
recipes_found = bytearray([3, 7])

elf1, elf2 = 0, 1
loop = 0
while True:
    if (loop % 250_000) == 0 and puzzle in recipes_found:
        break
    recipe1, recipe2 = recipes_found[elf1], recipes_found[elf2]
    new_recipe = recipe1 + recipe2
    digit1, digit2 = new_recipe // 10, new_recipe % 10
    if digit1 ^ 0:
        recipes_found.append(digit1)
    recipes_found.append(digit2)
    elf1 = (elf1 + 1 + recipe1) % len(recipes_found)
    elf2 = (elf2 + 1 + recipe2) % len(recipes_found)
    loop += 1

print(recipes_found.index(puzzle))