149 comments

[ 3.0 ms ] story [ 85.1 ms ] thread
I did several of these last year and found them deeply unpleasant. I like puzzles but some puzzles are just...bad. Like the ones that require you to just brute force a solution, or write lots of detailed code to capture the requirements...that shouldn't be what this is. Just my opinion, of course, but like I said I found last year an unpleasant chore that felt more like work. Hope it's not like that this year.
I recently went through the 2021 puzzles and I don't recall having this experience.

I also think the choice of language matters a lot. I did it in prolog a few years ago and it was super concise because you just dealt with pure logic at that point.

I can see it be more verbose in Java :) but seriously I find these puzzles hard but not in a chore kind of way.

(comment deleted)
Are your Prolog solutions public? I would love to take a look!
There was one about piecing together data from multiple under-water sensors regarding the locations of mines or something. With the data being rotated in various orientations (in right angle increments) thus having to correlate the overlapping data items. I think it was 19. I wrote quite a log of code to brute force this:

https://www.kylheku.com/cgit/advent/tree/2021/19

Some people's solutions used some linear algebra libraries in ways I don't understand; one day I will revisit that.

Each year does vary slightly in theme and focus, so it's possible you'll have more fun this time if you give it another chance. Or not. But remember that it's never too late to give up. :)

My favorite so far is 2019, where several of the problems had you write and extend an emulator for the imaginary (and wacky) "IntCode" computer.

2019 was excellent. Each day, the puzzle would have you adding new features (new instructions, addressing modes, input/output handling) to the emulator. The early days were fairly simple, but things got progressively more complicated. On one day the puzzle input was code that played a game of Breakout. Your task was to implement an emulated joystick that would play perfectly. The solution was the final score. On another day the puzzle required several virtual machines running in parallel feeding the output of one into the input of the next to get the final answer.

Reddit r/adventofcode is also fun. People post not only solutions in various languages, but visualizations of solutions (e.g., an animation of that game of Breakout). Sometimes people post fun things, like a solution to a puzzle in Apple II BASIC and a video of it running on an actual Apple II.

One of the things I really loved about the IntCode problems was best exhibited by that Breakout game. One way of solving the problem was to create a joystick, as you said, but if you had built an IntCode inspector/debugger, you could also dig into the game code itself (your puzzle input) and find out where the blocks were in memory, and how much each one was worth, and just sum it up directly.

It reminded me of Wastl's other big puzzle collection (Synacore) which also had a big emphasis on implementing a VM to host further puzzles on top of.

I like that solution by code-diving. I had initially rigged up a joystick for it, but programmed it to to play itself to completion.
A different kind of programming puzzle: https://BUGFIX-66.com

The idea is that you read and understand a small piece of code (full of useful techniques) and make a small change to demonstrate understanding.

Games that require you to write the code are limited to rehashing the same old tired algorithms... reverse a string and other sequence techniques, edit distance and dp variants, optimization by binary search and evaluation, etc., the standard leetcode stuff. Basically, useless wankery you will never use. The competitive programming standards.

If you don't have to write it, just understand it, the game can cover some very interesting new algorithmic terrain. It becomes part book, part game. Like Hacker's Delight: The Game.

I like this idea! Sounds more relaxing like I could passively work on it while on the train, and also see code examples that I wouldn’t normally be exposed to in my day job.

Seems like it might help me get better at code reviews too. Granted, I don’t like doing code reviews (mostly cus it’s usually pretty uninteresting code). But I do like puzzles! I’ll check it out :)

I felt similar last year. I was trying to do them in Zig and Rust, and it felt like most of the challenge was just writing custom data parsers for poorly formatted data which felt too much like my day job.
Same feeling for me as well. At a certain point it just stopped being fun and felt like work.
Fwiw there’s a few recurring formats, the old hands have a bunch of helpers for that and other things. Sometimes there’s something completely bespoke but the most commons are space-separated lines of things, usually ints, commonly fixed-size.
> felt too much like my day job

Agree.

I think it helps to do it in a language you're not familiar with, or with some artificial limitation on how to solve it (no third party libraries for instance).

It takes more time, but felt less like a grind for me.

Last year I have used Python without using any imports and, whenever I felt like it, tried to golf it as much as I could. Turned out easier than I expected, even without any libraries Python is pretty powerful for this kind of tasks: https://gitlab.com/dos1/AoC21

There were only like two or three days that felt frustrating, but mostly because of the problem being poorly specified.

I'm using a language with easier data parsing this year and so far I'm having a much better time (I'm also more time poor and these exercises fit in pretty nicely to a bit of after dinner free time).
I love Advent of Code. I learnt Rust while solving last year's puzzles.
One of the best ways to test drive a new language. Love aoc for this.

In the 350 (for now) stars club.

I'm ready with my codex key.
Last year I went through 8 of them. I wonder what's the theme of this year. Hopefully it's somewhat closer to CPU design (because reading Soul of the new machine)
Not CPU design, but does involve a simple VM, have you checked out 2019? About half (1/3rd?) of the challenges involve a VM for "intcode". First few challenges get it up and running, then concurrency is added, and then challenges are presented inside it.
Thanks, I'll check it out. Definitely close to my definition of fun :D

I also cannot tolerate hard problems so probably will stop around the same number.

If you enjoy that, the same guy made Synacor Challenge: http://challenge.synacor.com

Similar basic problem as the intcode VM but less need to dive into concurrency.

Thanks! This is really cool~

One of my dreams is to consume small pieces of challenges of some topic, one sightly more involved than the previous, then viola! At the end I get to learn say 50% of a CS course.

Books are good but they don't force me to write code. I'm a bad learner :D

Really enjoyed that one. I do it in Excel, and moving things around between registers actually maps really well to a spreadsheet.
I did this for the first time last year. It was fun! Really excited to do in again.
Once more unto the breach, dear friends, once more
Elixir ended up being a great choice last year. I contemplated using ocaml, sbcl, or guile this go round but ultimately decided to see how far I can get with awk. I'm feeling confident I can get by with awk using getline as needed, we'll see how long I endure...

Best of luck to everyone!

Yes! I did two years in awk (https://github.com/tomberek/advent) and loved the ability to dig in and truly grok the language. The performance wasn’t bad, but the multidimensional array support and ergonomics were…meh. I’m contemplating Elixir.
(comment deleted)
Time for my yearly tradition of making it to day 4 in Haskell and feeling very smart before completely giving up on the first hard problem that needs regular arrays :)
Try Ocaml instead :)
Or F# for that .NET ecosystem goodness ;)
I tried that last year, and got worn down by how often I'd Google how to do something and get an answer explaining how recursion works from first principles as opposed to just pointing at the deciding standard library function that did what I needed.

I want to try again this year, do you have any advice for how to get going with Ocaml as someone who has programmed long enough to understand how recursion, linked lists, and all that jazz works, and just wants to figure out how to be productive in the language?

I'm not an OCaml expert either. I've used Haskell professionally a little bit and also know OCaml. I find OCaml more practical because you don't have to fight with "pure" functional programming when you really want an imperative algorithm. For example, OCaml provides mutable arrays even though it encourages functional style whenever possible.

One downside of OCaml is that its standard library is not very powerful and there are multiple third party replacements that are popular. Jane Street's base/core, Containers, Batteries Included, to name a few. So you have to make a choice.

Having said that, I think you can live with the built in standard library to solve most of the AOC problems.

I did OCaml the passed two years. GPL productivity in OCaml is easily accessible, but you need opam packages. Its not a deeply batteries-included language at all. With the exception of eio, my goto set of base packages are: https://github.com/cdaringe/protohacks/blob/main/dune-projec...

containers is my preferred “add batteries” std lib extension. Also, the ocaml discord chat and discuss forums are very active and welcome to questions

I’ll be joining you for “see how far I can Haskell (for great good)” this year!

Then I’ll probably fall back on Python. :)

Ditto, but MS Excel. Some problems are much easier, some are... pretty hairy.
Yeah... Day 1 woohoo C, Zig, etc.

Day 8... Screw it... Python onwards...

At that point, reach for regular arrays in Haskell :)
That's me but with F# :')
I know exactly what you mean. I'm going to try AoC this year again with Haskell, but this time around I'm just going to cheat and use it as an imperative language.

    {-# LANGUAGE BlockArguments #-}
    {-# LANGUAGE Strict #-}

    stateful s' f = runState f s'

    forEach xs state' f = foldM f state' xs

    solve input = forEach input initial_state $ \st current_value -> stateful st do
        ...
Have you been impish or admirable?
Advent is not an event that resonates with me.
AoC is one of my favorite events of the year! I find the puzzles generally approachable, but interesting enough to spend time on. I also like that there's a definitively right answer, which motivates me in an interesting way. I've developed a base class over the years that handles input parsing, so I can focus more on the solutions themselves.

Additionally I've been solving for a number of years, but for the past 2 years, I've done a daily explanation of the solution. I use interesting parts of the Python stdlib and walk readers through common algorithms. I've found it _incredibly_ rewarding and plan on doing it again this year.

You can see all of those solutions here: https://github.com/xavdid/advent-of-code/tree/main/solutions

Please let me know if you enjoy reading these, I love hearing from folks!

wow, your username somewhat resembles mine!
Ha, so it does. A small world. :)
I just skimmed through your repo, and I loved the way that you used AoC as an opportunity to share many of the batteries that are included in the Python stdlib. In one particular case, I wanted to also share some more fun corners of the collections module / common algorithms and sent you a pull request.
Thank you for reading! I never thought to accept contributions on here, but these look great. Thank you for sending it over!
Thanks for creating this and helping others learn! Amazing effort :)
You're very welcome! I hope you (and any other readers out there) have found them useful.
I'm excited to try again this year! Last year, I only got 7 days done before getting distracted because of how crazy December is.
Different style of challenge that launched this year (found it in another HN thread a few weeks ago): https://protohackers.com

You're asked to write server code that meets the given protocol definition.

I was just telling all my computer-adjacent friends about this. Hype hype hype!!
Last year I completed it in Python, but I'm pretty familiar with the language. This year I want to try in a new language - mostly either zig or rust. Eager to see how far I can get!
(comment deleted)
I wonder how helpful GPT-3 and Copilot will be for this :) Not necessarily to solve the whole puzzle but rather to give hints when I'm stuck with a particular task.
If Microsoft updates the model daily then you could easily get a copy of someone elses solution by the next day.
Last year when I was doing AoC in Go, I was pleasantly surprised how good Copilot is and it felt like magic. Given most of the time I use Terraform, YAML, JSON, jq, and Bash these days, I can't really appreciate Copilot, but last year I did!
I ended up turning off Copilot last year since it was literally giving me complete correct solutions with no effort on my part. Kind of took the fun out of it.
I can't say it gave me complete solutions, but it really guessed my intent most of the time and saved me typing time so that I could come close to the winners who predominantly use Python.
Last years I started around the 14th and Copilot auto completed the solutions for all the old problems from basically just the file name. I created a file called 'advent_of_code/1.py' typed 'def main()' and Copilot did everything else.
No, I'm not doing it. At least, I'm not doing it in real time! What a time waster - my family hated me! Sorry, offline holidays and online programming contest don't mix well! Enjoy your life, solve the problems after the holidays!
I wonder how the persons on the leader board manages it? First person today solved part1 after 39 seoncds, and was done with part2 after 53 seconds!

I felt I was quite fast in being done with part1 after 3 minutes and part2 in 4 minutes (rank ~1000). I even tried to skimread the explanation to be fast, have a script to download the input and run it etc., but still no match!

1. Have everything in place at the start (a script to grab the inputs helps).

2. Use a language that makes the edit/run cycle short.

3. Be very familiar with that language and how to process input in it.

4. Have solved many similar problems in the past so you can parse these problem statements quickly.

5. Have solved many similar problems in the past so you know exactly what code to write or use (if you have a utility library).

“Have solved many similar problems in the past so you can parse these problem statements quickly”

This sounds like an advent of code specific thing. The problem itself is trivial, no need to have solved anything similar in the past, but the description is so verbose (because it’s a cute Santa-related story) that it becomes hard to parse the problem we’re trying to solve, quickly.

I don’t think this is common in any other competitive programming environment.

(comment deleted)
Feel I have to disagree on this one. Firstly, most programming competitions I've been to have this kind of problem description as well, just check Kattis problems for instance.

But secondly, while the problems in the beginning are trivial, you still have a huge advantage if you can immediately start programming without having to think, or having to look up a function in the stdlib. (Spoilers:) I probably wasted a minute today thinking about the solution of making a list for elves, and creating a new element whenever I saw an empty line. While a pro probably immediately did a split on "\n\n", summed and was done.

(comment deleted)
ehm

I did s.split("\n\n").fold... But this was first thing in the morning and where I lost time was that what I actually did at first was: s.split("/n/n")

It helps if you sort of read the problem statement backwards
You only need to read the bolded white words to have a very educated guess (5 second skim; it's intentional)
Google FooBar uses this exact form as well, state the problem as a somewhat consistent story through the different challenges.
I have most of it in place, but I guess it's 4&5 I need to improve. I feel like my problem, when comparing to the video posted of today's winner, is that I'm "too safe". I should gamble a bit more, read only parts of it at the chance of misunderstanding, and go with my first thought of implementation even though it may not work. Because the moment I start to consider things the others are already done, heh.

And I guess I could do better on 2, but on this day I only needed 1 run. I use Kotlin, and guess I lose a second or two on it compiling before running. I see today's winner just did everything in browser console as a repl. So that's probably a good way to minimize the loop. Pretty annoying for the later problems, though.

Where can I find that video of the winner?
How do you grab the inputs? I get the following error:

     curl https://adventofcode.com/2022/day/1/input   
    Puzzle inputs differ by user.  Please log in to get your puzzle input.
There's a session token in your browser cookie for the site, you have to pass that to the server. Honestly, though, I'm not going to be in the top 100 so I don't bother anymore. I open the input and hit Cmd-s and save it to my inputs directory. I've made it into the top 100 precisely one time in the 4 years (this is my 5th) I've participated, and I honestly don't know why I was in the top that time. It wasn't a terribly hard problem (for the folks that were reliably making it in the top 100) if you'd done the earlier parts since it was a simple search (increment register 0 value, check that it's not in a cycle, and count the number of executed instruction if it halts). You did need to complete day 16 first though, and it was closer to Christmas itself so maybe that was why.

If you do use a download script make sure you check whether or not you've downloaded it before. He's also requested that you put in a user agent that provides some contact info (rather than being generic). The server has been getting slammed by people hitting it too often and he's considering banning some, and wants a way to reach out to people who may have a misbehaving script.

https://adventofcode.com/2018/day/21 - My one top 100 result

https://adventofcode.com/2018/day/16

https://www.reddit.com/r/adventofcode/comments/z9dhtd/please...

Do you want to be fast, or do you just want to have fun?

Who cares what others do with the game? Have fun while doing it

For the easier tasks, my "fun" is doing it as quickly as possible first ;) Then I rewrite it with a goal in mind, for instance entirely functional with no mutations, as a single expression or whatever.
Is there any way to play without logging in (for previous years, if necessary)?

I couldn't find anything on the About page that clarifies this.

Edit: I see anonymous users in the leaderboard, so it seems like it might be possible.

You have to have a login (Google, Github, Reddit, Twitter) to get inputs, and part 2 is only unlocked after completing (correctly) part 1 for any given day. You don't have to share your identity with anyone but the host of the server.
You have to log in, but you don’t have to reveal your identity or username on the leaderboard.
No, there is no way to submit answers without logging in. The "anonymous" feature is just a setting to hide your username from the leaderboards.
Other comments haven’t pointed this out, but the key thing is that each account gets a different input (so it's a little harder to cheat).
It's easy to cheat by applying someone else's code (ex: from reddit) to your own input.
Every time I do the AoC puzzles I wish for two things:

1) The site should ask for the language used to solve the problem and then use this as semi-scientific data for comparing "time-to-solution" for various languages. The sheer volume of data and the relatively high difficulty of cheating on novel problems would make this data set interesting and maybe even useful.

2) I wish all the puzzles had a "hardcore" mode where a naive approach would take a million years of compute, or exabytes of memory. Have multi-gigabyte inputs[1] such that the time-to-solution isn't just how fast you can bang out some simple parsers and loops, but the runtime performance would materially affect your time score.

[1] A method for this would be to use an input-file-generator that is small to download but can generate huge puzzle inputs.

Part2 is quite often what you wish for in 2), isn't it? At least for the later puzzles, part1 is often something that can be solved naively, while part2 needs some cleverness to not blow up.
Yeah, usually part 2 is. Bear in mind that tonight's puzzle is a warmup, it's day 1 after all!

I do find there's usually one or two spots that you can eek by with threads and throwing compute power at the problem. But those are rare — usually you have to actually solve it.

In previous years there have always been several I can just use a massive swapfile to get it
> site should ask for the language used to solve the problem and then use this as semi-scientific data for comparing "time-to-solution" for various languages.

I think this would just show you the average time zone of the language's users.

Today 4 minutes gets you top 1000. There’s more than enough users starting when the problem gets released that an analysis could be done by checking for solutions submitted within the first hour.
I generally find time to solution uninteresting and that how closely the solution models/mimics the problem statement the far more interesting thing.

I imagine that there’s a wide breadth of languages showing up in the top results but would guess that it skews towards imperative languages. Yet, the functional languages will almost read like the problem statement, which is what I find wonderful.

Only if language choice isn’t correlated with timezone. I suspect for many it is.
> The site should ask for the language used to solve the problem and then use this as semi-scientific data for comparing "time-to-solution" for various languages.

I can't believe any valid causal inference about languages could be drawn from this, because the skill of the individual programmer at solving these types of puzzles (recognizing the patterns, knowing the number theory, etc.) would surely dominate any impact of the language itself.

I suppose you could conclude something along the lines of "newer programmers use Python more often than Haskell", but I doubt there would be many surprises there.

It would work if language to programmer mapping was largely random with respect to skill level, or randomly assigned languages to use rather than giving the programmers a choice, but then you'd also need to give six months notice or something to learn the assigned language if they didn't already know it.
Try codingame.com.

You'll see those stats and others' solutions (well, not on all challenges).

I’ve used AoC to dabble in new languages. This time I’m going to learn emacs instead. Vi/vim for over 20 years…