cargo fmt

This commit is contained in:
Glenn Griffin 2020-12-18 16:08:29 -08:00
parent 9e2e317f8d
commit 40b618593f

View File

@ -5,9 +5,13 @@ use std::collections::HashSet;
fn solve_d17_p1(input: &str) -> usize { fn solve_d17_p1(input: &str) -> usize {
let mut world = HashSet::new(); let mut world = HashSet::new();
for (y, line) in input.split('\n').enumerate() { for (y, line) in input.split('\n').enumerate() {
for (x, _) in line.as_bytes().iter().copied().enumerate().filter(|&(_, byte)| { for (x, _) in line
byte == b'#' .as_bytes()
}) { .iter()
.copied()
.enumerate()
.filter(|&(_, byte)| byte == b'#')
{
world.insert((x as isize, y as isize, 0isize, 0isize)); world.insert((x as isize, y as isize, 0isize, 0isize));
} }
} }
@ -17,7 +21,10 @@ fn solve_d17_p1(input: &str) -> usize {
world.len() world.len()
} }
fn neighbors(world: &HashSet<(isize, isize, isize, isize)>, (x, y, z, w): (isize, isize, isize, isize)) -> usize { fn neighbors(
world: &HashSet<(isize, isize, isize, isize)>,
(x, y, z, w): (isize, isize, isize, isize),
) -> usize {
let mut count = 0; let mut count = 0;
for xa in x - 1..=x + 1 { for xa in x - 1..=x + 1 {
for ya in y - 1..=y + 1 { for ya in y - 1..=y + 1 {
@ -43,8 +50,16 @@ fn step(world: HashSet<(isize, isize, isize, isize)>) -> HashSet<(isize, isize,
w_max: isize, w_max: isize,
} }
let MinMax { let MinMax {
x_min, x_max, y_min, y_max, z_min, z_max, w_min, w_max, x_min,
} = world.iter().fold(MinMax{ x_max,
y_min,
y_max,
z_min,
z_max,
w_min,
w_max,
} = world.iter().fold(
MinMax {
x_min: isize::MAX, x_min: isize::MAX,
x_max: isize::MIN, x_max: isize::MIN,
y_min: isize::MAX, y_min: isize::MAX,
@ -53,8 +68,8 @@ fn step(world: HashSet<(isize, isize, isize, isize)>) -> HashSet<(isize, isize,
z_max: isize::MIN, z_max: isize::MIN,
w_min: isize::MAX, w_min: isize::MAX,
w_max: isize::MIN, w_max: isize::MIN,
}, |minmax, &(x, y, z, w)| { },
MinMax{ |minmax, &(x, y, z, w)| MinMax {
x_min: std::cmp::min(minmax.x_min, x), x_min: std::cmp::min(minmax.x_min, x),
x_max: std::cmp::max(minmax.x_max, x), x_max: std::cmp::max(minmax.x_max, x),
y_min: std::cmp::min(minmax.y_min, y), y_min: std::cmp::min(minmax.y_min, y),
@ -63,8 +78,8 @@ fn step(world: HashSet<(isize, isize, isize, isize)>) -> HashSet<(isize, isize,
z_max: std::cmp::max(minmax.z_max, z), z_max: std::cmp::max(minmax.z_max, z),
w_min: std::cmp::min(minmax.w_min, w), w_min: std::cmp::min(minmax.w_min, w),
w_max: std::cmp::max(minmax.w_max, w), w_max: std::cmp::max(minmax.w_max, w),
} },
}); );
let mut new_world = HashSet::new(); let mut new_world = HashSet::new();
for x in x_min - 1..=x_max + 1 { for x in x_min - 1..=x_max + 1 {
for y in y_min - 1..=y_max + 1 { for y in y_min - 1..=y_max + 1 {
@ -84,5 +99,3 @@ fn step(world: HashSet<(isize, isize, isize, isize)>) -> HashSet<(isize, isize,
} }
new_world new_world
} }