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