I've (somewhat) participated the last few years, more as a way to learn new languages, I've never actually made it through all the puzzles yet. I got fairly close with Rust last year, before getting burned out by the end. I'm currently debating either doing it with Nim or Ruby, of which I've never written a single line of in my life, but I'm curious to try out.
I also learned Nim in 2018 with AoC. I found one of the best things was coming up with my own solution, then looking at other people's solutions (the Nim community usually does Advent of Nim where a bunch of people post their solution repos on the nim forum) for more idiomatic approaches or stdlib functions I didn't know about.
I have discovered Nim on this (HN) site in 2018 [0] and shortly after I wrote my first lines of code thanks to advent of code (it was also my first year discovering advent of code).
I have become so affectionate of both (Nim and Advent of Code), that I always look forward to this moment of the year!
Last year I used it to test my notebook library nimib [1] (and it was first, and currently only, year that I completed the calendar). This year a nice challenge could be to try and use a different library from Nim ecosystem each day (always wanted to use Nico for this, Manim looks it could give nice results, …).
Best advent of code I’ve done was the ”int-code computer” one. So good - one recurring theme of making a computer and in the end running games on it!
Super excited for this year’s edition :)
One of my favorite things about the intcode computer was implementing the extendable memory by just appending an infinite list of zeros using haskell's lazy evaluation.
Unfortunately my implementation was incredibly slow (probably because of the linked lists) and I only made it about halfway through.
I also did that year in haskell! My favorite part was using knot tying to feed the output of my intcode machine into itself! Lazy evaluation allowed me to continue expressing my intcode machine as a pure function of [Int] -> [Int] without having to restructure the entire machine to allow getting an output, then adding the next input to the machine in a step-wise manner usually accomplished with generators of some sort in other languages
Was this 2019? I did half of it in elm. Simulating a processor with the core states of read, eval, and write was very cool. Using setTimeout to send it clock signals was very slow until I realized I could compose the processor step function to run a few thousand clock cycles per timeout. Wild time.
That was my first and my favorite so far. I did it in Haskell, barely knowing Haskell, which made things a bit interesting. I ended up learning/using STArray for the memory.
Having never written anything close to a parser or a compiler, I totally crashed on that one. I often misunderstood subtleties in the problem formulation and had to read solutions in order to figure out the question and ended up with such a mess of if-else statements for compiling int-codes that it just became impossible to extend my program.
On the AoC website you need to provide solutions for each day in a given year to see the next day’s problem, so you can’t instantly see all the problems from a given year unless you’ve previously completed them.
You may be able to find the problems elsewhere on the net.
All problems are available as long as their day has come even while the event is running. But the part 2 of each problem requires solving part 1 first.
You can definitely get some incredibly elegant and fast solutions using Rust. Check out timvisee's AoC 2020 [0]. It honestly had a significant impact on my personal style.
To be clear, I don’t compete for the leaderboard or code golf. But I do try to write elegant code that’s performant.
AoC is a great way to learn a new language. I try to solve the puzzles entirely on my own. Then I check the Reddit solutions thread and Ctrl-F my language. It’s a great way to learn new tricks, libraries, or just idiomatic language style.
And using Rust for AoC turned me into a certified fan. Rust iterators are really great compared to C++. They’re like C# linq but better. The itertools crate is super helpful.
I was going to do something fun, but gimmicky and try to implement them all in like SPL/2100 on an emulator running RTE, but quickly found I'd end up spending the month learning the latter.
I've been trying to think I've something, else fun to do or maybe use a language I've been itching to try, like Ada, but based on the first question it seems it'd just be boring to so in a language like that. I can think of a ton of other gimmicky solutions, but none that are very fun.
Would people reccomend this as a way to cement an understanding of Python / OOP in general? I’m typically more geared towards data science style scripting use cases and want to explore more problem focused programming.
Doubtful unless you do it in a way that facilitates that understanding. it could be like a year or two ago where you build up a computer from the ground up and do things with it where it would be more oop but a lot of the times they are self contained and don't require that much structure.
if you do it deliberately it's a good way to learn a new language.
I'd say AoC is more about problem solving and less about Python. The puzzles tend to be pretty good and I usually learn something from them. You could have a look at the previous edition to see if AoC is something you'd enjoy [0]. What I found informative was looking up other people's solutions on reddit and GitHub.
There is also Rosalind for more data oriented challenges [1].
I just started rosalind after someone posted it on here last week. They're definitely focused on bioinformatics similar to euler being more math focused.
I haven't gotten too far, but the initial problems don't seem too hard in higher level languages. They are very good problems to get better at IO, string manipulation, and data wrangling in your language of choice though.
> I just started rosalind after someone posted it on here last week.
Same.
> I haven't gotten too far, but the initial problems don't seem too hard in higher level languages.
True. But the info boxes in the top are interesting and informative, those make it worth it to keep going.
> They are very good problems to get better at IO, string manipulation, and data wrangling in your language of choice though.
For me, it's also a way to peek into BioJulia and get some familiarity with it. (I don't mind "cheating" this way since this was my primary goal with the site anyway.) So far I'm pretty impressed by how fast it is!
I usually use AoC with some specific goals or limitation in mind to teach myself. The problems will not require OOP, but if you force yourself to solve each problem using OOP...
Last year I did typescript and tried to really focus in on the type system.
I highly recommend it to explore new programming styles in general. As some others, I use it as an excuse to learn a new language each year.
While I think python is a really great language for advent of code, I'm not sure I'd recommend going for an OOP-heavy style. Although that might just be a matter of personal taste - I think OOP is a poor strategy for most problems.
Yup. Very much a chance to learn a new (for me) language. Looking to do Golang this year - brushing up on the basics of the language as we roll into a long turkey weekend.
I'm something of an elixir zealot, but I have to say that Clojure has the most pleasurable syntax for this kind of thing out of any programming language.
I actually have played around with it! I think Clojure feels a lot more polished, but it's also a lot more rigid, which I could definitely see someone disliking. LFE almost feels a little more like Common Lisp, although that's more to do with Erlang and the BEAM than any specific syntax choice. Plus, of course, you get to work with all that OTP goodness. If had to choose between LFE and Clojure as the only language I ever programmed in again, it would be a really hard tossup. Clojure might have a relatively larger community, but I don't want to give up the BEAM!
The reason LFE didn't do it for me was that Elixir is relatively painless syntax-wise, and has really nice high-level libraries like Phoenix and Ecto that simplify a lot of work. If I don't need the BEAM, than I'd rather have a more strictly functional language like Clojure, or something more low-level like Common Lisp. LFE doesn't occupy a niche in my personal ecosystem. That being said, I'd definitely give it another try sometime, and I'd recommend it to anyone else who wants to feel the power of the BEAM.
Clojure is the most practically expressive language I've ever had the pleasure of working with. For some reason the example that immediately comes to mind is how you can use a collection as an accesser for itself, so ({:a 2 :b 3} :a) returns 2. Just a neat bit of syntactic sugar, but now if 'blacklist' is a set, you can just do (remove blacklist guests) to remove everything in blacklist from guests. There's a hundred little things like that which combine to make it a really fun and concise language to work with.
Babashka is fast-starting but slow-running (compared to JVM Clojure). AOC puzzles typically contain a lot of loops so you will likely run into the slow-running-ness. But it shouldn't be much trouble to move to Clojure when you hit this.
Clojure is fun to try out. I tried it last year and had a lot of fun combining and finding the right function from its huge expressive vocabulary. It inspires you to treat code as data.
I've had a couple of Clojure books I've meant to work through over the past year. Where I'd get stuck is in the development workflow more so than in the language features or syntax. Clojure (and lisp-like languages in general) seem like my usual edit, save, run loop isn't the most effective way (especially if it's Clojure and the JVM needs to start each time if you run cold).
I like OOP approaches a fair bit, but only for relatively large, long-lived systems, especially when working with a team. E.g., the Domain-Driven Design approach can provide a ton of shared clarity.
For something like Advent of Code, though, I'd avoid it. It's just me and it's not for long; there's no need for me to be explicit about how I'm thinking about the problem.
Python, sure, but not OOP. Most solutions will not be very large and there's really no need for OOP (ever) but particularly not for something like this.
Don't hate on poor old OOP :( It's a good way to take that step from scripting to software engineering. Sure it can get out of hand with AbstractSingletonProxyFactoryBean's but so can other paradigms.
I mean...it forces you to plan and organize your code, if that's what you mean. But I also think it encourages you to do it in a way such that the organization becomes more important (and oftentimes, more complicated) than the problem you're solving, and I'd contend that's kind of a bad way to take that step, especially for people not otherwise experienced enough to know how to avoid that complexity.
The problems are designed to be solved in Python with less than 100 lines of code, by taking advantage of Python's extensive library of data structures and algorithms.
quite strongly disagree with this. You can solve the problems with fewer than 100 lines of code, but you can certainly also take it as an opportunity to flesh your programs out in OOP style. In general, programming is about what you want to do and learn, and the problems aren't designed for any specific paradigm. A lot of people have taken Advent of Code as an opportunity to not lean on any external libraries for example.
There's numerous problems from board or combat game simulations, to mazes and the intcode computers that lend themselves to be approached in OOP style. The context OP is coming from is data science scripting, it's fine to start with small examples.
I did AoC2020 with C++ and did it in a enterprise, over-the-top, well-structured way. E.g. need to find two items whose prices sum up to 123? Implement a multidimensional knapsack just in case you need it later (spoiler: I did need it). If you take the time, and don't bother with the leaderboard, you might find AoC to be a really fun and engaging way to explore new concepts and solutions.
Yes, this is the way I do it as well. There were quite a few cases where I went all in with an apparently overengineered solution, and then I could use the code directly for the second problem with almost no changes.
I don't go for being the fastest or anything, I just want to do everything in a way that I like. Last year I did everything on the same day it got out; I plan to do the same this one, unless there is a particularly bullshitty problem that puts me off.
Contrary to other responses, you can certainly use OOP programming to solve these problems, and I think that is a better way to do it. You wouldn't write 100 line blocks of dense algorithms in prod code, why do it here? Thinking about breaking things into objects makes a lot of the problems easier to solve in my opinion.
That said, I don't think it's great for really getting in depth understanding of any language in particular - you'll only use a limited subset of language features for these problems.
A couple of years ago I decided to learn Kotlin by doing AoC puzzles. It was a really good way to get comfortable with the basic syntax and data structures of the language.
OOP's toolset is useful for abstracting over interchangeable parts, which is the sort of thing that doesn't really come up a lot in Advent of Code problems. AoC is lots of fun, and Python is a great language to do it in, but I don't think it's a good place for OOP.
Perhaps, but it's something that's difficult to do _while_ learning the language. The most painful part is hiding all the memory allocation and management, but perhaps you could just declare a static allocator of the default type. You could just an arena allocator probably; AOC problems should not run out of memory, even if allocations are never released.
It was only so long ago somebody asked "[Whatever happened to Wolfram Alpha](https://news.ycombinator.com/item?id=29131931)". As somebody who didn't have Mathematica installed at the time, cheesing a problem with Wolfram Alpha was for sure one of the best applications I've had with it.
this year I guess I should probably have mathematica installed
If you just want access to the language and are fine with Jupyter as a front end you can just use https://www.wolfram.com/engine/ no need to buy anything then.
I'm torn between F# and Common Lisp (maybe even Raku for one or two puzzles). Julia is my fallback, as always. I think this year I want to solve all puzzles (got to 3/4 last year) and have all of them run in under one second, collectively. A tall order but interesting and fun!
I did Common Lisp last year. It was fun and often my solutions were extremely short in terms of LOC, because of how expressive Lisp is.
I got frustrated half way through because most of my time was spent fighting parsing bugs, since AOC tends to give you the data in very inconvenient formats.
I'm afraid I don't have a repo, sorry. I was working via several different machines and so I kept all the code on my brother's server but he lost the disk encryption keys, kind of a long story.
I just scanned through my 2020 solutions. It seems I used cl-ppcre for almost all my parsing if I couldn't read them directly with the built-in read or read-line functions. On the one occasion I used parseq in 2020 I didn't actually need it (a regex would've done the trick, day 2 password parsing). Parseq is a good option for anything more complex than regexes, though. I'd suggest taking a few days worth of puzzles and writing parsers to get some practice.
For the parsing I used a PEG parsing module (of GNU Guile). That made it really safe and precise, but also cost much more time than fumbling around with regex. I am more comfortable with my code being probably correct and for a work problem, I would rather use a grammar and parser than some elaborate regex mess in many cases. So I did the same in AoC. This meant however, that I fell behind. Once that happened, I did not continue for long. Coworkers also stopped a bit earlier. Lets see how far I can go with solving this year's puzzles. Hopefully I can share the joy of collecting stars with anyone I know.
Day 20 last year was definitely the most time-consuming and longest solution. If I remember correctly, the inputs for that day have a guarantee that's not mentioned in the instructions, so you can just write a naive brute-force-ish solution and get the answer in a reasonable running time.
No, because they have leaderboards. You have your choice of Google, Github, Twitter, or Reddit though. I don't believe Reddit even requires an e-mail address to create an account.
I've heard of AoC but never participated in it before
How hard would it be for someone to finish the entire thing? I'm planning to use this as an opportunity to learn Python. I have some programming experience in Java, C, and JS but not that much.
The first 3 days are "easy". The following 5-10 get harder, past the mid month, it takes serious commitment (unless you're a wiz of course!).
Overall it is absolutely worth attempting, you'll learn something guaranteed, about algorithms, about the language(s) you chose and about yourself (resilience and determination).
Check out a few problems from a previous year to get a feel for the difficulty. Generally, the puzzles get harder as the month progresses. Here's last year's calendar: https://adventofcode.com/2020
It is a great opportunity to do that. I would say do not expect to complete the year (most of us don’t). My bet is you will enjoy it anyway, even if you end up having a hard time (my personal suggestion is to keep trying on new days even when you did not complete previous ones)
It's very doable, but the problems tend to get longer later in December, so it's easy to fall behind late in the month. It's fun, it's certainly worth giving a shot.
You're really overselling the time commitment, in my opinion. Last year, only three days (13, 19, 20) took me more than a half hour. I suppose I probably fit criterion A, but the other two are nonsense.
That's really impressive, congrats! But, I'm not a bad programmer and up to around day 15 they regularly took me multiple hours. And around day 15 I started to find them hard as in couldn't do them. Do you remember what it's like to not be able to do a problem? There are lots of normal people reading HN -- surely you remember what they're like? Like, imagine someone who's learning to program, or one of those people who's really keen to do things in an obscure abstract way, but hasn't yet learned how to do things usimply. Have you met programmers from bootcamps who've only been taught a jumble of javascript, mostly framework stuff? I know there aren't many people like that where you work! But they do exist and they are here with us reading HN.
It often takes me 15 or 20 minutes to read and understand the problem description. But it sounds like you frequently had solutions written within that time!
I'm more with you, I guess. I find the increasing difficulty to push my brain more and more to its limits. So I usually just do the first few days in my language of choice for that year and there I go. No need to stress.
That was a very kind way of putting me in my place, and I sincerely appreciate it. I don't have a big competitive coding background or anything like that (AoC is really the only competition I've tried) but I suppose it's undeniable that I have a stronger background in coding in general than many, and it's totally reasonable that without that background, a larger time commitment would be necessary. Fair point!
I don't actually, although that's a good guess--I think a lot of the really fast solvers use Python. Makes sense--not a lot of typing, big stdlib to lean on. I use JS though, because it happens to be the language I'm most comfortable in. (Which is probably the most important thing if speed is a goal!)
NB. there's an Advent of Code subreddit and every day has a 'solutions' thread where people post their code in all kinds of languages, and discussions of different approaches, which is interesting to browse.
I've done AoC in Go every year, with a few good leaderboard placings, but this year I'm trying something new: a custom competitive programming language, optimized for solving AoC problems as quickly as possible. Will it be powerful enough to solve all of the problems? Certainly not. But hopefully, on the problems it can solve, it will enable me to solve them much faster than Go would. :)
I'll be doing the opposite, trying to do it in Go for the first time - it's a language I've been wanting to learn. Probably a bad decision to do the challenges with the overhead of learning Go at the same time, but it'll still be fun :)
It's at least good to hear that Go is a competetive option!
Yes! However, I'll say this: If you're using a new language that you're trying to learn, don't also try to do it for time. That is to say, take your time, it doesn't matter if it takes you a few days to do a single problem. Do try and read other people's solutions in OCaml after you've solved it yourself, or even before, if you're really stuck.
Absolutely. But I suggest learning it a couple of days beforehand just to know the tooling and the language enough to get started. A cold start with AoC is quite hard.
Sure, but start right now solving a few problems from previous years.
You'll want to know how to open and read a file, parse input (generally line by line, splitting each line on spaces), get familiar with data structures such as the dictionary/hash map and how to use the OCaml version. Not that you'll be competing for the leaderboard; this is more about getting familiar with the typical things for solving each problem.
203 comments
[ 4.0 ms ] story [ 270 ms ] threadLove it and excited for 2021
I've (somewhat) participated the last few years, more as a way to learn new languages, I've never actually made it through all the puzzles yet. I got fairly close with Rust last year, before getting burned out by the end. I'm currently debating either doing it with Nim or Ruby, of which I've never written a single line of in my life, but I'm curious to try out.
Last year I'd asked for some getting started advice here: https://www.reddit.com/r/nim/comments/k22h74/advent_of_nim_2...
I have become so affectionate of both (Nim and Advent of Code), that I always look forward to this moment of the year!
Last year I used it to test my notebook library nimib [1] (and it was first, and currently only, year that I completed the calendar). This year a nice challenge could be to try and use a different library from Nim ecosystem each day (always wanted to use Nico for this, Manim looks it could give nice results, …).
[0]: https://news.ycombinator.com/item?id=18045259
[1]: https://pietroppeter.github.io/adventofnim/2020/day11.html
Unfortunately my implementation was incredibly slow (probably because of the linked lists) and I only made it about halfway through.
I think it started in 2015.
On the AoC website you need to provide solutions for each day in a given year to see the next day’s problem, so you can’t instantly see all the problems from a given year unless you’ve previously completed them.
You may be able to find the problems elsewhere on the net.
https://adventofcode.com/2019
Not everyday is about intcodes, but day 2, 5 and 7 are the first 3 days with intcodes and they built on top of eachother.
A couple of years ago I used Advent of Code to learn Rust. This year I’m going to use it to learn Zig.
[0]: https://github.com/timvisee/advent-of-code-2020
https://www.forrestthewoods.com/blog/learning-rust-via-adven... https://www.forrestthewoods.com/blog/solving-advent-of-code-...
To be clear, I don’t compete for the leaderboard or code golf. But I do try to write elegant code that’s performant.
AoC is a great way to learn a new language. I try to solve the puzzles entirely on my own. Then I check the Reddit solutions thread and Ctrl-F my language. It’s a great way to learn new tricks, libraries, or just idiomatic language style.
And using Rust for AoC turned me into a certified fan. Rust iterators are really great compared to C++. They’re like C# linq but better. The itertools crate is super helpful.
Not sure if doing again, but could be useful resource
He got onto the leaderboard for fastest solutions with APL, too.
Implementing Intcode in Nim for 2019 was really pretty fun
I've been trying to think I've something, else fun to do or maybe use a language I've been itching to try, like Ada, but based on the first question it seems it'd just be boring to so in a language like that. I can think of a ton of other gimmicky solutions, but none that are very fun.
if you do it deliberately it's a good way to learn a new language.
There is also Rosalind for more data oriented challenges [1].
0. https://adventofcode.com/2020
1. http://rosalind.info/problems/locations/
I haven't gotten too far, but the initial problems don't seem too hard in higher level languages. They are very good problems to get better at IO, string manipulation, and data wrangling in your language of choice though.
Same.
> I haven't gotten too far, but the initial problems don't seem too hard in higher level languages.
True. But the info boxes in the top are interesting and informative, those make it worth it to keep going.
> They are very good problems to get better at IO, string manipulation, and data wrangling in your language of choice though.
For me, it's also a way to peek into BioJulia and get some familiarity with it. (I don't mind "cheating" this way since this was my primary goal with the site anyway.) So far I'm pretty impressed by how fast it is!
Last year I did typescript and tried to really focus in on the type system.
While I think python is a really great language for advent of code, I'm not sure I'd recommend going for an OOP-heavy style. Although that might just be a matter of personal taste - I think OOP is a poor strategy for most problems.
https://lfe.io/
The reason LFE didn't do it for me was that Elixir is relatively painless syntax-wise, and has really nice high-level libraries like Phoenix and Ecto that simplify a lot of work. If I don't need the BEAM, than I'd rather have a more strictly functional language like Clojure, or something more low-level like Common Lisp. LFE doesn't occupy a niche in my personal ecosystem. That being said, I'd definitely give it another try sometime, and I'd recommend it to anyone else who wants to feel the power of the BEAM.
I first heard of people doing this for codejam, and it works just as well for AoC
My 2c from the experience,
* I hated Go for this style of programming, but I could see it being good for some production-ready code
* Rust should be renamed to Rustcargo. Even for the most basic of tasks it seems like these two are welded together.
* I still really like Nim as a replacement for Python in my toolbox
I much prefer RustCargo to C++BringYourOwnShittyBuildSystem! Cargo definitely one of the bright spots in Rust imho.
For something like Advent of Code, though, I'd avoid it. It's just me and it's not for long; there's no need for me to be explicit about how I'm thinking about the problem.
The problems are designed to be solved in Python with less than 100 lines of code, by taking advantage of Python's extensive library of data structures and algorithms.
There's numerous problems from board or combat game simulations, to mazes and the intcode computers that lend themselves to be approached in OOP style. The context OP is coming from is data science scripting, it's fine to start with small examples.
I don't go for being the fastest or anything, I just want to do everything in a way that I like. Last year I did everything on the same day it got out; I plan to do the same this one, unless there is a particularly bullshitty problem that puts me off.
That said, I don't think it's great for really getting in depth understanding of any language in particular - you'll only use a limited subset of language features for these problems.
Make an API client, a GUI or game if you want to use OO in Python canonically.
I look forward to it!
this year I guess I should probably have mathematica installed
I got frustrated half way through because most of my time was spent fighting parsing bugs, since AOC tends to give you the data in very inconvenient formats.
Do you have a repo somewhere with the lisp code?
https://github.com/mrossini-ethz/parseq/
It makes working with the F# REPl very nice. I also had a good experience with F# type providers on consuming external input like AoC's.
How hard would it be for someone to finish the entire thing? I'm planning to use this as an opportunity to learn Python. I have some programming experience in Java, C, and JS but not that much.
Overall it is absolutely worth attempting, you'll learn something guaranteed, about algorithms, about the language(s) you chose and about yourself (resilience and determination).
It often takes me 15 or 20 minutes to read and understand the problem description. But it sounds like you frequently had solutions written within that time!
e.g. 2020 Day 1:
https://old.reddit.com/r/adventofcode/comments/k4e4lm/2020_d...
It's at least good to hear that Go is a competetive option!
https://github.com/KxSystems/kdb/blob/master/ad.k
You'll want to know how to open and read a file, parse input (generally line by line, splitting each line on spaces), get familiar with data structures such as the dictionary/hash map and how to use the OCaml version. Not that you'll be competing for the leaderboard; this is more about getting familiar with the typical things for solving each problem.