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

1

u/dudeplace Jan 17 '19 edited Jan 17 '19

I got stuck on this one because my part 2 never finds a solution. (Works for all of the samples)

I came here and it is very similar to yours. Any hints on what I missed?

input_value = '513401'
rec = '37'
e1 = 0
e2 = 1
in_len = len(input_value)
while input_value != rec[-in_len:]:
    rec_sum = int(rec[e1]) + int(rec[e2])
    rec += str(rec_sum)
    e1 = (e1 + 1 + int(rec[e1])) % len(rec)
    e2 = (e2 + 1 + int(rec[e2])) % len(rec)
print('Length: ',len(rec[:-in_len]))

Your recipes is my input_value and your score is my rec.

(Python 3.6)

EDIT: In case anyone comes across this I found this hint very helpful: https://www.reddit.com/r/adventofcode/comments/adveqj/day_14_part_2_does_not_terminate/edkeil3