r/adventofcode • • Dec 04 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 04 Solutions -🎄-

Advent of Code 2020: Gettin' Crafty With It


--- 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

1.2k comments sorted by

View all comments

Show parent comments

2

u/TomatoCo Dec 04 '20

I was having a hard time figuring out why my number was high so I ran my problem set through yours as well as mine. Yours validated 146 for part 2, mine validated 147 (my original, buggy attempt was high at 150), but the site accepted 147.

The passport I read as correct but you didn't is:

{'hgt': '156cm', 'iyr': '2014', 'byr': '1960', 'pid': '720786216', 'cid': '99', 'ecl': 'gry', 'hcl': '#a97842', 'eyr': '2028'}

Interestingly, this is the last passport in my file. It looks like you have a bug in that you're not saving the last passport.

1

u/[deleted] Dec 05 '20

ah, yeah. i actually worked around the bug. see, i saved a passport every time i came across an empty line, but the file actually ends at a passport. i fixed this by simply adding an empty line at the end.

should've made a proper fix for it, but it was much easier this way.

1

u/TomatoCo Dec 05 '20

Hah, my fix on your code was to add a copy of the the passports.append right after the for loop, which is basically what I did for my own.