Advent of Code 2024

Advent of Code is an Advent calendar of programming challenges held from December 1st through December 25th each year. The first event was in 2015, and I’ve been participating since 2020. I thought this year it would be fun to have a thread about it here in case anyone else here is taking part.

The way it works is that there is a Christmas-themed story where you are a human working with elves at the North Pole. Every day at midnight US Eastern Time (UTC-5), a new part of the story and a corresponding programming puzzle unlock. Each puzzle has two parts, with the second part unlocking after you’ve solved the first part. Once a puzzle unlocks, it stays unlocked forever, so there is no pressure to solve it immediately (although there is a leaderboard where the first 100 people to solve a puzzle get points). If you don’t have time to solve puzzles every day, you can do them later at your own pace. You don’t have to do them in order so you can skip ones if you want. You can even go back and do puzzles from previous years.

To solve a puzzle, you must first download your input. (I recommend downloading via the “save link as” option rather than copying and pasting.) Each problem has multiple possible inputs, so not everyone gets the same one. You can solve the problem in any programming language you like and then enter the result (not the source code) into the form on the website, which will tell you if you are correct. For example, there was one puzzle one year where we were given a list of numbers and had to count how many times a number in the list was greater than the one right before it. That count is the answer you would enter. You get a star for every answer you get right, so if you complete a year, you will have 50 stars.

Early problems are generally easier, while later challenges are more challenging. Programmers of all experience levels may take part, but novice programmers may only be able to complete the first few days. Last year, less than 5% of participants who completed the first day made it to the end, to give you some idea of the progression of difficulty. The difficulty of any given day will, of course, also vary based on your own strengths and experience. It helps to have a background in data structures and algorithms for the later puzzles. Expect to see some pathfinding problems. Efficient algorithms are crucial for many of the later puzzles. A math background also helps because there is usually a problem or two that is easy if you know an applicable math theorem. Advent of Code is a good opportunity to learn something new so don’t worry if you don’t know how to approach a particular puzzle. Some puzzles are tricky because you must examine your input for special properties that make the problem solvable or look for patterns in output produced by each loop iteration. The input is part of the puzzle, so remember you only need a solution for your input, not any possible input. You may want to think of them as puzzles that require programming rather than straight programming challenges.

There is a FAQ if you want to learn more. Or you can ask questions here. I’m looking forward to learning some new things and saving Christmas again! I’ll be using C# and have a goal of getting 40 stars. What about you?

I’m in. I doubt I’ll get far, but I’m in.

I’m a programmer but don’t know any math. Are there hints along the way?

Is it even worth trying? Lol

I haven’t heard of this but I’ll give it a try. I’ll probably write in Perl unless there’s some reason a specific problem would be much easier in another language. I’m a retired software engineer but I spend a fair amount of time doing recreational programming so this sounds like fun.

Don’t worry about not knowing any math. There’s usually only one or two problems each year that are math problems. We can help each other with hints in this thread. Past problems have included the Chinese remainder theorem and the shoelace formula. I hadn’t heard of either of those before, but after getting some hints from the subreddit, I found it fun to implement them. If you enjoy programming at all, I’d encourage you to give it a try!

Will do. Might use it to learn some basic Python with ChatGPT help.

I tried last year’s just to see how difficult it is. 2023 Day 1 Part 1 was easy, but Part 2 was frustrating because of the poorly-defined requirements about what should happen when there’s a word like oneight – should it be replaced by 1, 8, or 18, ugh.

Sure, I’m willing to try. I’ll probably do it in Python, as well.

There’s a little less than 13 hours until the first day unlocks! Yay!

Got the first one. It took me about 8 minutes, but I wasted a couple of minutes getting the input file downloaded and in the right directory. Then a stupid typo in my program cost me another couple of minutes.

ETA: OMG, my time was ranked #3635 on the leaderboard. That is, 3634 people solved it faster than my 8 minute time. I guess I’ll abandon hopes of getting on the leaderboard.

Yay, an nice, easy-peasy one to start with. Not like last year’s “Twone Problem” that had everyone tearing their hair out. :smiley:

I got my first two stars so I’m off to a good start. Let’s go find that Chief Historian!

Thanks to the OP, this sounded interesting to me. I retired five years ago from my job of eleven years teaching programming at a community college, which came after a couple decades of programming (mostly in C) at a major computer company. And I have a masters degree in software engineering, so I know algorithms and data structures and all that. So this should be fun!

I immediately understood the assignment - err, problem - and had to decide which language to use. C? which I’m very familiar with. Or Java, the major language I taught? Or Python, which I used in the introduction to programming class? I chose Python, because I’m anticipating problems that will push its capabilities to the max.

Oh, Python! How do I start a loop? Oh right, a semicolon. List appending, text to integer conversions, all that. I had to look up a few things (OK, lots of them), which shows either how good of a teacher I was, or how easily you forget stuff if you don’t use them continually.

Once I got started, it was easy. That said, if this was an assignment in my class (any language), any beginning student that completes it would deserve an A for the semester.

I got the two gold stars, but I’m afraid to look at how much time it took. I’m sure it’ll get tougher, but I’m looking forward to the challenge.

Any theories on what the ASCII art picture on the homepage is going to be? So far it’s looking kind of like a semi truck and trailer facing left, but I doubt that’s what it really is.

It looks like it has elements from previous years’ art. The top left looks like an island from 2023, the top middle looks like a tree from 2016, and the top right looks like a reindeer from 2018. I think since this is the 10th year, we are doing a retrospective.

It does seem like the story is visiting places from past stories, too. What a fun idea!

I got today’s answers, but I’m a little annoyed at an ambiguity in the instructions in the first part. It wasn’t clear to me that the word has to be in a straight line. I initially thought something like this would be acceptable:

.XM..
..A..
..S..

and went on a wild goose chase for an hour or so trying to figure out why I was getting counts much larger than theirs.

I had considered the possibility that they didn’t have to be in a straight line, but when I looked at the example, I saw some that were not in a straight line and were not being counted.

I had search the boxes in the dusty attic I call my brain for sorting algorithms today. :smile: I haven’t needed that knowledge in years.

I’m using Perl so I just used the built-in sort function, using a comparison function that I implemented in part 1. Couldn’t you have used the C# List.Sort method?

Now that I think about it, I probably could have. There was a puzzle last year where I implemented a CompareTo method and then called Sort on the List so I could have done something similar for this one. For whatever reason, I guess I just fixated on needing to implement a sorting algorithm.