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 t...
For further actions, you may consider blocking this person and/or reporting abuse
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.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.
I might have created the dirtiest js code in the world for this
Plain forgot to break out of the comfort zone and use something other than javascript :|
I'll try C tomorrow
Here's today:
(added
check
as a way to see which field validator was broken when I failed part 2 the first time. It was a stupid typo in 'ecl')This was a long one, but I learned a ton about the
<string.h>
library. I also incremented a macro by 1 and spent 3 hours chasing a segfault. So, all in all, I think it sounds like we all had similar days. There are also several edge cases that I'm pretty sure my code doesn't cover, BUT that doesn't matter because this is AoC and it's not wrong if you get the stars. Right? Right?Day4.h:
Day4.c:
Hi,
A lot of class for this one in order to limit each class responsability.
Full size here : Advent of Code - Day 4
Here is a Haskell soloution for Day 4:
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
Again, more javascript. It's in a gist if you like that sort of thing.
Part 1 required far less code than part 2 😋
God damn, it was not that easy for me! To be honest, I'm not the best with both algorithms and Elixir, but... anyway AoC is a great chance to improve these skills. I've wasted time making stupid things with Regex. Facepalm.
There is my solution for the first step:
And the second step:
My JavaScript walkthrough: