Skip to content

Commit

Permalink
refactor(2023): simplify day 8 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
believer committed Dec 8, 2023
1 parent 7fbc1f8 commit 0a0dedb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions rust/2023/src/day_08.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ assert_eq!(solve_part_01(&input_generator(data)), 22411);
```"#]
#[aoc(day8, part1)]
pub fn solve_part_01(input: &Input) -> u64 {
let Input {
directions,
instructions,
} = input;
let mut steps = 0;
let mut location = "AAA".to_string();

while location != "ZZZ" {
for char in &input.directions {
location = match char {
Direction::Right => input.instructions.get(&location).unwrap().1.to_string(),
Direction::Left => input.instructions.get(&location).unwrap().0.to_string(),
for direction in directions {
let (left, right) = instructions.get(&location).unwrap();

location = match direction {
Direction::Right => right.to_string(),
Direction::Left => left.to_string(),
};

steps += 1;
Expand Down

0 comments on commit 0a0dedb

Please sign in to comment.