Day 4! I was worried as I was reading the first problem yesterday that I would have to optimize for any rational slope. I'm thankful he decided to take it easier than that for Day 3.
The Puzzle
In today’s puzzle, we're just trying to get through airport security, which is jam-packed because, obviously, Santa's magic keeps the North Pole COVID-free. It's classified as a hum-bug. 🥁 Anyways. The passport scanner is broken and we're doing a good deed by "fixing" it. And by "fixing," we mean "hacking it to let us through but also mostly fixing it."
Y'all. We are THIS close to validating YAML and I am here for it.
The Leaderboards
As always, this is the spot where I’ll plug any leaderboard codes shared from the community.
Ryan's Leaderboard: 224198-25048a19
If you want to generate your own leaderboard and signal boost it a little bit, send it to me either in a DEV message or in a comment on one of these posts and I'll add it to the list above.
Yesterday’s Languages
Updated 03:06PM 12/12/2020 PST.
Language | Count |
---|---|
Python | 8 |
JavaScript | 3 |
Rust | 2 |
Haskell | 2 |
C# | 1 |
Raku | 1 |
COBOL | 1 |
PHP | 1 |
Ruby | 1 |
Elixir | 1 |
Go | 1 |
C | 1 |
Merry Coding!
Top comments (23)
My super gross rust impl. Messy regex. I am sure there are way better ways to parse according to white space.
Also, I sort of went half-way with a struct solution. Probably would have been better to either go all the way or not have custom types at all.
You're not alone in the ugly feeling. I had a particularly nasty bug that gave me one result too many in part two (realized I had a missing ^ and $ on the regex for
pid
).I see a fair amount of similarities in approach, so I'm glad to see I'm in good company. :D
As always, on Github.
I hate problems like this:
Thank you so much for the clear and concise python, I'm new to python and thought this would be an excellent way to learn it. I figured this one out eventually and thought I would come here to see how someone else did it. I don't understand how yours doesn't throw a key error when trying to access dictionary keys that aren't there. I need to learn more about classes but I don't know why this works. If you could point me in the right direction I'd greatly appreciate it. Thank you again for the wonderful example
I went ahead and wrote a solution using PEG in Python (parsimonious library). Aside from the slightly compact PEG grammar, the rest of it is very readable
Not my finest work, I took advantage of the fact that some problems didn't arise in the test data. Then again, this isn't real life, it's a game and I got the stars. 😉
Part 2 here.
I feel this reads as quite elegant in Ruby -- or at least my implementation of it.
Hoping on something more interesting to do for Day 5!
Still not doing these the day the come out but here's my Haskell solution.
Problems like these seem like work to me :P
would anyone be interested in a solution written entirely in C, without regex or hashtables
The input
s
tois_valid
should be a full passport string (what you get after splitting by double new lines). It does parsing + validation at once and eagerly exits if any field validation fails.Yes, I know - very cursed. 'twas just for fun, and to prove a point ;)
Warning this might be offensive to some :D
My Saturday was too long, so I created a code-golfed PHP version (for both parts)
Go again, a bit hacky with the very last element
Feels like it could have been cleaner, my first round was worse though! I refactored to use
Result
and the?
error propagation operator, which was fun.