Readit News logoReadit News
zaptheimpaler · a year ago
I love AoC! Did it the last 2-3 years in Rust, hanging out in a discord where we all try to make the absolute fastest solutions. Learnt all kinds of crazy performance hacks and some advanced algorithms & SIMD that way.

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.

Cthulhu_ · a year ago
I've used Go in the past few years (but I never find the time / attention span to get any further than day 6), I really like it for this kind of thing because it's pragmatic, minimal environment setup / "sidequests", most things you need (reading/parsing files, etc) are builtin, performance is great and close to the metal (few hidden performance pitfalls), etc.

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.

makapuf · a year ago
Interested by your rust speed approaches, care to share a link ?
whalesalad · a year ago
Same. I am doing rust + clojure this year. Very interested in performance hax, esp around SIMD. I know absolutely nothing at all about rust, this is my first time working with it.

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/aoc

ManDeJan · a year ago
'd you be interested in sharing the discord? :)

I try every year to optimize for speed in zig: https://github.com/ManDeJan/advent-of-code

wanderingmind · a year ago
This server seems to be active, although they are all unofficial servers from enthusiasts.

https://discord.gg/wYmyYsf

xyproto · a year ago
Go (not "Golang") has better compilation times than Rust and does not try to combine incompatible ways of using concurrency.

I have the opposite dilemma to you, I want to learn to like Rust.

whalesalad · a year ago
Personally I loathe golang for the sheer fact that it was created recently enough to have included a much better design. Old languages get a pass.

Rust to me is what a modern take on a systems language would be. I think it’s substantially better than go.

jaredklewis · a year ago
Let's try to settle the Go/Rust debate in this AoC sub-thread ^_^
GTP · a year ago
flysand7 · a year ago
What's Go, if not Golang? I mean, there's some other programming language called Go that I don't know about?

Deleted Comment

otteromkram · a year ago
How do you structure your aoc project?

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

nindalf · a year ago
Take a look at my repo - http://github.com/nindalf/advent-2024

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.

Scipio_Afri · a year ago
Is there a discord every year? Interested in joining that if you don’t mind sharing
raulns86 · a year ago
Sounds like a very interesting Discord to check :)

Dead Comment

the_duke · a year ago
This years challenge for me: write it in C without the standard library or an allocator. Has to be runnable on an STM32 with 32kb of SRAM.

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

badgersnake · a year ago
Last year I tried C on a real Amiga 1200 (using DICE, Matt Dillon’s compiler / runtime). I didn’t get very far, lack of memory protection makes things really hard.

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.

simmonmt · a year ago
Forgive the dumb question... it's been ages since I've done Amiga programming in C. What behaves differently? Is the lower K of memory mapped, such that null pointer deferences cause excitement rather than simply crashing your program? Or is it something else?
ChrisRR · a year ago
> I didn’t get very far, lack of memory protection makes things really hard

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?

peterashford · a year ago
Heh. Yeah, a memfault tanking the machine is not conducive to iterative programming :o)
BoingBoomTschak · a year ago
Good luck! Personally, I'm still going with CL but decided to try it in all the languages I "know" for the first day. Including C which doesn't have hash tables (inb4 hsearch)... what a pain, let me tell you.

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.

nickstinemates · a year ago
I just want to note that Quake 3 CPMA is one of the best games ever made. No idea if the handle is in reference to that, but thanks for the :)
shawn_w · a year ago
POSIX `hsearch` is absolutely terrible and almost useless, but... it would get the job done for this problem.
Twirrim · a year ago
I don't think there are enough entries to make it worth the cost of a hash. I know it's not "efficient" exactly, but just repeatedly looping through and counting just isn't that slow.
liontwist · a year ago
- bsearch + qsort is a great way to implement associative tables

- 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

sebtron · a year ago
Your restrictions sound quite challenging, good luck!

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

derethanhausen · a year ago
Fitting, given that iirc one of the problems was to implement a hashtable!
foota · a year ago
As long as you can make an RPC call, anything is doable within 32kb of ram :-)
nine_k · a year ago
Symmetrically, I would consider only using sh and standard non-Turing-complete CLI tools (grep yes, awk no). About as limiting, but without devastating memory corruption bugs.
sudobash1 · a year ago
Awk is turing complete. You could do the challenges only in Awk if you wanted.
a_humean · a year ago
I think there might end up being some problems which will be very challenging to solve with those resource constraints - namely memory. You will probably have to be pretty clever with your solutions.

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.

the_duke · a year ago
Yeah I know it will be tough.

I do allow myself a 5Gb disk to which I can page out memory.

ChrisRR · a year ago
I tried doing it in C a few years ago but wasted so much time just not having a string library
uticus · a year ago
Assembly is so much cleaner on an STM8 8-bit. If you’re into that sort of masochism
mlsu · a year ago
Glorious!

I think I'll follow in your footsteps. STM32F7 with 320k but with bare metal Rust :)

ikiris · a year ago
this is like trying to solve it in a computer built in turing complete
127 · a year ago
Do you have a public repo?
codr7 · a year ago
I usually do AoC in Common Lisp, but this year I'm giving Swift a chance.

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.

timsneath · a year ago
Excellent! Come and join the Swift leaderboard here https://forums.swift.org/t/advent-of-code-2024 if you haven't already -- it's super interesting to compare different solutions.
usmannk · a year ago
dont you find all the string parsing and manipulation to be quite painful in Swift? I tried to do AoC in Swift before and that put me off a lot. I liked doing little functional one liners but a week from now the parsing burden will be too high.
mattdw · a year ago
I found the Scanner API (1) to be pretty handy for the more complex parsing in past years.

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

tarentel · a year ago
I program everyday in Swift. I attempted AoC for the first time in Swift last year and gave up after about a week or so for this exact reason and switched to python for the remainder. I don't want to struggle with the awkward string API to do things other languages can do in a line.
codr7 · a year ago
Nah, the String type is fine as far as basic functionality goes, I like adding my own convenience stuff in extensions.

The language has been moving pretty fast though, I have a feeling a lot of features I find useful are relatively new.

tomtom1337 · a year ago
I enjoyed reading your solutions! I’m surprised how terse they are!
codr7 · a year ago
Lovely! I try to strive for readability first and foremost, which is a challenge in itself.
clearing · a year ago
Are you writing the solutions / compiling / running all with Emacs? I wanted to try Swift this year as well but feels sort of silly spinning up XCode for this.
spaenleh · a year ago
You can use VSCode with a swift project created with the SwiftPackageManager (SPM). I find the experience to be good, with a good LSP support. I just have to sometimes trigger the build task for it to find newly defined objects.

That is if you have nothing against using VSCode.

codr7 · a year ago
Yep, on Linux, or WSL to be exact, I just use the internal shell though.
bargainbin · a year ago
Ah here it is again, 25 days of writing increasingly complex input parsers.
Jcampuzano2 · a year ago
Those are the problems I loathe the most, where the real problem is figuring out how to parse the input into something more workable. Once its parsed its ezpz.
zelphirkalt · a year ago
Are you solving all puzzles? I find usually that the parsing isn't my problem, but some of the puzzles puzzle me (ha, couldn't resist), because they expect some kind of graph knowledge or some mathematical trick or so. Last year got stuck at day 17 for example. Usually some learning in it then, but parsing, while possibly annoying day after day, wasn't usually what stopped me from completing puzzles.
63 · a year ago
After a few days I cave and just use regex, which I of course forget every year and need to relearn.
coolThingsFirst · a year ago
Hahahaha, this is so true. Regex is so easy to forget.
xdavidliu · a year ago
the input parsers don't get increasingly complex over the days. The problems themselves do. Even on the most difficult days around 22 or 23, the inputs are all just lines of space separate ints or some grid of points or something, just like the trivial problems on days 1-3
ricardobeat · a year ago
From last year: hot springs, the pipes problem, gears, pulses, range math.. half the problem is turning the text input into the correct data structures to solve it.
reocha · a year ago
It's input parsing with a fun story

Deleted Comment

tonymet · a year ago
i find ScanF and state machines are a lot more effective than split / explode style parsers.
fdrs · a year ago
Rust + nom makes it easier
cactusfrog · a year ago
Why isn’t the input a csv?
Jtsummers · a year ago
Sometimes it is, or very nearly is.
akx · a year ago
... and inevitably, a virtual machine
underdeserver · a year ago
Claude will do it for you.
reocha · a year ago
What is the point in doing a programming challenge if you aren't learning anything
talldayo · a year ago
So will Fiverr. Who cares?
timeon · a year ago
Why bother.
tirpen · a year ago
"Running a marathon is hard work, but a car will do it for you."

Sure, but then what's the point?

mattbillenstein · a year ago
Aiming to get all the stars this year to round it out with 500 total - all the years, all the problems.

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.

ctur · a year ago
Woohoo, one of the highlights of this time of year. I had to do mine from an eastbound flight over the pacific. This has become a fun tradition not just for me personally but for many friends, colleagues, and fellow HNers. Big props once again to wastl and his helper elves for making this!

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.

mteoharov · a year ago
> 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.

ducdetronquito · a year ago
I will try to do it with F# and Gleam this year, but like every year I won’t have time (and brain) to do more than 10/12 days ^^

For the pythonists around here, give F# a try: it can feels very close to scripting and it has a wonderful REPL too :)

thaliaarchi · a year ago
I'm continuing my tradition of doing AoC in Whitespace[0]. The first year I did it, it was motivation to build out a standard library so things wouldn't be so tedious. Now, I find myself wishing I had finished better tooling. I debug with wsjq[1], a CLI debugger like gdb written in jq, but it's slow.

[0]: https://github.com/thaliaarchi/ws-challenges

[1]: https://github.com/thaliaarchi/wsjq

axpy906 · a year ago
I am doing it in bash. Will see how far I can go!
ssernikk · a year ago
I've done last two AoCs in F# (well, only the first few days too). For a person without prior functional programming experience, it was fun! Unfortunately I won't have time to participate this year, but if I did, I'd probably chose F# again.
codeconscious · a year ago
Nice. I've started picking up F# too and am trying AoC with it this year. I'm still early in my functional journey, but I think AoC has been helpful thus far.
andrelaszlo · a year ago
How's linux support? :)
davidgl · a year ago
Perfect, run loads of f# and c# on Linux, and have for years
ducdetronquito · a year ago
Works like a charm for me with Ubuntu 24.04/VSCode/Ionide (F# extension) !

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

neonsunset · a year ago
If almost 9 years were not enough to make this question seem silly, perhaps DuckDuckGo/Kagi/Perplexity could answer this?
atribecalledqst · a year ago
Last year I got stuck on Day 12 for a full week, and thinking about how to solve it consumed my every waking moment. I think this year, I'm going to be kind to myself and not participate so I can really enjoy the winter break from work.
rak1507 · a year ago
What's so hard about Day 12? It's just

    +/'{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.txt

meisel · a year ago
This is what programming languages looked like to me before I learned programming
jnordwick · a year ago
I'm doing this year in K2 (after a long hiatus from K). Is there a K4/5 binary? ATW gave me a K2 binary, but I miss some of the K4 and later functionality):

https://github.com/jnordwick/aok2024

gcanyon · a year ago
Any idea how close that is to valid J code?
Jorge1o1 · a year ago
Is this Q? or k?
SketchySeaBeast · a year ago
It ate my life for a few years in a row, I even managed to finish on Christmas eve twice. Now I don't even look, it turns from fun to stress rather quickly.
ljm · a year ago
I re-read the intro and the fact it mentions leetcode and the like was enough for me to decide that it's an ultimately pointless endeavour for me.

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.

moomin · a year ago
Only year I ever completed it it took eight months.

I’m not seeing my name on a leaderboard any time soon.

alach11 · a year ago
I just do the puzzles until it stops being fun. For me that's usually around day 14.
orra · a year ago
Sounds sensible. It's important to set boundaries, and enjoy time off.

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.

matsemann · a year ago
There's a graph here of the "hardness" of each day/task, based on how long the 100th place on the leaderboard used. https://aoc.xhyrom.dev/

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!

tails4e · a year ago
I usually make it Monday 18 or 19 and then I loose the will as the time taken is excessive, and obsessing about it is not good. I've finished a 5 years, but all after the fact. Some I am not sure I'll ever finish....
pvinis · a year ago
A friend recently shared this with me. I think you'll like it.

https://eli.li/december-adventure

pkd · a year ago
Thanks, I like this.
adventofshmode · a year ago
I got stuck on the graph-cut puzzle for FOUR MONTHS. I had to write a force-directed graphing engine to find the longest three edges to cut.

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.

moustachehedron · a year ago
Oh man, this is my best memory of last year's AoC. After uselessly noodling for a while, I used Graphviz to draw the graph to an SVG file. It drew two messy balls of yarn neatly connected by three edges.

My script still says "TODO: find a real solution". Good times.

evah · a year ago
This was the day 25 problem: given a graph of ~1600 nodes and ~3500 edges, find the 3 edges that if deleted divide the graph into 2 components. I looked over some of the solutions and it surprised me how few used the simplest method: for each edge with endpoints u, v in the graph, delete it and then find another path P1 between u and v. Then, for each edge e1 in P1, delete it and then find another path P2 between u and v. Then, for each edge e2 in P2, delete it and then try to find another path between u and v. If there is no path, (u, v), e1, e2 is your cut-set. Otherwise, add e2 back and try the next edge in P2. When you've exhausted P2, add e1 back and try the next edge in P1. When you've exhausted P1, add (u, v) back and try the next edge in the graph. It's 3-6 loops deep depending on how you count, but it works. My python implementation completes in under 2 minutes, but it varies because it appears the standard python data structures have some nondeterminism, and I may have had a lucky draw with my puzzle input.
jjnoakes · a year ago
I have a self-imposed goal of not using third-party libraries for any of the solve logic. It feels more satisfying to do it myself, even if it takes longer.
tialaramex · a year ago
Like Minecraft, everybody should play it however they want, it's just a game.

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.

wjholden · a year ago
What solver are you referring to? I've used z3 and OR-tools, but I find it so difficult to model problems in either one that I seldom get good usage of either one.
JackMorgan · a year ago
All things in moderation! Now if I can just make it through the winter without installing the new Factorio DLC...
mrwww · a year ago
this comment actually prompted me to finally download and install the factorio demo, been hearing so many things about how it takes over lives! :)
Tyr42 · a year ago
I've been playing half an hour each morning before the rest of the family wakes up. Just finally made it to the volcano world
oweiler · a year ago
I will probably solve the first 7 puzzles like every year and then just stop.
rikroots · a year ago
This is my experience. After the first week I develop an intense hatred of all things Elf and start swearing at my laptop. At which point I give up to stop my mental health deteriorating any further.
bmitc · a year ago
One reason I didn't enjoy it was that I felt the days don't build on each other well. So you get little code reuse. It was continually changing requirements, so it was especially like work.
Jtsummers · a year ago
In 2019 he built up about 12 challenges using a VM, for Intcode, you had to construct. It was poorly received because without a working version (developed over the first few Intcode challenges), you couldn't solve the rest of them. He hasn't done anything like that since, though I thought it was probably the more interesting series of challenges.

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.

smrq · a year ago
There's a lot of potential code reuse between years; whether that's good or bad is up to you, I think. (I would personally prefer if my Chinese remainder theorem solving function got less use, but it seems to be called for every year or two.)
brightball · a year ago
We run a private board for Advent of Code for the Carolina Code Conference. Eligibility for prizes starts after earning only 10 of 50 possible stars precisely for this reason.
flanbiscuit · a year ago
Oh cool. I live in WNC and had just missed your last conference in August. Is it possible to join multiple private boards? I usually do one with my coworkers as well
alach11 · a year ago
That's awesome. We do the exact same thing for prize eligibility on my work leaderboard. The whole point is for it to be fun and challenging. No need to grind to the end unless you want to.
ryukoposting · a year ago
Likewise. I did it one year in college and it became a life-consuming thing almost immediately. Not AoC's fault - part of it was depression, part of it was the Minnesota winter. Now that I have a full-time job and a wife, I'm trying to be more careful with those things that I know will suck me in.
globular-toast · a year ago
The year I did it I got lucky and solved them all within a reasonable amount of time until there was one that suddenly involved a lot of nontrivial linear algebra and I immediately spotted that this wouldn't be fun and noped out. Noticed the number of people solving dropped off a cliff on that day.

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

9witz · a year ago
You can also set a time rule. For me it's 45min, if it takes longer to solve it, I an allowed to quit.

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.

anonzzzies · a year ago
I just have them lingering in the back of my brain the whole year. I solved the last one from last year a month ago. This is much nicer than sudokus or whatever: I sometimes dream about them and I keep finding better (in my mind) solutions for ones from years ago. It's lovely when you sit at another dumb crap meeting/standup so you have something to do in your head.
smcl · a year ago
Ah yeah I've been there! Having done it a few years now, I've found that the approach that works for me is: if it starts looking like I'll be stuck on one for more than a few hours, I'll skip it and move on. Otherwise I'll accumulate an insurmountable backlog that becomes more of a depressing chore to think about, than a fun little christmas tradition. I'd rather have a mostly-complete set of problems by the end of the year that I can come back and clean up when I feel like it.

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!

chucksmash · a year ago
My main complaint the last time I did this (2022) was the havoc it wreaked on my sleep schedule. Advent of Code is not kind to East Coast participants.

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.

nja · a year ago
> I can really enjoy the winter break from work

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.

atribecalledqst · a year ago
I get the week between Christmas and New Year's off and then I take a bunch of my PTO in December. It's not an official break or anything.
LandR · a year ago
Developer here. I'm off from 13 Dec to 6 Jan this year.

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.

__loam · a year ago
Lots of people (in tech at least) take time on top of mandatory vacation that can result in like 2 weeks of time.
istjohn · a year ago
Heh, I just checked. That's where I got stuck last year, too. I solved the first half.
danielovichdk · a year ago
Hahaha...I love this comment. I have just been stuck for a week doing edge puzzles and backstepping recursion, keeping myself awake aye night because it bothered me I couldn't "just" solve it.