Skip to content

alex-schaaf/adventofcode2024

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

advent of code 2024

🎄 This year I'm starting out with using it to learn Rust from scratch, so let's see how long it takes until I switch back to trusted old Python.

  1. Solution. An easy start this year, which gave me a good opportunity to learn about Vec and HashMap data structures in Rust. I really like the Option<T> enum approach to handling optional values.
  2. Solution. This one made me learn about cloning vectors, how to turn vectors into iterators, and anonymous functions. I got a bit stuck at first, as I was including 0 as an acceptable value when checking for the gradient monotony. Luckily writing some tests for my gradient monotony function got me to figure that out quickly!
    • Learnt about the Vec::windows method, that returns an iterator over a window of given size. So you can just .map over it using an anonymous diff function to calculate the gradient array.
  3. Solution. Simple regex parsing. This time I learned more about how to implement functions that return an Option<T>. Combined with the ? shorthand for propagating errors, this makes for really nice happy-path coding without the verbosity that you see in Go code.
  4. Solution. Nice! I liked that I could just use the count of a given page number in the valid rulesets to determine the ordering! At first I thought I'd need to iterate a lot more.
  5. Solution. Had fun over-engineering this by implementing a Vec2d struct, that represents a 2D vector as a 1D vector. First time I did OOP in Rust, so lots of things to learn here. Haven't started on Part 2 yet, though.
  6. Solution. I got a bit annoyed here with Rust, as creating the cartesian product of operators felt like an unneccessary hassle to get Rust to do what I wanted it to do. A stark contrast to Python's itertools. Also first time in my life I had to deal with an integer overflow, because I was using first i32 for the calculations, but it required i64. Thankfully Rust just tells you that when trying to parse a stringified number.

About

My solutions to the 2024 Advent of Code 🎄

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages