77 points · by keithnz · 7y ago · 54 comments
For me I found it quite a nice learning exercise, though oddly enough ( I was trying to do them as fast as I could ) I often resorted to mega functions and basic data types to solve the problems. This worked out well early in the event, but later it would lead to many simple bugs. I also found that it's nice when your language has a lot of toys to make life easier. I started with Go, as a learning exercise, but swapped to C# as so many problems fit nicely with "Linq", however there were lots of missing niceties, so I spawned a NuGet package with a library of extension methods which I hope to polish now that AoC is over
What are your takeaways?
On day 6 I got a stack overflow, so I had to quickly implement new/delete. For the Elf processor I had to add in binary operators. Design-wise it taught me that good literals can be really helpful, e. g. an initializer expression for an array of structs. With Python's dict/tuple/array literals e. g. you could sometimes replace parsing entirely with a couple text transformations in Sublime. Maybe this is specific to these kinds of problems, but I think it would also be helpful for unit tests.
It was fun to learn a new algorithm (A*) and implement it. Day 23 part 2 was my favorite. I was stuck for hours, tried two solutions that didn't work out. Went to bed frustrated, then implemented the solution the next morning. I'm still thinking about it, it's an interesting problem.
Day 23 part 2 (teleportation nanobots one) was fairly difficult as well; I tried to implement an actual solution, but failed because of wrong assumptions about its correctness. (I tried to represent the intersection of a number of octahedrons with the bounded volume of 8 planes, but it seems that representation is redundant, so there are invalid configurations. I didn't feel like fixing that anymore after 8+ hours.) Looking at the solutions board on reddit, I wrote a smtlib2 script for Z3 that solves it; it works, but isn't all that satisfying.
The sheer amount of pathfinding amazed me; some of the plain pathfinding problems were good (day 22 with its pathfinding in the implicit graph where you split nodes up into the various combinations of tools), and I was happy to see that day 25 was just an unordered graph component analysis (i.e. a few floodfills).
I liked yesteryear more, and in general I'd like to see smaller problem statements (and thereby also less details to implement!), and possibly slightly more of an algorithmic challenge, though the latter is definitely not necessary (this is not a competitive programming competition, it's an advent calendar of all things!).
Still, big thanks to Eric for giving us this!
(I did the problems in Rust, to become more familiar with the language. See my implementations here[1].)
In particular, Day 23 was pretty remarkable for the sheer number of "solutions" posted to the solutions board that worked for the person's own input, but only by luck -- they failed for other peoples'. The only possibly general solutions I've seen are the ones that set up external solvers -- either z3 or some integer programming package. (I wound up using the latter, and may have lucked out myself -- whether due to numerical instability or some fault in problem setup, I only got close enough to optimum to find it with a little local hill-climbing.) I'm not sure that's what Eric had in mind; everything else can be solved in Python or Ruby with no recourse to large external libraries.
For the most part, I had fun with this stuff -- even day 24, which I had to set aside for hours before a careful desk check found the reason why the answers I was getting weren't quite right. But rules that matter for some people, but not others, do take a bit of the shine off. There were more minor problems along the same lines with some of the other problems -- day 15 and day 24 had a lot of fiddly rules which didn't matter at all for some peoples' inputs.
There is an algorithm for finding a maximum clique in a graph, and some people on Reddit seem to have used it: the Born-Kerbosch algorithm [1]. Your graph has a connection between two nodes if their ranges overlap. It relies on the assumption that overlapping of manhattan regions is transitive; no-one on Reddit seemed to know whether that assumption is true, and I don't know either. :)
[1]: https://en.wikipedia.org/wiki/Bron%E2%80%93Kerbosch_algorith...
https://www.reddit.com/r/adventofcode/comments/a8s17l/2018_d...
That said -- one visualization posted elsewhere showed that that person's particular input was a bunch of singletons, plus one colossal clique that all intersected at a single point. That may have been structure that people were meant to discover -- but it's not clear that anyone did until after the fact. (The person with the visualization identified the clique as all the "bot ranges" intersecting with a solution point that they'd already found by other means.)
On one day I just did not know how to create a solution at all, so I stopped.
Also, I did not have much time, since work and my musicianship were too time consuming. Did not want to come home late in the evening just to lose my mind on more problems that need solving.
They might have been easier using an imperative language, but using Elixir had been a joy nonetheless, despite my occasional cravings for indexes and imperative for-loops.
But I will definitely come back to AoC to further practice Elixir and watch some of Jose Valim's streams. They always add some further insight into the language.
It made me go back to Hackerrank and try a few of those out.
Plus time is always hard to find.
I don't want to sound ungrateful though, I think the creator is doing an amazing service to software engineers/hobbyists everywhere and it's always fun to see solutions people come up with.
However this year I found the puzzles way too finicky, after about day 5-6. Was taking way too long to load the problem into my head.
Perhaps I had greater mental bandwidth in previous years, this year work + growing kids was top of mind.
I don’t mind problems that take a long time to think about, and/or take a long time to work through, trial and error, change approaches, etc.
What I do mind and what drove me away from AOC this year is that the problems seemed so detailed in ways that seemed arbitrary and ad-hoc, I didn’t have the motivation to spend the time required to load the problem into my head.
- I wanted to solve some problems using Prolog, but I struggled and reverted back to C# for all of them.
- I used LINQ a lot, including the query syntax which I rarely used before.
- I never made it to the leaderboard. I always ranked between 500 and 1000.
- I'm constantly surprised by how consistently fast top rankers are.
- I'm constantly surprised by how fast time goes by when solving these problems.
- I stopped participating at day 14, or when problems started to take me over an hour to solve.
There are some aspects where things are easier if your language has good support for features which AoC leans on. Notably, almost every problem requires parsing an input text file, so good regex support is really useful. I found myself wishing for a serde regex backend so I could initialize into structs from a regex match without a lot of tedious Point { x: cap[1].parse().unwrap(), y: cap[2].parse().unwrap(), ... } boilerplate. And since a lot of problems use 2D grids of ascii characters, Rust's lack of native 2D arrays and insistence that strings are utf8 and thus not trivially indexable makes things a bit more awkward than they might have been in a different language. I definitely agree with you that a language with a wide ranging standard library helps a lot to make life easier, too.
It's going to be posted on my company's blog at 12pm EST on the 30th of December: https://formapi.io/blog
I also did one last year [1], but this time it will be more of a programming challenge instead of a "treasure hunt". Anyway, hope you enjoy it, and good luck!
Fantastic learning experience.
I was using it to get more familiar with Rust, and I feel a lot more comfortable with the language now. I doubt I did everything idiomatically, and especially not at the beginning, but I feel like I can solve problems now. I've been putting my code on github [1] as I go, if anyone wants to see how I did things.
One takeaway for me next year is that there are some common things that pop up on multiple days, and if I actually card about being competitive, I'd want to make generic solutions for them before the competition started. Things like working with 2D and 3D grids, pathfinding, and parsing input. But since I was learning a language, the repetition helped.
Another takeaway was that I should not check the problems immediately when they open, which is late for me. Probably about half the time I would tell myself I'd do some simple stuff, then go to bed and finish in the morning. But then I'd get into it, and stay up too late. I do look forward to not having such a messed up sleep schedule next month.
I'll definitely be looking forward to it next year. This was my first year, so I may go back and do some past years to fill the time until then.
I was using Python which for me turned out to be the optimal programming language for problems like AoC. My reading of other solution on reddit confirms this. You often have to use maps (dictionaries) or lists and Python can be very concise in working with these. Also learned about convenience modules such as "collections" and defaultdict. Some people were able to produce concise and quite readable solutions with Numpy which I want to explore further in the future.
Overall I was impressed to see that some people were able to produce short but still very readable Python programs as solutions to the problems.
I gave up on day 8 when I didn't have the motivation to cut out the time between (or before) life, work and family to solve more and more complicated puzzles that became more and more arbitrary and didn't show any intrinsic motivation. (Although I did follow on some and found the CPU instruction set puzzle quite interesting).
I know a number of people thought some of the "simulation with lots of details to keep track of" problems were a bit over the top this year. Personally, I rather enjoyed them, and in particular found day 15 really satisfying to complete. Not something you'd want to do every day, but it's good to have some problems which pose a bit of a challenge without turning into a "can you pattern-match this against an algorithms textbook" exercise. The overall breadth and balance of problem types was impressive as ever.
I hope it's back next year!
I used to Scheme a lot, and this was a significant part of how Python ended up beating it for regular work. This year I tackled AoC in my own pet new Scheme descendant which tries to fix this problem: https://github.com/darius/squeam -- I'll check in my solutions later today.
Incidentally one thing I learned on Day 1 was that Chez Scheme's built-in hash function is not very good. Chez is generally awesome, so maybe it does work well in the context of Chez's built-in hashtable type, or something -- I didn't check. (My Squeam interpreter runs on top of Chez.)
Day 23 part 2 I had no idea how to solve correctly and in the end just wrote something that tries a bunch of spread out points, refining around the most promising point. Turned out to give the right answer but could have gotten stuck in a local optimum.
I did most of the problems the next day as I didn't want to wait up for the problems to be posted. I did get a few leaderboard positions on days where I did stay up.
All in all I enjoyed it, learned a few new things (how A* actually works) and improved my fluency in JavaScript.
As a mainly Python dev, I tried solving them in Golang during work breaks or afternoons with what little mental energy I had left :P to upload them on Github.
I learned so much more about Go, as some puzzles allowed me to use some nifty language features, and really liked the puzzles that featured recursion! In the end of the day, visiting the subreddit, there were tons of ingenious answers, people willing to help, or discuss the problem on a more theoretical basis. I still missed some of Python's minimalistic style, though.
Thanks Eric Wastl for this Christmas Gift!
Given a set of n strings, each of length m, find if there is a pair that differs in exactly one position.
It was not trivial to come up with an optimal and elementary O(nm) time algorithm. (by elementary, I mean something does not need a few hours to implement).
I've seen people getting running times of the form O(n^2m), O(n(n+m)) and O(nm^2) on multiple Reddit posts, and was surprised at all kind of different approaches.
Compute the hashes of the nm strings formed by taking each of the n strings and zeroing out one of the m characters. If you get any hash collisions, compare the strings.
for each string (n)
for each char (n∙m)
zero out char, compute hash (n∙m²)An example of such a hash is a polynomial hash (sum c_i * p^i modulo M, with p and M prime) such as the one used to explain https://en.m.wikipedia.org/wiki/Rabin–Karp_algorithm
The bad : - Some problem took a lot of time because of sentences I found unclear. - Some problems had very long specs (goblin vs elfes).
I will probably do it again next year (hoping that rough corners get smoothed).
I’m not caught up yet. Finished day 17 earlier today.
I’ve been using the advent to learn Rust. I’m pretty happy with my progress so far. A few things were more difficult than had I used C++. But for the most part it’s gone swimmingly.
I love the advent of code subreddit. Every time I solve a puzzle I check how other people did it in Rust. I learned several new things this way.
The hardest puzzles were definitely the fiddliest ones, day 15 in particular.
I wish there was a way for non US people to get a leaderboard in different timezones, appreciate it's hard (impossible) to do fairly.
This is my first time trying and I'm enjoying it a lot.
I did the first few then life and work got in the way and I am finally catching up to it.
I also find that Python is an excellent choice for such ad hoc data explorations
Done.