Hacker News new | past | comments | ask | show | jobs | submit login
Advent of Code Python Solutions, Explained (michaelfogleman.com)
134 points by fogleman on Dec 18, 2018 | hide | past | favorite | 17 comments

OP here. I really enjoyed reading through Peter Norvig's AoC solutions a while back: https://github.com/norvig/pytudes/blob/master/ipynb/Advent%2...

I'm no Norvig, but I thought I'd try my hand at walking the reader through my own solutions this year. This is what I've come up with so far!

I'm currently 9th on the global leaderboard: https://adventofcode.com/2018/leaderboard

Hey OP, great job! While I see your notes that you've cleaned up your solutions after the fact, what you've published is remarkably clean, concise, and beautiful code.

Thank you!

9th on the leaderboard is insane, great work.

Well done. Great job taking the lead.

I love looking at other ways to solve these problems.

But I hope it remains clear to all that there's no singular right way to solve them. I remember writing a few of them thinking, "the big O is terrible but this is so much more obvious to read." Or even, "I bet part 2 will want to do X so I'll make it more robust for refactoring." So many variables. Fun to practice which ones you constrain.

I've enjoyed solving them on my own and then looking at the other solutions in the AoC subreddit. Its really interesting to see how people solve them in lots of languages including the language I wrote in. Usually I learn something new, and even if its in a different language I can see optimisations that I could apply to my solution.

I've really enjoyed these solutions in Javascript: https://beta.observablehq.com/collection/@mpcowan/advent-of-....

Observable has made it fun to follow along and re-run the code.

I recommend reading the solutions on the Advent of Code subreddit: https://www.reddit.com/r/adventofcode/

There are much more interesting, highly optimized solutions and better discussion, animations, etc.

Thanks for the link, OP.

Looking at just Days 1 and 2, the author has given examples that are certainly concise, but (arguably) at the expense of readability. Similarly, the Day 2 part 2 answer is concise at the expense of performance, as there is a lot of duplicated comparisons and comparisons that could be skipped.

In an alternate reality, I made the solutions more performant and you criticized them for being too verbose.

I think it's worth noting that the problems are such that many solution don't need performance, and then later there are problems that do need performance, and of course those that no matter how much performance you had you have to work another approach entirely.

I was amused watching some people doing day 9 having solved it using a good datastructure and confused why p2 was so simple, vs watching people having no idea about their languages performance for the baked in collections they were using.

Fair point. I wasn't trying to necessarily criticize the solutions, but personally found differences between the given solutions and my own enlightening.

Haha, fair enough. There's certainly a balance to be made.

Thank you for this. I always like reading people's writeups for problems like these. Cheers.

Im still stuck on Day 15 in F# :| Trying to resist copying OPs python search algorithm.

And it might not even work. Some solutions work only on a fraction of inputs due to a vicious tie-breaking rule.

This thread might help you if you already pass all the tests : https://www.reddit.com/comments/a6f100/-/ebw1uda/

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact