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