Hacker News new | past | comments | ask | show | jobs | submit login
Advent of Code 2021 (adventofcode.com)
745 points by amenghra on Nov 21, 2021 | hide | past | favorite | 197 comments



I love Advent of Code. If you like programming, Advent of Code probably has something for you. It's a great source of practice problems for learning a new language or style. There's a "competitive" aspect for people who like programming competitions, and you can even make private leaderboards so you can compete against your friends even if you can't make it on to the global leaderboard.

Last year I was earnestly trying to compete on the global leaderboard, and scored points a few times, ending up 103rd overall (slightly frustrating as the displayed leaderboard only goes down to 100th place!), but it's too stressful for me to want to do that again, and in my timezone it requires getting awake in time for the puzzles to be released at 5am.

This year I've been building a homebrew 16-bit CPU from 74xx logic, and have written an operating system and development environment for it, and I plan to do as much as possible of Advent of Code 2021 on my homemade computer.

There are 2 big hurdles to this. The first is that my computer is very slow. It takes over a minute to compile a typical program, which makes for a very long edit-compile-test cycle, and I don't have any hardware multiplication etc., so even integer arithmetic can be quite expensive.

The other hurdle is that it only has 64K words of memory, and IIRC some Advent of Code problems in the past have required keeping track of state for dozens of thousands of separate things. In those cases I'd either fail, or come up with a way to use the disk for extra storage. I look forward to trying, regardless.

As it happens, just this morning I did kind of a "dry run" on problem 1 from 2016 on my homemade computer, and recorded my attempt, which you can watch if you want: https://www.youtube.com/watch?v=UOizI9qi6FU


You could maybe try implementing bank switching to handle more memory. This does make code more complex but it should be possible to use boilerplate to access arbitrary memory. IIRC from when I toyed with making CPUs, a bank switch is implementable as a single extra register which simply drives the upper 16bit (or less) of your address line. It will probably be fairly slow.


Yes, that would be a good way to go. In practice I think bank-switching would be of great value even if none of the programs use it directly: currently context-switching is implemented by dumping the running process to disk and loading the new process from disk. If I had bank-switching then I could context switch much more rapidly by just giving each process its own bank(s) of memory.

It's slightly more complicated than just having 1 register to drive the upper bits of the address, because if you just blindly switch on some of the upper bits of the address then suddenly all of your instructions go missing and the CPU starts executing whatever arbitrary bytes happen to be in memory. So you'd want some way to switch out just the parts you want to store data in, while leaving all your code still mapped in.

I have an RC2014 with the bank-switching memory expansion. The RC2014 handles it by splitting memory into 4 (I think?) "pages" of 16K each, and allowing you to select which bank backs each page separately.


I believe the Apollo Guidance Computer used a hardwired lower segment that always points to Bank 0 and one for Bank 1. Then a few freely changeable segments.

I also recall some systems where it works just as described, but you had to be incredibly careful about bank switching and IIRC there was a dedicated instruction to write the bank register and program counter register at the same clock cycle.


Building a Forth could tighter your edit-test cycle.


I am fascinated by Forth, but every time I've tried to learn it I haven't really "got it". It's always felt very unwieldy to me.

But implementing Forth on my CPU, and getting proficient at using it, is definitely something I'd like to do at some point!


> I am fascinated by Forth, but every time I've tried to learn it I haven't really "got it".

Try reading Jonesforth, a literate Forth implementation in one x86 assembly file and one Forth file. You can read it top to bottom and it will explain how everything works step-by-step.

https://rwmj.wordpress.com/2010/08/07/jonesforth-git-reposit...

Github mirror: https://github.com/nornagon/jonesforth


I don't know if I'm not creative enough but what I've read about Forth tells you about the stack, about how to make new words, push arguments and pop to print. But that's it, and I can't figure out how to get things done with those building blocks. There's the famous washing machine example but there's not much else about doing things with it.

It's something that many programming language tutorials miss: exploring the possibility space and teaching you the language's expressive power


Starting Forth: https://www.forth.com/starting-forth/

Thinking Forth: http://thinking-forth.sourceforge.net/

In combination, very effective introduction to programming in Forth including how to go about combining those building blocks.


Do you have more info on your processor build? Sounds fascinating! I hoped that there might be a video on your channel, but it didn't appear so.


I don't have a great single resource unfortunately. I'd like to put up a web page about it at some point.

This is the github repo that contains everything: https://github.com/jes/scamp-cpu/ - some of the stuff under "doc/" might be what you're after (but some of it is just incoherent ramblings).

I have some blog posts here: https://incoherency.co.uk/blog/tags/cpu.html

And there is a video here, but it's not really very informative: https://www.youtube.com/watch?v=4sBB0iD6XvI


This is seriously cool. Nice one.


Unrelated but your automated chess board[1] is wonderful. Good work!

[1] https://www.youtube.com/watch?v=8ScFtkWvHW8


From the FAQ:

>I have a puzzle idea! Can I send it to you?

>Please don't. Because of legal issues like copyright and attribution, I don't accept puzzle ideas, and I won't even read your email if it looks like one just in case I use parts of it by accident.

It's sad that we live in a world where code snippets sent by others can result in legal issues down the line.


I suspect the Eric Wastl (AoC developer) wants this project to remain solely his and this is mostly a polite way to wave away all contributions in one go. I believe he has said he has way more problem ideas than time to implement them as-is, so I think that's a very fair position to take.


I had no clue AoC is a one-man-band project. With that in mind, how diversified are these puzzles? Wouldn't it be repetitive for people doing it year over year or is Eric one excessively creative individual?


Let's create an Advent of Community with crowd source puzzle under FOSS license


There's a Reddit that has a coding problem every day.


Which one?


https://www.reddit.com/r/dailyprogrammer/ - that's the one I know of. Sadly it's become defunct, but has a large number of problems going back over the years. I used to enjoy it as a kind of warmup at the start of my day.


A bit specialized but I like codegolf on stackexchange. Sure, the problem itself isn't the focus here, the implementation is, but it still does it for puzzling for me. I have finished all the regex crosswords I could find on the net...


This is a neat idea. If you're serious, I'd be willing to provide my email and chat through the idea and help out.


Why not. I am not sure if I would have both the level and the time though.


This is the same reason production companies burn all unrequested scripts sent to them.

If they open it and accidentally make a movie/tv-show that's too similar, they're liable to get sued. But if they can prove that all unsolicited mail is disposed without opening, they're golden.


The best thing about Advent of Code is how you can adjust it to anyone's skills and interests - you can do it for time, you can take ages, you can use any language you want or multiple languages, you can get help from other people online, you can go down various CS rabbit holes, you can make more elaborate solutions and/or extensions (some people were doing really cool visualisation of the game of life variations last year) etc.

It's very easy to recommend to it anyone who does any amount of programming at any level, from complete beginners to very experienced.

Other people in this thread are talking about learning new languages and I found that a bit distracting. I think I'd rather focus on the puzzles themselves and there's also something very satisfying about writing a clean and concise solution in a few lines which you can't always do when you're picking up a new language. I like using Python for it because I can just translate what I'm thinking to a solution without worrying about the language itself. Also, even if I didn't mind doing it in a new language, I don't think that AoC gives you large enough problems that can really explore a new language and all of its features. And you can always mix the languages if there's a language that's really suitable for a given problem. You don't have to stick to the same language for all problems.

I really enjoyed last year's, I'm looking forward to this one.


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.

e.g. 2020 Day 1:

https://old.reddit.com/r/adventofcode/comments/k4e4lm/2020_d...


What does NB mean?




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 :)


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.


But now you have written one, which might come in handy at some point in your career.


Well, I guess I know now how not to write one ;)


way to sum up my coding career :D


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


my fun thing was running my intcode computers in parallel


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.


I agree. That year was the only one in which I completed all of the puzzles the day they came out.


That sounds amazing, is there any way to access this material right now?


You can see any year by changing the url: https://adventofcode.com/2021

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.


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.


Hah - I’ve assumed for years that days weren’t accessible because the section of ASCII art for them is greyed out!


you write the intcode computer in AoC 2019

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.



I love advent of code, but I always burn out on it after a couple of days because it just starts taking up too much time. I'm always amazed at the people here that complete the whole thing, I feel like there must be a vast gulf in skill level between me and the average hn poster. Excited to try the first couple of days again this year.


> there must be a vast gulf in skill level between me and the average hn poster

I suspect it's much more a time gulf than a skill gulf.

I love AoC as well and don't so much burn out but find that after a week of coding for fun in the evening a mountain of real world responsibilities start piling up, especially around the holiday season.

When I was in undergrad I had virtually no family responsibilities during December and a large amount of free time when classes ended, so it would have been easy to spend hours a day on AoC. Many younger, single professionals are likely in the same situation.

I think for most adults with family responsibilities and full time jobs (and likely a range of side projects that also need attention) that first week of December is a rare lull, and a great time to solve a bunch of fun code problems. After that more and more other things take focus as the holidays approach.


Exactly the same thing happens to me. Ain't nobody got time for that, after like day 9 or so.


For inspiration, here’s the full solution set for the 2015 edition in around 100 loc of k. Yes, all problems.

https://github.com/KxSystems/kdb/blob/master/ad.k


Ah K. It's like someone saw regexs and thought "I wish all programming was as readable as this!"


Very impressive, I understand the first two lines of the file.


In context, I don’t think I actually even understand the second line.


Tried this properly for the first time last year, and very much enjoyed doing each task 'properly' with literate programming, unit tests, benchmarks for different implementations etc. It was extremely soothing, much more so than if I'd just tried to solve each problem as quickly as possibly. I'm sure some others would get a lot out of this approach, whether or not you're trying a new language.


> unit tests

Don't you need a way to generate more inputs in addition to the one you have?


Every puzzle comes with example inputs and expected outputs. Those inputs are much smaller than the puzzle input, but if you get the example inputs and expected outputs right then you are probably most of the way there.

Basically every puzzle comes with unit tests that just need to be translated into code.


Yup, although I do enjoy finding edge cases that aren’t necessarily present in the examples or input. I intend to do a fair bit more property-based testing this year, just for kicks. That’s something I’ve had success with for raw algorithmic code but struggled with in the past for nitty-gritty real-world use cases.


Those would be functional tests


Same thing if your whole solution is a single function :)


Which is another name for unit tests.


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. :)


What's custom about Python? ;)


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!


Good luck! I recommend building up a library of helper functions; it will save you a lot of typing. Here's mine: https://github.com/lukechampine/advent/blob/master/utils/uti...


I'm doing the 2020 ones in go as practice, it's been easier to learn than I was expecting


Now that I finally learned what a modulo multiplicative inverse and how to compute one is it will probably be the year that it doesn’t come up.


I almost got an heart attack while seeing this post. Still dizzy from waking up early I thought it was already December.


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.


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.


You can go one further - last year I tried to solve every problem in a different language!

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


> Rust should be renamed to Rustcargo

I much prefer RustCargo to C++BringYourOwnShittyBuildSystem! Cargo definitely one of the bright spots in Rust imho.


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 torn between Clojure (totally n00b) or Elixir (mostly to force myself to use it rather than defaulting to Python)


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.


Being an elixir zealot have you ever considered lisp flavored erlang? If so, what are your thoughts in comparing it to clojure?

https://lfe.io/


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.


That's good to know. What is it about the AoC that makes it play into Clojure syntax so well?


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.


This year I'm going to try it with Babashka, the native Clojure scripting runtime. See how far it can take me.


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 can't possibly sing the praises of Cider loudly enough. Emacs is a hard sell, I get that, but Cider is such a nice way of working with Clojure.


I suppose Cider in Doom Emacs means I can keep using the vim keys I already know.


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.


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

0. https://adventofcode.com/2020

1. http://rosalind.info/problems/locations/


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!


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.


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.


You can apply OOP principles to even the simplest problems. Search for “fizzbuzz enterprise edition” to get some ideas.


I think most problems would be solved elegantly with a pseudo-functional approach in Python, so AoC wouldn't be the best for OOP.

Make an API client, a GUI or game if you want to use OO in Python canonically.


Maybe they could be, but that doesn't mean they have to be. My intcode computer was written using OOP.


AoC won't teach you anything about OOP.

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.


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.


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.


Advent of Code is generally to small to help with OOP practice. It will help get you familiar with Python though.


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.


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.


it can be a great way to learn a language and to explore other programming paradigms.


Good way to learn Rust, F#, Nim, Zig or Lisp! or anything but those are all worth a look


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.


Gonna be giving APL/J a shot this year.


Remember seeing someone did videos last year exploring APL solutions.

Not sure if doing again, but could be useful resource


Jay Foad has done Advent of Code solutions in APL for previous years: https://github.com/jayfoad/aoc2020apl

He got onto the leaderboard for fastest solutions with APL, too.


There are many sets of published solutions: see https://aplwiki.com/wiki/Advent_of_Code.


I will be doing it w/ Zig and Julia this year, i'm redoing some Rust, python, and scala solutions from previous years


I did 2019 in Nim, and I'll be doing 2021 in Rust. 2020 I tried to go for speed though, so I went with python.

Implementing Intcode in Nim for 2019 was really pretty fun


I did this last year and loved it, if you aren’t even considering it I would, it made me a better programmer and it allowed me to go from completing around 60% of in interview coding tests to maybe 90%+. I’m not scared of them like I used to be either. If people do this for fun it’s also probably worth hiring them…


It would be great if that was true but I would still feel kind cheesy putting it on my CV. That might just be my own biases speaking though.


That's why you put it on your GitHub.


How hard is it to go all the way? Last year 163763 people completed both puzzles for day 1. On day 25 only 13016 completed both puzzles resulting in a "completion ratio" of 13016 / 163763 = 7.95%.

       Day 1  Day 25 Ratio
  2020 163763 13016   7.95%
  2019 103187 3399    3.29%
  2018 71480  3192    4.47%
  2017 48543  5577   11.49%
  2016 19299  2772   14.36%
  2015 55970  4171    7.45%
Based on https://adventofcode.com/2020/stats, https://adventofcode.com/2019/stats, https://adventofcode.com/2018/stats, https://adventofcode.com/2017/stats, https://adventofcode.com/2016/stats and https://adventofcode.com/2015/stats.


In my experience the difficulty and time requirements ramp up considerably after about day 10. I think that plus the fact that its Christmas time makes it hard to complete the whole thing - I would even wager that some significant fraction of the people who completed day 25 didnt do it in December…


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


Why bother installing Mathematica? You get all the functionality for free in their cloud notebooks.


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.


In what way did you cheese the problem?


The first Advent of Code since the advent of Copilot. Should be interesting.


It's a trap... :) This site is the biggest nerd snipe https://xkcd.com/356/

Love it and excited for 2021


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!


If you do it in F#, try out VS notebooks: https://www.compositional-it.com/news-blog/a-brief-introduct...

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.


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.


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.


Yeah, I did the first week of 2020 with both Lisp and Julia and parsing was indeed an issue; but I'm a Lisp beginner anyway.

Do you have a repo somewhere with the lisp code?


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.

https://github.com/mrossini-ethz/parseq/


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 honestly can't wait for this to open. I ground out the full 300 stars recently going back through all the previous years and it was one of my favourite programming experiences. Eric Wastl's such a great problem setter.


I recorded about 40 hours of me solving these problems from scratch last year. That was not for everyone but some people really like seeing your thinking process, getting stuck, going down the wrong path, and recovering.

This year I'm going to be hosting a series of workshops to discuss solutions in Python.

Participants will come to the workshop having already implemented the problems we will be discussing. The goal will be learning about more intermediate and advanced features, testing, OO vs functional solutions, utilizing editors efficiently, getting feedback, data structures and runtime, and improving your coding ability.


Will this be virtual? If yes, I would be interested in participating


am interetested in this too..


Would OCaml be a good language to use here? It would be my first time in AoC, want to learn OCaml as well.


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.


Thanks for the advice!!


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.


Thanks for the advice


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.


Thanks for the advice, would start from today!!


as good as any :)


What exactly is it? I understand there is something about code puzzles but how does it work? How does the leaderboard work - presumably there is some sort of scoring involved?


Daily two part puzzles, for one star each, 50 stars total. Second part is usually related to the first (but unknown until you solve the first) which makes you refactor or learn to write your code generically the first time. Input is usually a small text file. Puzzles are often dependent on earlier ones (spoilers: most years you write a interpreter for a made up language over a few days and later puzzles use it as an input generator which you seed with the text file)

Leaderboard points are only assigned if you're in the top 100 for either parts which you should ignore if this is your first time since it's not the point!


You get points for being the fastest to submit the correct solution to a puzzle part each day. First one gets 100 points, second one 99, and so on down to place 100. So you could get up to 200 points per day if you solve both parts of the puzzle as first one. However unless you can be on your computer when the puzzles unlock (midnight EST (UTC-5)) I wouldn't bother with the global leaderboard, it gets filled within minutes.


So for the first time in years, we are leaving for the holidays (in-laws). I was going to use the time off (and the inevitable boredom) to get an AWS cert to help my job search. Now I don't know...

In the past, I've given up on AoC after a couple weeks due to time and conflicting priorities. With two whole weeks of free time that coincides with the hardest puzzles, I guess I know what I'm doing in December.


Time to learn Zig!


Tried to learn Zig by doing AOC earlier this year. Wow, that was painful. Python is a much better match for all the text manipulation.


That makes sense, but surely it must be possible to write a little string library in preparation for AOC, which would make Zig a better fit?


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's nearly upon us once again!

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 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, …).

[0]: https://news.ycombinator.com/item?id=18045259

[1]: https://pietroppeter.github.io/adventofnim/2020/day11.html


Also hoping to do it with Nim!

Last year I'd asked for some getting started advice here: https://www.reddit.com/r/nim/comments/k22h74/advent_of_nim_2...


I did AoC in Nim one year and was very happy with it! I also became infatuated with Nim that year..


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.


Solutions made with https://github.com/zevv/npeg were surreal, I felt like a caveman watching a TV.


Yes, I do distinctly remember having that same feeling when reading zevv's solutions!


I'm going to try Crystal[1] this year, now that it's had a 1.0 release. At least for the first 10 problems - after that, I'll likely switch to Julia unless Crystal proves to be even more enjoyable than I expect.

[1] https://crystal-lang.org/


I've still got my Lazarus/Free Pascal installation warmed up from Google Kickstart, so I'm ready.


Time to break out the ZX Spectrum Basic again!


Advent of Code is fun! I have done it every year since the start. I have previously used C++, Rust, Racket, F# and a smattering of Factor and SML.

I'm vacillating between doing it in C# and Javascript/Typescript this year. C# has gotten more attractive lately as there are improvement that makes it less ceremonious for short programs, like toplevel statements and global imports, and also fun optimizations for ricers. If I do it in JS/TS I would do it in a web environment, and try to do it with a nice web GUI.


You might like Scala 3 starting off quickly with: https://scala-cli.virtuslab.org/ too (maybe!).


José Valim is going to stream Advent of Code again this year https://twitter.com/josevalim/status/1461064540465078273

His 2018 AOC stream https://www.twitch.tv/collections/YDM6eKu6bhV1Nw


I should probably finish last year's. I did all parts mostly in time except for day 20, I couldn't figure out part 2 and just refused to do it.


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.


Oooh, so excited, last year I also wrote a little discord bot that can run on a raspberry pi zero written in plain JS. So shameless plug here: https://github.com/francisduvivier/aoc-discord-notifier-bot


I’ll probably end up doing it in C again.


How does this compare to "classical" competitive programming (like ICPC, Codeforces, etc)?


The scoring should adjust based on your chosen language of choice and mental demise ;)

I look forward to it!


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.


It's doable if you (a) are good at algorithmic programming challenges, (b) don't have a job, and (c) don't need to buy any christmas presents.


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!


Thanks, that's a nice response to get! Do you use python for doing these sorts of things quickly?


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!)


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)


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


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.


One of my favorite times of year!

A couple of years ago I used Advent of Code to learn Rust. This year I’m going to use it to learn Zig.


How was the experience for you? I've done the past few years in C#, but am considering using 2021 to learn Rust.


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.

[0]: https://github.com/timvisee/advent-of-code-2020


Thanks for linking! I plan to do something like this again this year :)


A++++ loved it. I wrote a pair of blog posts about it.

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.


I usually do it in Rust. I have a lot of fun with it, it's great practice.


Had fun doing it with /sci/ in 2019. Hoping to complete this and the first 100 problems in project Euler!


Have gone back to 2019 day 10, warming myself up for this year. Trying to get my colleagues to participate, too.


Looking forward again. The puzzles are good, but they are described so well they become a real joy to solve.


Someone repost this in 8 days so I remember


Really cool design and content.


Did they remove the requirement to link an external account yet?


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 hope that Peter Norvig participates this year again!


I likewise hope for Michael Fogleman's participation: https://github.com/fogleman?tab=repositories&q=advent




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: