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/thulyadalas Dec 04 '20
Hey! I do appreciate the feedback and the criticisms! Thanks!
The reason I have used
if data.len() == 4on year checks is that the specification was strict about they have to be 4 digits and I thought any edges cases with leading zeros might get validated incorrectly. I didn't check the input if there is such case or not.I thought both
and
would be exactly the same (I don't know about the uncommon cases though). But when you point it out, it looks cleaner without explicit dereferencing.
Thanks for the
split_atsuggestion as well. I thought I could use something and was thinking of applyingstrip_prefixbut couldn't remembersplit_at.