1388 points · by thinkingemote · 1y ago · 554 comments
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.
My day 1 rust solution:
cargo solve 1 --
release
Finished `release` profile [optimized] target(s) in 0.05s
Running `target/release/01`
Part 1: 1189304 (95.8µs)
Part 2: 24349736 (120.4µs)
Day 1 clojure solution: lein run 1
running all tasks for day 1
reading input from resources/day01.txt
running day 1 part 1
part-fn: #'aoc.day-01/part-1
took: 5.511375 ms
result: 1189304
reading input from resources/day01.txt
running day 1 part 2
part-fn: #'aoc.day-01/part-2
took: 1.822334 ms
result: 243497365
Code here: https://github.com/whalesalad/aochttps://old.reddit.com/r/adventofcode/comments/1h3vp6n/2024_...
Though it is just a beginning and maybe it is a matter of habit,but I should say, that reading LISP family language is so difficult for my brain.
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.
Rust to me is what a modern take on a systems language would be. I think it’s substantially better than go.
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)?
Each day is a new module, this way I don't have to think of new names for part1() and part2(). I can still import code from the rest of the crate if I want with `use crate::`.
If you like this style of structuring the project, you may be interested in the generator I use for it - http://github.com/nindalf/aocgen. `aocgen --day 2` will create these files and save you a bit of time. It will even download your problem input if you give it your adventofcode.com cookie.
Also check out https://codspeed.io/advent/day/1 for other Rust solutions that are aimed at being fast. They all use the same project structure. I wouldn't read the top 20 solutions though, they sacrifice readability and idiomaticity for speed.
Though you shouldn't upload the text and inputs of the puzzles (maybe .gitignore them) as per [0]:
> Can I copy/redistribute part of Advent of Code? Please don't. Advent of Code is free to use, not free to copy. If you're posting a code repository somewhere, please don't include parts of Advent of Code like the puzzle text or your inputs. If you're making a website, please don't make it look like Advent of Code or name it something similar.
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.
Not unworkable, but not the most relaxed environment for fast’n’fun cowboy coding. You typically have to reboot a lot.
What was the issue with lack of memory protection? If you're used to programming in C is there actually that much difference to running on a modern PC or embedded system?
I say it in jest but that's actually how I used to program a few years ago when I was working on large industrial pieces of software with long compilation time. You just have to be careful and check what you wrote before sending it to the machine.
I think "iterative" programming has made people really complacent when it comes to silly errors. Slowing down can often do wonder.
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.
https://www.musixmatch.com/lyrics/Kraftwerk/Boing-Boom-Tscha...
Remember that brute force is also a solution in the AoC; had plenty of fun using SBCL to crack some problems where Pythonistas had to be clever, last year =)
- you can implement a hash table in C in about 125 LOC and reuse it.
- hash tables are not the only way to solve problems. hammer/nail
Only if you write/read your table in two separate passes. A tally needs mixed read/write to increment a counter, not just insertion, so it must be kept sorted during the table creation. Some kind of tree or linked list is probably better in this case.
> you can implement a hash table in C in about 125 LOC and reuse it.
I know. Anyone who uses C and never made at least a basic FNV1A/bucket-based hash table must be insane. But I wanted a small self-contained .c here and have become allergic to (void *); if I were to use C seriously, I'd fix it using a better preprocessor (à la https://github.com/etwyniel/c-generics).
> hash tables are not the only way to solve problems. hammer/nail
Eh, a tally seemed the most intuitive way for the 2nd part.
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
Well, awk suffices to write a first-person shooter: https://news.ycombinator.com/item?id=34442528
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.txthttps://ngn.codeberg.page/k/#eJxVjsFugzAMhu95iiyWik1CIGPtIVG...
I have no interest at all in competitive programming or maths; I spend 40+ hours a week doing programming for work, I want games and challenges that pull me away from that so I continue to have a life outside of my job.
My daily grind is like carefully scaffolding and repainting a 50 storey office building made of typed, modular, spaghetti couples Python ML code.
AOC in ipython, by comparison, is like doodling pictures with a brush pen!
It is very enjoyable and also why leetcode is a little silly for interviews: convince me you can I want to know a candidate can flawlessly paint several hundred square feet of wall, not doodle a cat cartoon.
(Or, away from the analogy, the software equivalents. Can you safely progress business goals as a member of a team on a legacy codebase that’s partly evolving on the cutting edge and also partly rotting on the trailing edge? I don’t care if you can build a naive implementation of our trading system… sorry I mean an Elephant Auction… in 90 minutes!)
Some time ago I started creating mods for the game stardew valley. It still involves some programming but mainly drawing, creating animations and composing music! It's an absolute blast and so relaxing (like the game itself).
I think by now I could even start working on my own game but I don't yet have a desire to.
Note it's a single-use game.
https://boardgamegeek.com/geeksearch.php?action=search&objec...
(I don't see any reference to leetcode, but people can approach Advent of Code however they like. I'm certainly not waking up at 5:50 to race for a solution.)
At best, I tend to set myself an upper limit for runtime.
If you have never tried it you should definitely give it a go. It’s quite enjoyable at a moderate dosage.
I’m not seeing my name on a leaderboard any time soon.
For 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.
So it's not linear, and also based on your own knowledge. So perfectly fine to skip some days and still it's possible to solve some of the next ones!
You try telling that to my brain. That guy doesn’t listen to me.
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.
My script still says "TODO: find a real solution". Good times.
Which one was the "graph-cut puzzle" ? I've had a few where I couldn't do them on the day, either I was busy or I found them harder than usual or sometimes both.
It looks like in 2023 I took until almost New Year's Eve to finish, but until like the 21st of December I was fine, I got thrown off by travel and other commitments in the last few days as they got more difficult.
The problem with continuity across days is that the later days can be blocked by the earlier ones, as they were in 2019. That partly defeats the purpose (or structure) of the challenge, where you can mostly pick any day and try it without regard to earlier days or prior years.
I thought the IntCode thing was great and I hope to see something like that again this year.
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".
It's totally worth it, though, especially for the first week, when you look up how other people solved the thing you just solved. I always learned (or re-learned) something from that. IMHO there's not that much value in looking up solutions before you solved it yourself, though.
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!
Every year except for one has been kind of the same pattern for me:
Day 1: this year, I'm just going to solve the problems. No futzing around.
Day 3: but it would be kind of neat to turn the solutions into a reusable AoC library. Just something minimal.
Day 5: and I should really add a CLI harness for retrieving the problems and parsing the input files.
Day 6: and testing of course.
Day 7: maybe I'll skip today's problem (just for today) and keep improving the framework.
Day 358: oh neat, Advent of Code is coming up.
But I luckily managed to avoid the "reusable AoC library" problem around 2019 when a week beforehand I wrote down the sort of functions I wanted to have at my disposal (usually things around representing 2D/3D grids of unknown size and pathfinding/debugging therein, but a few other bits and pieces) and made a simple library that I will sometimes add things to after I'm done with the problem for the day.
I was tempted to some functions (similar to those your CLI harness provided) for retrieving test data and submitting answers but I managed to stop myself short of that! But I am sure you're far from the only one to end up down that road.
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.
PRevious years I've managed basically the entire month of December.
I always have holiday days left over at the end of the year to take.
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.
they have part of the site that has lessons for developers:
https://app.codility.com/programmers/
I haven't used it for a long time, but they also have contests with some small prizes: https://app.codility.com/programmers/challenges/
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. with Ada.Strings.Unbounded.Text_IO;
use Ada.Strings.Unbounded.Text_IO;
with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
procedure main is
Line: Unbounded_String;
begin
Line := Get_Line;
Put_Line(Line);
end main;
https://learn.adacore.com - good source of tutorials, unfortunately a lot of the better learning materials beyond this are books, not online tutorials.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.
There are plenty of professionals with jobs and families making time for AOC because they enjoy it. Doing the problems at the same time as everyone else is a VERY different experience from doing them whenever you'd like.
If you don't want to make the time for it, power to you. I'd recommend most people to drop off after the first 10ish days. But don't delude yourself by ascribing this as the domain of "young people" or those without responsibilities. You're making a decision. Own it.
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.
I created a repo for my solutions here: https://github.com/lyxell/aoc2024-sqlite
Update: Wow. Reading your solutions was a real eye-opener for me. It never struck me that one can exploit the fact that unmaterialized CTE's will not be evaluated for rows that is not needed by another SELECT and one can use this the same way one uses laziness in Haskell. This is great stuff, thanks again for sharing!
I realized when solving todays problem that SQLite’s
json_each("[" || T.c1 || "]")
Is useful for parsing comma separated rows into (row, col)-pairs as well.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.
Fortunately it's never been needed. Every time it's come up the problem has been solvable with high school algebra level math skills (you need to know what the lcm is and that's covered in middle school in many places). If you knew the CRT you could jump straight to a solution, but a solution was easily derived using algebra and a couple loops.
I think a lot of people are so focused on "optimal" solutions they fail out or burn out quickly, ignoring the ugly "just loop a bunch of things" option.
I'm by far an expert on AoC, but the number of people I see every year on day 2 or 3 saying "IT'S TOO MUCH" because they were trying to implement some crazy algorithm when basic array operations and for loops would solve it...
I flunked out of high school. I don't even properly understand algebra, never mind any sort of complex math. I have no CS degree. I've completed most of it in some gross PHP that completed before next year on a single core in an old laptop.
If "knowledge of obscure algorithms" is a requirement either I'm a once in a generation genius or... it's not a requirement.
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.
I think the strategy for the harder puzzles is to still "do" them yourself (i.e. read the challenge and understand it) but write the solution in English pseudocode and then have an LLM take it from there. Doing this has yielded perfect results (but less than perfect implementations) in several languages for me so far and I've learnt a few interesting things about how they perform and the "tells" that an LLM was involved.
i1:("I I";" ")0: `:1.txt;
sum {abs last deltas x }each flip asc each i1 / answer 1
sum {x * sum x = i1[1]}each i1[0] / answer 2 from collections import *
xys = list(map(int, open(0).read().split()))
xs = xys[::2]
ys = xys[1::2]
xs.sort()
ys.sort()
print(sum(abs(x-y) for x,y in zip(xs,ys)))
yc = Counter(ys)
print(sum(((yc[x])*x for x in xs)))What does each flip asc do?
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.
Enshittification occurs when previously good or excellent things are replaced by mediocre things that are good enough for those susceptible for advertising and group think.
Examples are McDonalds vs. real restaurants, Disney theme parks vs. Paris, the interior of modern cars, search engine decline, software bloat etc.
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...
AoC usually loses my interest around day 6 or so, but a PDL journey for the advent sounds a lot more appealing. Time to dust off my Perl skills and see if I find it as fun today as I did back then.
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'm going through each day and asking ChatGPT to speed it up, it doesn't always work, but that is the way of the Gippity.
The payoff is these heavy iterating operational scripts I run for work will end up running faster :)
Learning when to lean on some of the .NET primitives really helps speed up PS as it likes to wrap things with unnecessary features.
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#.
I suppose. I do actually useful projects at work. AoC reminds me of why I personally loved programming in the first place - solving small technical puzzles. I don't like trying to make every single moment of my life "productive".
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.
In particular the LLM cheating isn’t just by conjuring a solution: humans don’t get ASCII characters pumped directly into their brain, we have to slowly read problem descriptions with our eyes. It takes humans more than 9 seconds to solve AoC #1 purely because of unavoidable latency.
Personally I don't do it to compete, I just like puzzles.
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
Compare https://adventofcode.com/2024/leaderboard/day/1 to e.g. https://fuglede.github.io/aoc-full-leaderboard/
There was also at least one instance of people working together where you would have 15 people from the same company submit solutions at the same time, which can be a bit frustrating but again, not a huge issue.
Usually this goes for any median which might be in a sneaky bimodal distribution of, say, AI models vs humans. I guess it applies to leaderboards too though.
A problem that wouldn't be immediately solvable by LLMs would either be too advanced or simply too large to be fun.
This is probably where programming as a whole is going. Many of the things that make programming fun for me, like deeply understanding a small but non-trivial problem and finding a good solution, are gonna be performed much faster by LLMs. After all most of what we do has been done before, just in a slightly different content or a different language.
Either LLMs will peak out at the current level and be often useful but very error prone and not-quite-there. Or they'll get better and we'll be just checking their output and designing the general architecture.
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.
Of all the cynical comments I see on HN, this ranks very very low.
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?