Clean up Day 22
This commit is contained in:
@@ -24,7 +24,6 @@ fn main() -> Result<()> {
|
|||||||
blocks.sort();
|
blocks.sort();
|
||||||
|
|
||||||
let mut slice = vec![vec![(0, 0); 10]; 10];
|
let mut slice = vec![vec![(0, 0); 10]; 10];
|
||||||
let mut bearing = HashSet::new();
|
|
||||||
let mut support = HashMap::new();
|
let mut support = HashMap::new();
|
||||||
for ([z, x, y], id) in blocks.iter_mut().zip(1..) {
|
for ([z, x, y], id) in blocks.iter_mut().zip(1..) {
|
||||||
let z_max = iproduct!(x.0..=x.1, y.0..=y.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)
|
.map(|(x, y)| slice[x][y].0)
|
||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
if supports.len() == 1 {
|
|
||||||
bearing.insert(*supports.iter().next().unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
support.insert(id, supports);
|
support.insert(id, supports);
|
||||||
|
|
||||||
for (x, y) in iproduct!(x.0..=x.1, y.0..=y.1) {
|
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())]);
|
let mut bearers = HashMap::from([(0, HashSet::new())]);
|
||||||
for id in 1..=blocks.len() {
|
for id in 1..=blocks.len() {
|
||||||
@@ -58,7 +60,7 @@ fn main() -> Result<()> {
|
|||||||
.map(|id| bearers.get(id).unwrap())
|
.map(|id| bearers.get(id).unwrap())
|
||||||
.cloned()
|
.cloned()
|
||||||
.reduce(|a, b| &a & &b)
|
.reduce(|a, b| &a & &b)
|
||||||
.unwrap_or_else(|| HashSet::new());
|
.unwrap_or_else(HashSet::new);
|
||||||
|
|
||||||
b.insert(id);
|
b.insert(id);
|
||||||
bearers.insert(id, b);
|
bearers.insert(id, b);
|
||||||
|
|||||||
Reference in New Issue
Block a user