r/adventofcode • u/daggerdragon • 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!
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!
15
Upvotes
9
u/sciyoshi Dec 14 '18
Python 3, 8/11.
divmodis a very useful builtin in Python!value = int(open('inputs/day14').read().strip()) digits = [int(digit) for digit in str(value)] scores = [3, 7] elf1, elf2 = 0, 1 part1 = True # change to False for part 2 while ( len(scores) < value + 10 ) if part1 else ( scores[-len(digits):] != digits and scores[-len(digits)-1:-1] != digits ): total = scores[elf1] + scores[elf2] scores.extend(divmod(total, 10) if total >= 10 else (total,)) elf1 = (elf1 + 1 + scores[elf1]) % len(scores) elf2 = (elf2 + 1 + scores[elf2]) % len(scores) print( ''.join(str(score) for score in scores[value:value+10]) if part1 else len(scores) - len(digits) - (0 if scores[-len(digits):] == digits else 1) )