pub fn parse_to_floor(input: &str) -> Vec> { let mut rows: Vec> = Vec::with_capacity(input.len() + 2); rows.push(vec![0u8; input.len()]); rows.append( &mut input .lines() .map(|line| { let mut col: Vec = Vec::with_capacity(line.len() + 2); col.push(0u8); col.append( &mut line .chars() .map(|c| match c { '@' => 1u8, _ => 0u8, }) .collect(), ); col.push(0u8); col }) .collect(), ); rows.push(vec![0u8; input.len()]); rows } pub fn remove_if_possible(floor: &mut Vec>) -> Option { let mut removed: Vec<(usize, usize)> = Vec::new(); floor .windows(3) .enumerate() .for_each(|(r, rows)| { rows[0] .iter() .zip(rows[1].iter()) .zip(rows[2].iter()) .map(|((a, b), c)| (a, b, c)) .collect::>() .windows(3) .enumerate() .for_each(|(c, cols)| { if cols[1].1 == &0u8 { return; } if cols.iter().map(|(a, b, c)| *a + *b + *c).sum::() - 1 < 4 { removed.push((r+1, c+1)); } }); }); removed.iter().for_each(|(r, c)| { floor[*r][*c] = 0; }); if removed.len() == 0 { return None; } Some(removed.len() as u64) }