
Advent of Code Python Solutions, Explained - fogleman
https://www.michaelfogleman.com/aoc18/
======
fogleman
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...](https://github.com/norvig/pytudes/blob/master/ipynb/Advent%202017.ipynb)

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](https://adventofcode.com/2018/leaderboard)

~~~
CobrastanJorji
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.

~~~
fogleman
Thank you!

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

~~~
a_humean
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.

------
bentleycook
I've really enjoyed these solutions in Javascript:
[https://beta.observablehq.com/collection/@mpcowan/advent-
of-...](https://beta.observablehq.com/collection/@mpcowan/advent-of-
code-2018).

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

------
jurassicfoxy
I recommend reading the solutions on the Advent of Code subreddit:
[https://www.reddit.com/r/adventofcode/](https://www.reddit.com/r/adventofcode/)

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

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

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

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

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

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

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

~~~
nestorD
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/](https://www.reddit.com/comments/a6f100/-/ebw1uda/)

