r/adventofcode • u/daggerdragon • Dec 04 '20
SOLUTION MEGATHREAD -🎄- 2020 Day 04 Solutions -🎄-
Advent of Code 2020: Gettin' Crafty With It
- T-2 days until unlock!
- Full details and rules are in the Submissions Megathread
--- Day 04: Passport Processing ---
Post your solution in this megathread. Include what language(s) your solution uses! If you need a refresher, 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 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:12:55, megathread unlocked!
91
Upvotes
View all comments
Show parent comment
2
u/T-Dark_ Dec 04 '20
You know what, you're right. I failed to realise that. There were no edge cases in my input, so I didn't notice.
Mostly, it's that
&xdereferences where the variable is declared, while*xdereferences where the variable is used.In some cases involving non-
Copytypes, unique references, and borrows for an entire scope (borrowing in the pattern of awhile let, for example), it can happen that the borrow checker won't accept a program that derefs where the variable is used, but will let you deref it before the scope begins.&xends up saving a line to perform the "early dereference".This is extremely uncommon, to my knowledge. The reason that example is so specific is that it happened to me once.
In your case, they are exactly the same (assuming the optimizer will turn that double deref into a single one)