Advent of Code 2024
adventofcode.com
adventofcode.com
This time I'm trying to do them in Rust and Golang in an effort to either learn to like/tolerate Golang (because we use it at work) or prove my hypothesis that it sucks and never use it unless I have to.
I can't compare with Rust though because I've never used it. From a very superficial point of view though, it feels less pragmatic. But since AoC doesn't need memory safety or whatever criteria you have for production software, pragmatism and performance for later challenges are more important than safety.
I try every year to optimize for speed in zig: https://github.com/ManDeJan/advent-of-code
I have the opposite dilemma to you, I want to learn to like Rust.
I tried doing Rust, but I'm too dumb to figure out if each day should be a module or if I should use lib (I guess?) files for each day and link everything to a main entry point.
Can you share your repo (if public)?
I tried doing it in Assembly two years ago, ended up spending hours and hours writing an Assembly standard library, then gave up and switched to Rust...
This year the Amiga has an 060 upgrade with an MMU, so perhaps I can figure out how to use that and have another go.
https://git.sr.ht/~q3cpma/aoc2024/tree/master/item/01
If you could post a repo link so I can look at some of the progress, I'd be grateful.
Last year I solved all the problems in C without external libraries [1] and I enjoyed it a lot. It forced me implement some low-level stuff that I had forgotten how to do (e.g. a heap) and to write some numerical routines myself (easier than you'd think!).
[1] https://github.com/sebastianotronto/aoc/tree/master/2023
I remember one of my naive brute force solutions from last year ended up allocating gigabtyes of memory. There were obviously more efficient solutions, but some of the inputs are pretty large and so hefty allocations might be difficult to avoid.
I think I'll follow in your footsteps. STM32F7 with 320k but with bare metal Rust :)
It's not half bad at this kind of twiddling for being a statically typed mainstream language.
https://github.com/codr7/aoc24/tree/main/swift/Sources/aoc
This year is a tiny bit weird, I was just getting ramped up organizing the event at a new job; because I think it's very useful for devs to learn some real problem solving, as opposed to stitching frameworks.
And then I had to leave because my new boss turned out to be someone I couldn't imagine working with.
Guess it'll be just me and Emacs as usual.
It’s Foundation so hopefully also on Linux/Windows, but if not there’s also one on GitHub called SwiftScanner.
1: https://developer.apple.com/documentation/foundation/scanner
The language has been moving pretty fast though, I have a feeling a lot of features I find useful are relatively new.
That is if you have nothing against using VSCode.
Sure, but then what's the point?
As of last week there were something around 1024 people who had all 450 stars.
Only started on like day 6 of 2022, but became hooked and had some time early in 2023 to go through the previous years. Once you have a few algorithms canned, it's not too difficult and some themes repeat across years.
It's fun to brush up on stuff you don't touch all the time - actual algorithms and stuff.
Hats off to the volunteers and Eric - I aim to donate every year now - it's a great event.
I encourage anyone who gets value from this to donate to support it if they can. It is a passion project but nonetheless comes with real costs.
With the sheer amount of sponsors and AoC++ users I do believe that this is not quite a small 'passion project' struggling to pay the monthly subscription to a VPS.
That being said, adventofcode is absolutely great and people should support it if they can. But I do think the author is doing quite well with the amount of support he is currently receiving.
For the pythonists around here, give F# a try: it can feels very close to scripting and it has a wonderful REPL too :)
For AoC I don't use a real project setup, just a `dayX.fsx` file and I run it like a script with `dotnet fsi dayX.fsx`, et voilà :)
+/'{x:".",x;H:(-1+;1+i-)@'+|\m*i:!#m:x=\:"#."
R:(x=x)({[h;d;x;y;z](z#0),+\(((-z)_~"#"=x)&z_d>z)*(*y),(-z+1)_y-0^y h}. H)[x]/y
(*|R)-R@*|0,&1_*+m}.''1({("?"/:5#,x;,/5#,y)}.')\@[;1;.:]'" "\:'0:`:i/12.txtFor me Advent of Code is a slippery slope. The difficulty ramps up so at first it's easy, then it's rewardingly difficult. But then before I know it, it takes wayyyyy too much time. The danger is being emotionally invested by then.
After I solved it I looked at other people's solutions and they used Meta's proposition solver in about 10 lines. Seemed like a massive cheat to me.
I think as nerds we need to be quite careful not to get too drawn into this kind of thing. Sometimes it's like a superpower, but other times it just pointlessly consumes your life. Kinda makes me think of gambling addiction: "when the fun stops, you stop".
That said, if you'd have a better holiday season by just stepping back from the computer and relaxing then that sounds great too. Either way - enjoy!
What line of work are you in that you can take a winter break, and furthermore, that you can actually not work during that break? I'm envious...
I've always wanted to do AoC but on top of work it is too much.
I like to do them in a functional style in Kotlin as far as possible, as that's different from what I do at work.
Edit: Here's mine from today, with my utils it's not exactly plain kotlin, but part of the fun is building a library of sorts with cool functions https://github.com/Matsemann/algorithm-problems/blob/main/ad...
This is also what I like, reading other's solutions and learning new stuff. I browse the subreddit after solving it myself to see all kinds of cool approaches.
FYI trying to solve the problems as fast as you can is not considered "the correct way". The author has emphasized multiple times that going for the leaderboard is not for everyone and requires a pretty questionable coding style. The main goal is to have fun and learn something new.
Wishing everyone a fun challenge. This year I will be practicing F# and hope some of you will give it a try too :) https://github.com/neon-sunset/AOC24/blob/master/day1.fsx
With leetcode you’re off in the woods by yourself. Stuck on a problem? Here’s a cold write up. Finished a problem? Do another, monkey.
Then once you do get that context... like LeetCode problems often aren't very inspiring? A lot of the time it's "just apply this technique here".
Whereas in AoC, at least in the first few weeks, it's mostly just, do the task, attack it from first principles.
I’m never gonna do it fast but I enjoy using fparsec to get the input text in whatever format I need each time, even if writing and debugging the parsers sometimes takes up way too much of my time!
curl "https://adventofcode.com/2024/day/$DAY/input" --header "Cookie: $(cat .token)" > input.txt
#!/bin/sh
set -e
curl "https://adventofcode.com/${YEAR:?}/day/${DAY:?}/input" --cookie "session=$(cat .token)"
then: YEAR=2024 DAY=1 ./aocdatahttps://github.com/NoelJacob/advent-and-other-calandars Compiled by myself.
I've promised myself that one year I will move beyond the first seven prompts ... who knew creativity could be so taxing?
I think there's a few of these for different languages/tech. I think they may be good for HN'ers seeking some kind of little daily advent-y fix without the potential emotional/mental investment of AoC.
Ada took me somewhere between 90-120 minutes, whereas I had the first problem done in JavaScript in about 30s-60s, just for verification.
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;
procedure main is
Left : Integer;
Right : Integer;
begin
Get(Left);
Get(Right);
Put(Left);
Put(Right);
end main;
If you give it any of these pairs it'll work as expected, put it in a loop and you'll get all of them: 1 2
3 4
5
6
Sometimes thinking about lines is a red herring in AoC, the lines often don't matter, only getting each value into the appropriate collection (a pair of vectors in this case since you don't know the size). For the counts, you can use a hashed map, they're built into the standard library. If you learn to use them now that'll help you out in later days, they're a commonly used collection (for me) in these challenges.If there is a community for those who use other rules to compare actual solutions instead of answers I would be interested to hear about it.
I am coming from low level C++ gamedev side so I understand that most people here use different tools to solve different problems.
If your goal is to compare solutions, lots of that happens on the subreddit for it where people post solutions in their language of choice on the daily threads.
I just do it for fun. When I was younger I'd actually do them at release (11pm in my timezone), now I don't even bother and just used them as sort of a brain teaser to start my days and compare with coworkers who also do it, a lot of us in different languages.
The subreddit /r/adventofcode contains discussions of solutions with lots of different skill levels.
I've done AoC for five years to learn new languages and try solve all of them myself during the month of December. (Dunno if I'll run the whole thing this year - I have another project.) Others try to get on the leaderboard, and some will implement solutions that they've seen sketched on reddit.
Last year a few people used Z3 for one of the problems, and I went back and tried that to get some experience with Z3. And I've occasionally gone back and tried another approach or new trick that I saw on the subreddit. (In the years that I've used Lean, I've sometimes gone back and added proofs for termination or array indices, too.)
Looks like it is for young people who have dedicated time for it everyday.
Personally I would like to do anything like this with no time limit and probably no monetary prizes. I think the only value of those puzzles is to fire up rarely used neurons that hopefully are still there after another year of shipping corporate products xD. I might appreciate fresh point of view from young people and new programming languages though.
Sry, can't upvote because I mostly read HN not logged in so I still can't upvote. If there were some other performance oriented forums either on reddit or somewhere I seem to be too lazy to find them anyway.
Generally you have the main community on reddit (memes, questions, daily thread for sharing solutions), then the language specific subreddits or hosted forums where you will see solutions discussed and shared, plus a couple of new users asking questions.
Also, within the daily main community thread you will see the niche sub community of people posting their code-golfing attempts.
However, there are other ways to rank yourself against others. You can order your private leaderboard by number of stars, or make your own leaderboard using their APIs.
But no, last year I lost all momentum on my side projects and my gf thought she'd lost me to the elves.
Completing it on time was rewarding but I can't go back.
But I can hear those elven bells a jingling...
This year I'm declaring "Advent of Claude"!
Challenge: Write a Claude custom style to solve Advent of Code puzzles within Claude's UI.
Score: # adventofcode.com stars earned in 2 daily conversation turns.
Fine print: web app artifacts are allowed, including paste of your custom input into the artifact UI; one click only.
Per https://adventofcode.com/2024/about, wait until the daily http://adventofcode.com leaderboard is full before submitting LLM-generated solutions!
Of course, feel free to use ChatGPT custom instructions, static prompts, etc.
Day 1: two stars, https://claude.site/artifacts/d16e6bdb-f697-45fe-930c-7f58b2...
Is there a place where you're blogging this or at least aggregating the links so we can see how far you get with it as the puzzles get more challenging?
Normally I'd break out Python for this, but given the constraints maybe I should try to see how far I can get through this in Excel. It'd be a fun little challenge :)
(I think you could even use typescript with this method with the on the fly babel transpiler (you just include a script tag) but I haven't tried that.)
I love what Advent of Code does, but when your site is all text, there's just no excuse to not let the user resize it by default.
Probably some problems will be impossible with limited RAM (2KiB, plus an optional 8KiB on the cartridge, maybe more if a fancy cartridge is used). But I'll try to solve as many as possible.
Today's was possible, in under 4 seconds, using 4KiB extra RAM on the cartridge.
https://gavinhoward.com/2024/11/advent-of-code-2024-getting-...
And here I am doing it in Ruby instead of Java this year thinking I was giving myself a challenge.
Edit: Someone else posted an "Advent of " list which included https://adventofsql.com/, perhaps those problems will be a little more pedestrian for SQL.
The use of “pretty far” gives them a bit of an out, but I think this statement is a little disingenuous. Last year, at least, a bunch of the problems needed fairly sophisticated algorithms to find the solution in a reasonable amount of time.
To me, a little programming knowledge is what somebody who is six weeks into their introduction to programming class has. They know variables, loops, lists, and maybe associative arrays.
It's more like a set of logic puzzles. Programming and algorithms are only incidental.
Skimming some, the core of Part 1 after people have parsed and sorted:
Python:
sum([abs(x-y) for x,y in zip(left,right))
TypeScript: list1.reduce((acc, cur, i) => {
return acc += Math.abs(cur - list2[i])
}, 0)
Common Lisp: (reduce #'+ (mapcar (lambda (l r) (abs (- l r))) sorted-left sorted-right))))
Julia: sum(abs.(list1 .- list2))
Rust: Ok(zip(left, right).map(|(l, r)| l.abs_diff(r)).sum()
F#: Seq.map2 (fun x y -> abs (x - y)) xs ys |> Seq.sum
APL: +/|-⌿
Haskell: map abs $ zipWith (-) column2 column1
and then all the submissions which don't do anything like this, and have manual loops and indexing and clunky data representations or performance-optimized data representations, etc. etc.Doing it in a Lisp I’ve been writing in Ruby will have me giving up even sooner, but it will be fun!
Just write that once, put it in a template /day0 folder that has /day0/part1, /day0/part2, and /day0/input.txt, and then just copy it and focus on the actual problem. It's all about having fun!
EDIT: nevermind, found it! https://github.com/ruuda/adventofcode/tree/master
The past few years I've decided to stick to the same principle I've used in all of my side projects recently. Either I do something in a new language, or I get it done correctly before I get bored. I've found I can't have both.
Repo: https://github.com/ArcHound/advent_of_code Writeup: https://blog.miloslavhomer.cz/p/advent-of-code-cli-client-an...
Good luck to y'all in 2024 and enjoy!
Obviously if you're doing it recreationally you can cheat with AI but then again that's no different than copying a solution from reddit and you're only fooling yourself. I don't see it having an impact.
Either that, or there were hundreds of people trying and none were able to get it working despite the basic problem. I like to imagine most people reading the rules and being a good sport.
https://blog.adacore.com/announcing-advent-of-ada-2024-codin...
Everything is here: https://advent-of-code.xavd.id/
I'm unlikely to finish it all in December (the puzzles get hard and I get busy) but I _do_ love the event.
The main exception is 2019's Intcode VM/interpreter which was used over about a dozen days (I mentioned it elsewhere, he hasn't done anything like that since). Occasionally, beyond basic algorithms there is some continuity between 2-3 days but that's not terribly common, I don't think there were any pairs of puzzles like that last year or the year before.
If you want to make one code base, you'll still have 25 or so separate solutions. You might have some continuity with common algorithms (like A*) that get used a fair bit in search problems or abstracting out the input handling when you identify common structures for parsing.
https://raku-advent.blog/2024/12/01/day-8-rendering-down-for...
Which is weird because that is not a thought that entered my mind when I did it for the first time. It was pure fun!
This year, I shook my head at my framework and rewrote it, but at least that only took me a day (so far). Day one was easy, which also helps. IIRC, last year’s first few days were non-trivial.
https://www.kylheku.com/cgit/advent/tree/2021
Give it a try. The structure and recurring themes in these solutions could be used as a source of ideas for how to get started.
I already solved the first problem and it was hard to get things ready, read the file, handle the data, etc. But once I had the first steps done it was easy to solve the problem
For this one, I learned how to write a basic parser with Text.Parsec and manipulate the tuples with bimap !
It's a very fun occasion to learn a new programming language.
My goal is to develop the muscle memory for the tool so I can write code quickly. I’m still generally thinking through the puzzles, but being able to just write out plain English logic, get code generated, ask for it to be well documented, quickly refactor things to be generally reusable, etc, is just fantastic and how all software development should be done in this day and age frankly. Such an accelerator to problem solving.
I want to use it as a test to see how human programming can be improved by an AI, so I wrote the solution for day 1, got the right answer, and then gave my code to ChatGPT 4o to ask it to make the code faster.
My version ran in ~3500 ms ChatGPT's version ran in 140 ms
both worked
A great example of how a common DevOps language program can be improved on by ChatGPT.
My hack-it-out code: https://pastebin.com/PDQhxDc9
Faster code: https://pastebin.com/6xwaVkwq
The hacky code uses slower techniques like:
- Get-Content which adds metadata to every line.
- @() arrays with += which copies the array in memory to a new one-larger memory location for every addition.
- Pipeline overhead e.g. ForEach-Object and Measure-Object.
- Filtering the whole second column for each number in the first column, repeated wasted work.
and it's still in the region of your ChatGPT one.
The faster one addresses these with:
- ReadAllLines() .NET method to get plain strings.
- [system.collections.generic.list[int]]::new() which don't box integers and can grow more quickly.
- plain adding numbers into sum variables.
- Building a hashtable [system.collections.generic.dictionary[int, int]]::new() to count each number in the second column.
- Swapping -split for string split() which may have a tiny bit less overhead.
- no pipelines.
The code isn't completely different, it's the same blocks doing the same things, leaning more on .NET lower levels, and years of experience of the basic PowerShell performance hits.
I've found especially as the month progresses it's just as much Advent of Reading Comprehension as it is coding :)
Perhaps if you aimed at global leaderboards it would be different, but that's neither my league nor I see any fun in that - getting there requires serious effort and preparation in things that aren't directly related to solving intelectual puzzles.
I find no particular pleasure in using an everyday language like Python for it, because as you said it's too easy.
I have used Haskell, Racket, and in some easier cases APL and it's been fun. Treating it more like a puzzle than an actual programming assignment.
When learning new languages, it's best to do something that actually makes you think in a different shape. If you know Python, don't do Ruby. If you know Java, don't do C#.
Pretty good tbh
BTW I love AoC for all else
Come to think of it, a pipeline that feeds the problem text into an LLM to generate a solution and automatically runs it on the input and attempts to submit the solution, doing this N times in parallel, could certainly solve the first few days' problem in 9 seconds.
Later, after being called out on it, they posted an apology to their GitHub profile (https://web.archive.org/web/20241201064816/https://github.co...): "If you are here from the AoC leaderboard, I apologize for not reading the FAQ. Won't happen again."
Both the repo and that message are now gone.
2015 - 10:55
2016 - 7:01
2017 - 1:16
2018 - 1:48
2019 - 1:39
2020 - 7:11
2021 - 1:07
2022 - 0:53
2023 - 2:24
And this year's second place was 0:54.I can imagine a great pipeline for performance optimization: 1. have an AI generate millions of tests for your existing code 2. have another AI generate faster code that still makes the tests pass
So I guess all I want for Christmas is a massive compute cluster and infinite OpenAI credits :P
Perhaps there is a scope for an alternative AoC type competition aimed at AI submissions...
...though of course that would be experimenting to get us all out of work. Hmm.
I didn't realise it was be timed, which is good because I casually set up a new rig to give future puzzles some kind of rig. I used C# which, although probably more wordy than other solutions, did the job and LINQ made light work of the list operations. Ended up with about 6.5 minutes for each one but most of that was refactoring out of pedantry.
RIP Advent of Code.
Bit simpler than writing an override or fetching the HTML.
Everyone’s different, and it sounds like AoC isn’t for you, but remember not everyone is you :)
So if some activity [work] doesn't contribute to your ability to never have to work again [retirement], you shouldn't do it?
What if I've retired, am I allowed to do AOC then? Or then does the first rule of, only do something the future you would be proud of apply?
What if all of the things I'm proud of are just a false sense of accomplishments? How do I know when I'm actually allowed to be proud of it, or if it's just a false sense of pride?
Like car accident?