Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



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.


Interested by your rust speed approaches, care to share a link ?


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


There's a Rust solution posted in the Reddit Day 1 answers mega thread which claims 22 microseconds part 1 and 10 microseconds part 2. (I haven't tried to verify):

https://old.reddit.com/r/adventofcode/comments/1h3vp6n/2024_...


Can't edit my comment, here's another claiming 12.7 μs and 7 μs:

https://old.reddit.com/r/adventofcode/comments/1h3vp6n/2024_...

Another claiming 30μs and 32μs:

https://old.reddit.com/r/adventofcode/comments/1h3vp6n/2024_...


For an interesting comparison, here's BQN, an array language, at 25.5μs (on an i3-4160) for both parts, including input parsing:

https://github.com/dzaima/aoc/blob/master/2024/BQN/1_fast.bq...


That's very impressive.


Sure but how long did it take to compile


I 'git clone' and 'cargo run' and it downloaded 16 crates and compiled all the crates and built a debug version in 29.7 seconds.

Then 'cargo build --release' took 23.3 seconds.

Commenting out one of the sort_unstable lines and rebuilding gave me a warning, recompiled in 1.8 seconds.


I do AoC first time and use it to try a functional LISP like language (Clojure).

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.


It takes a while. But if you continue to practice, it will eventually click.


Are the timings with language runtime startup, or only the procedure calls of the actual code?


Just the individual part1 and part2 functions. At least on the Clojure side, I made the runner. For the rust side I’m not sure I’m using a template project that does that containment.


'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


This server seems to be active, although they are all unofficial servers from enthusiasts.

https://discord.gg/wYmyYsf


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.


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.


To be fair, Go was never a proper "systems language" (and shamefully attempted to redefine what the term means).


I don't think it attempted to redefine the term, but "web" was left off the beginning of the phrase. Go's primary strength is in creating distributed, concurrent services and other networked systems. This makes sense as a language born within Google, though like any language it can be used for other purposes.


Let's try to settle the Go/Rust debate in this AoC sub-thread ^_^


Let's mix in some tabs/spaces and vim/emacs too, and we've got a stew going!


Personally I like them both but I find the barrier to onboarding new devs is lower for Golang.

/s



What's Go, if not Golang? I mean, there's some other programming language called Go that I don't know about?


Yes, "Go!" came before "Go".

But regardless of this, the name of the Go programming language is "Go" and not "Golang".


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


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.


Looks pretty neat I'll take some inspiration from this.

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.

[0]: https://adventofcode.com/2024/about


I'm usually a rule follower, but this is a rule that I choose not to follow. I have a couple of reasons:

- I've spent effort on this, and I want the repository to work in future. I want to be able to clone it and run all the code without having to fetch the input once more, even if the site is unavailable. (I actually do this while benchmarking new hardware).

- I don't think it actually hurts the creator in any way, in my opinion. Here's an example: At least 660 people have uploaded inputs from 2022 (https://github.com/search?q=%22closest+beacon+is+at+x%22+pat...). These files have been up for 2 years. Exactly what injury has the creator suffered because of this? Are there people out there thinking "nah, it's too much effort to log into adventofcode.com, I'll just trawl GitHub repos for inputs and figure out what I'm supposed to do from there"? Obviously not.

So I have a compelling interest, and the creator hasn't articulated a good reason to avoid it. If he's able to articulate a good reason, then I'm willing to reassess my stance on this. He has my sympathy and full support if someone creates a lookalike site with the same puzzles and inputs but different CSS and without ads. That would be messed up. The potential injury is clear - he'd be losing users to the lookalike.

This is a subject of some controversy in the AOC community, but nothing I've read in those threads so far has been compelling. Anti-storage arguments usually just come down to "he's asking nicely so please comply". To which I politely respond that I don't accede to every polite request that comes my way.


I use a private submodule (hosted on my own infra) for the inputs, which addresses point 1. But I get where you're coming from.


That's smart! I'll probably do this too when I'll publish my AoC code


Is there a discord every year? Interested in joining that if you don’t mind sharing


Sounds like a very interesting Discord to check :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: