Clean up Day 22

This commit is contained in:
Christian
2023-12-28 13:56:22 +01:00
parent af8413cba8
commit ce80483f96

View File

@@ -24,7 +24,6 @@ fn main() -> Result<()> {
blocks.sort();
let mut slice = vec![vec![(0, 0); 10]; 10];
let mut bearing = HashSet::new();
let mut support = HashMap::new();
for ([z, x, y], id) in blocks.iter_mut().zip(1..) {
let z_max = iproduct!(x.0..=x.1, y.0..=y.1)
@@ -37,10 +36,6 @@ fn main() -> Result<()> {
.map(|(x, y)| slice[x][y].0)
.collect::<HashSet<_>>();
if supports.len() == 1 {
bearing.insert(*supports.iter().next().unwrap());
}
support.insert(id, supports);
for (x, y) in iproduct!(x.0..=x.1, y.0..=y.1) {
@@ -49,7 +44,14 @@ fn main() -> Result<()> {
}
}
let part1 = blocks.len() - bearing.len() + 1;
let bearing_count = support
.values()
.filter(|supports| supports.len() == 1)
.filter_map(|supports| supports.iter().next())
.unique()
.count();
let part1 = blocks.len() - bearing_count + 1;
let mut bearers = HashMap::from([(0, HashSet::new())]);
for id in 1..=blocks.len() {
@@ -58,7 +60,7 @@ fn main() -> Result<()> {
.map(|id| bearers.get(id).unwrap())
.cloned()
.reduce(|a, b| &a & &b)
.unwrap_or_else(|| HashSet::new());
.unwrap_or_else(HashSet::new);
b.insert(id);
bearers.insert(id, b);