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!
Latest comments (23)
Still not doing these the day the come out but here's my Haskell solution.
Problems like these seem like work to me :P
My JavaScript walkthrough:
Ruby, part 2:
This is a fun little thread. Since there's no C# representation, I figured I would share my solution. I have a little framework code that handles some stuff behind the scenes such as locating and reading the file, as well as validating the solving on the sample data returns the correct solution, so you won't see any of that in the code here:
Part 1
Part 2
Passport
Warning this might be offensive to some :D
My Saturday was too long, so I created a code-golfed PHP version (for both parts)
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 ;)
Go again, a bit hacky with the very last element
Reading all of these solutions, I'm glad I opted to avoid regexes in my answers! There are some messy hacks here (
"1234567890abcdef".indexOf(c)
stands out) and the types should probably all have beenstring?
instead ofstring
, which would have made this a little more concise, but I'm still pretty happy with how it turned out.I am annoyed they decided to put multiple K:V pairs on the same line because it made the parsing a little messier but oh well.
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.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