From 498151008fea96efc07754e13674a14f80ade0ef Mon Sep 17 00:00:00 2001 From: Mathis Date: Mon, 25 Dec 2023 01:02:36 +0100 Subject: [PATCH] 2023-17: Add down dir to start cost --- src/year_2023/day_17_clumsy_crucible/part_one.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/year_2023/day_17_clumsy_crucible/part_one.rs b/src/year_2023/day_17_clumsy_crucible/part_one.rs index caaec58..5b45965 100644 --- a/src/year_2023/day_17_clumsy_crucible/part_one.rs +++ b/src/year_2023/day_17_clumsy_crucible/part_one.rs @@ -14,9 +14,12 @@ pub fn part_one(input_lines: Vec) -> String { } let mut cache: HashMap<(i32, i32), i32> = HashMap::new(); - let current_path: HashSet<(i32, i32)> = HashSet::new(); - let cost = min_cost_path(&map, &mut cache, current_path, Direction::Right, 0, 0, 0) - map[0][0]; + let cost = min( + min_cost_path(&map, &mut cache, HashSet::new(), Direction::Right, 0, 0, 0), + min_cost_path(&map, &mut cache, HashSet::new(), Direction::Down, 0, 0, 0), + i32::MAX, + ); cost.to_string() } @@ -29,7 +32,7 @@ fn min_cost_path( i: i32, j: i32) -> i32 { - // println!("{}: {} {} {:?}", step_count, i, j, dir); + println!("{}: {} {} {:?}", step_count, i, j, dir); if i < 0 || j < 0 || i >= map.len() as i32 || j >= map[0].len() as i32 { return i32::MAX; @@ -54,7 +57,10 @@ fn min_cost_path( return *cache.get(&(i,j)).unwrap(); } - let mut cost = map[i as usize][j as usize]; + let mut cost = 0; + if i != 0 && j != 0 { + cost = map[i as usize][j as usize]; + } let res: i32; match dir {