137
SOLUTION MEGATHREAD-🎄- 2020 Day 1 Solutions -🎄-(self.adventofcode)
submitted 5 years, 1 month ago* (edited 3 hours, 3 minutes after) by daggerdragon to /r/adventofcode (134.8k)
It's been one heck of a crappy year, so let's make the holidays bright with Advent of Code 2020! If ...
since 5 years, 1 month ago
1 of 1
Tip Reveddit Real-Time can notify you when your content is removed.
your account history
Tip Check if your account has any removed comments.
view my removed comments you are viewing a single comment's thread.
view all comments


Rust
In this problem, I had to find two numbers that add up to 2020. While I could have put two loops, it's possible to reorder the terms in
a + b = 2020to2020 - a = b. This allows retrievingbby merely knowing whatais, and this number could be checked for existence in a list in constant time with hash sets.I also used this fact in second part of a puzzle which allowed to reduce the complexity from O(N3) to O(N2).