See https://adventofcode.com/2022
-
Day 1. Ah, it's not that hard! :)
-
Day 2. First went all
enum Shape
andimpl FromStr
andshape.score()
etc., but then later figured that for a script, simpleconst
s make for way simpler and readable code :)- Learned: don't always need
enum/impl
- Learned: don't always need
-
Day 3. Note the funny
'a'..'{'
— I later learned the syntax'a'..='z'
from Auke's solution :P- Learned:
..=
code - ('a' as i32)
- Learned:
-
Day 4. I decided to go with an actual separate parser, figuring parsing the input of subsequent days would probably get harder and harder. A bit unnecessary here ofc. Also, how did I not know about
fs::read_to_string
in previous days? :P- Learned:
fs::read_to_string
- Learned:
-
Day 5. The first significantly harder day! Not because of the parsing though (regexes work just fine), but because of data & ownership stuff I guess.
-
Day 6. Surprisingly simple, too bad! :P
-
Day 7. Harder again.
- First I had an
enum Item { Folder, File }
, but then I had to write so manymatch
blocks, even if using common data (likename
), that I went for a more pragmaticstruct Node
with some redundancy. And then it was just a bit finnicky to get it all right. - Went immediately for a flat data structure w/ userland indirection instead of a recursive data structure, because I know that ownership gets really complicated otherwise — probably saved me quite some time.
- For simplicity, I made
compute_folder_size
accumulate the folder sizes through a&mut Vec<usize>
instead of trying to merge resulting vectors. => Q: is this the Rust way?
- First I had an