2023-17: Add down dir to start cost

This commit is contained in:
Mathis 2023-12-25 01:02:36 +01:00
parent 1f901849d6
commit 498151008f
1 changed files with 10 additions and 4 deletions

View File

@ -14,9 +14,12 @@ pub fn part_one(input_lines: Vec<String>) -> 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 {