Final changes
This commit is contained in:
parent
cf5d423f50
commit
fc65d53120
|
@ -1,8 +1,7 @@
|
|||
use aoc_runner_derive::{aoc, aoc_generator};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug)]
|
||||
struct Path {
|
||||
steps: usize,
|
||||
path: [Option<DirButton>; 6],
|
||||
}
|
||||
|
||||
|
@ -15,9 +14,8 @@ impl Path {
|
|||
path[i] = Some(buttons[i]);
|
||||
i += 1;
|
||||
}
|
||||
let steps = steps + 1;
|
||||
path[i] = Some(DirButton::A);
|
||||
Some(Self { steps, path })
|
||||
Some(Self { path })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,13 +189,7 @@ impl NumButton {
|
|||
x[i + dx] = Some(by);
|
||||
});
|
||||
x[dx + dy] = Some(DirButton::A);
|
||||
[
|
||||
Some(Path {
|
||||
steps: dx + dy + 1,
|
||||
path: x,
|
||||
}),
|
||||
None,
|
||||
]
|
||||
[Some(Path { path: x }), None]
|
||||
} else if end.0 == 0 && start.1 == 3 {
|
||||
let mut y = [None, None, None, None, None, None];
|
||||
(0..dx).for_each(|i| {
|
||||
|
@ -207,13 +199,7 @@ impl NumButton {
|
|||
y[i] = Some(by);
|
||||
});
|
||||
y[dx + dy] = Some(DirButton::A);
|
||||
[
|
||||
Some(Path {
|
||||
steps: dx + dy + 1,
|
||||
path: y,
|
||||
}),
|
||||
None,
|
||||
]
|
||||
[Some(Path { path: y }), None]
|
||||
} else {
|
||||
let mut x = [None, None, None, None, None, None];
|
||||
let mut y = [None, None, None, None, None, None];
|
||||
|
@ -227,16 +213,7 @@ impl NumButton {
|
|||
});
|
||||
x[dx + dy] = Some(DirButton::A);
|
||||
y[dx + dy] = Some(DirButton::A);
|
||||
[
|
||||
Some(Path {
|
||||
steps: dx + dy + 1,
|
||||
path: x,
|
||||
}),
|
||||
Some(Path {
|
||||
steps: dx + dy + 1,
|
||||
path: y,
|
||||
}),
|
||||
]
|
||||
[Some(Path { path: x }), Some(Path { path: y })]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -309,7 +286,7 @@ fn precompute_steps(steps: &mut [DistanceMatrix]) {
|
|||
});
|
||||
}
|
||||
|
||||
fn shortest_dir_path(path: Path, steps: &mut [DistanceMatrix]) -> DistanceSize {
|
||||
fn shortest_dir_path(path: &Path, steps: &mut [DistanceMatrix]) -> DistanceSize {
|
||||
path.path
|
||||
.iter()
|
||||
.flatten()
|
||||
|
@ -327,7 +304,7 @@ fn shortest_path(path: &[NumButton], steps: &mut [DistanceMatrix]) -> DistanceSi
|
|||
+ acc
|
||||
.1
|
||||
.paths_to(end)
|
||||
.into_iter()
|
||||
.iter()
|
||||
.flatten()
|
||||
.map(|path| shortest_dir_path(path, steps))
|
||||
.fold(DistanceSize::MAX, |acc, next| acc.min(next)),
|
||||
|
|
Loading…
Reference in New Issue