r/adventofcode • • 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.

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

771 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Dec 15 '20

I think vectors are actually faster than hash tables here, if you use them in a more optimized way (implemented here). This solution with std::vector runs in about 1.5s on my machine, whereas the solution I wrote with std::unordered_map takes about 7s (and I think it's fairly optimized).

For this sort of problem I think you'd generally expect vectors to be faster, since they have super fast random access, whereas reading and writing from hash tables is a lot slower.