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.
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_...
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.
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_...
https://github.com/dzaima/aoc/blob/master/2024/BQN/1_fast.bq...
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.
/s
But regardless of this, the name of the Go programming language is "Go" and not "Golang".
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'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.