Advent of Code 2022, using Rust

See https://adventofcode.com/2022

Diary

  • Day 1. Ah, it's not that hard! :)

  • Day 2. First went all enum Shape and impl FromStr and shape.score() etc., but then later figured that for a script, simple consts make for way simpler and readable code :)

    • Learned: don't always need enum/impl
  • Day 3. Note the funny 'a'..'{' — I later learned the syntax 'a'..='z' from Auke's solution :P

    • Learned:
      • ..=
      • code - ('a' as i32)
  • 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
  • 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 many match blocks, even if using common data (like name), that I went for a more pragmatic struct 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?