r/adventofcode • u/daggerdragon • Dec 15 '20
SOLUTION MEGATHREAD -🎄- 2020 Day 15 Solutions -🎄-
Advent of Code 2020: Gettin' Crafty With It
- 7 days remaining until the submission deadline on December 22 at 23:59 EST
- Full details and rules are in the Submissions Megathread
--- Day 15: Rambunctious Recitation ---
Post your code solution in this megathread.
- Include what language(s) your solution uses!
- Here's a quick link to /u/topaz2078's
pasteif you need it for longer code blocks. - The full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:09:24, megathread unlocked!
39
Upvotes
View all comments
1
u/rprouse Dec 15 '20 edited Dec 16 '20
C
I'd written this as an array with the number of turns for part one and searched backwards in the array each turn which worked great, but I should have known that the second part would be a huge number of turns and written it for that in the first place.
For part 2, I rewrote my solution with a
Dictionary<int, int>where the key is the number that was spoken and the value is the turn where it was last spoken. This gives me a fairly quick lookup although it still took 3.4 seconds to solve.I then refactored that to use a sparse array instead of the
Dictionary, trading memory for performance. This dropped the execution time to just over a half second.https://github.com/rprouse/AdventOfCode/blob/master/AdventOfCode2020/Day15/Day15.cs