Clean up day20
This commit is contained in:
parent
dfa6d05f59
commit
6dc6f04368
@ -24,7 +24,7 @@ impl Direction {
|
|||||||
vec![Up, Left, Down, Right]
|
vec![Up, Left, Down, Right]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn turn_right(&self) -> Self {
|
fn turn(&self) -> Self {
|
||||||
match self {
|
match self {
|
||||||
Up => Right,
|
Up => Right,
|
||||||
Left => Up,
|
Left => Up,
|
||||||
@ -99,33 +99,31 @@ fn get_distances(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn part12(map: &[Vec<Tile>], path: &[IVec2], max_distance: i32) -> usize {
|
fn part12(map: &[Vec<Tile>], path: &[IVec2], max_distance: i32) -> usize {
|
||||||
|
let combinations: Vec<(i32, i32)> = (1..=max_distance)
|
||||||
|
.flat_map(|i| (0..=(max_distance - i)).map(move |j| (i, j)))
|
||||||
|
.collect();
|
||||||
path.par_iter()
|
path.par_iter()
|
||||||
.map(|tile| {
|
.map(|tile| {
|
||||||
Direction::all()
|
Direction::all()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|direction| {
|
.map(|direction| {
|
||||||
(1..=max_distance)
|
combinations
|
||||||
.map(|i| {
|
.iter()
|
||||||
(0..=(max_distance - i))
|
.filter(|(i, j)| {
|
||||||
.filter(|j| {
|
let new_tile_pos =
|
||||||
let new_tile_pos = tile
|
tile + i * direction.to_vec() + j * direction.turn().to_vec();
|
||||||
+ i * direction.to_vec()
|
map.get(new_tile_pos.x as usize)
|
||||||
+ j * direction.turn_right().to_vec();
|
.and_then(|l| l.get(new_tile_pos.y as usize))
|
||||||
map.get(new_tile_pos.x as usize)
|
.map_or(false, |t| {
|
||||||
.and_then(|l| l.get(new_tile_pos.y as usize))
|
t.distance
|
||||||
.map_or(false, |t| {
|
>= map[tile.x as usize][tile.y as usize].distance
|
||||||
!t.tiletype
|
+ 100
|
||||||
&& t.distance
|
+ *i as usize
|
||||||
>= map[tile.x as usize][tile.y as usize]
|
+ *j as usize
|
||||||
.distance
|
&& !t.tiletype
|
||||||
+ 100
|
|
||||||
+ i as usize
|
|
||||||
+ *j as usize
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.count()
|
|
||||||
})
|
})
|
||||||
.sum::<usize>()
|
.count()
|
||||||
})
|
})
|
||||||
.sum::<usize>()
|
.sum::<usize>()
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user