Skip to content

Commit

Permalink
Add solution for 2023 day08
Browse files Browse the repository at this point in the history
  • Loading branch information
Daedrus committed Dec 9, 2023
1 parent 25ba276 commit c1bbe9a
Show file tree
Hide file tree
Showing 9 changed files with 1,053 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 2023/day08_haunted_wasteland/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "day08_haunted_wasteland"
version = "0.1.0"
edition = "2021"
rust-version.workspace = true

[dependencies]
log.workspace = true
env_logger.workspace = true
nom.workspace = true
num.workspace = true
25 changes: 25 additions & 0 deletions 2023/day08_haunted_wasteland/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Very cheeky part 2. I basically winged it after seeing the example and
thinking that "surely that's the least common multiple". I looked at the input
and saw that the paths cycle (aka the end node cycles back to the start node)
and then I just prayged that the cycles are "clean". It worked, but solution
would definitely break on an input that's not this constrained.

---

Being able to pass functions as arguments leads to some really nice code since
you can code what an end node is through a:
```
is_end_node: fn(&str) -> bool,
```
And use that as a break condition for the traversal.

---

Imported a new crate called `num` for the `lcm` implementation. I had not
pulled in a new crate in a very long time.

---

To have an iterator go back to the start when it reaches the end one can use
the `cycle` function. I am surprised I have not used this before. It made it
very easy to cycle through the instructions endlessly.
Loading

0 comments on commit c1bbe9a

Please sign in to comment.