diff --git a/Cargo.toml b/Cargo.toml index 39ad3e1..fab1a53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "advent_of_code" version = "0.9.3" authors = ["Felix Spöttel <1682504+fspoettel@users.noreply.github.com>", "Hans Baker"] -edition = "2023" +edition = "2021" default-run = "advent_of_code" publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/bin/22.rs b/src/bin/22.rs index ec04cfc..c4d0f11 100644 --- a/src/bin/22.rs +++ b/src/bin/22.rs @@ -97,8 +97,8 @@ impl Block { fn lower_to(&mut self, new_z: usize) { let diff = self.lowest_z() - new_z; - self.start.z = self.start.z - diff; - self.end.z = self.end.z - diff; + self.start.z -= diff; + self.end.z -= diff; } } @@ -131,7 +131,7 @@ fn drop_floating_blocks(blocks: Vec) -> (Vec, Vec>) { let mut max = highest_possible; blocks.iter_mut().for_each(|b| { if b.lowest_z() == 1 { - tops[b.highest_z()].push(b.clone()); + tops[b.highest_z()].push(*b); } else { let mut indices = (1..b.lowest_z()).rev(); let new_z = loop { @@ -144,7 +144,7 @@ fn drop_floating_blocks(blocks: Vec) -> (Vec, Vec>) { } }; b.lower_to(new_z); - tops[b.highest_z()].push(b.clone()); + tops[b.highest_z()].push(*b); max = b.highest_z(); } }); @@ -158,7 +158,7 @@ struct BlockNode { parents: Vec, } -fn build_tree(supports: Vec>) -> (HashMap) { +fn build_tree(supports: Vec>) -> HashMap { let mut map: HashMap = HashMap::new(); supports.iter().flatten().for_each(|block| { let bottom = block.lowest_z(); @@ -200,18 +200,11 @@ pub fn part_one(input: &str) -> Option { let count = tree .values() .filter(|node| { - if node.children.len() == 0 { - true - } else { - if node.children.iter().all(|child| { + node.children.is_empty() + || node.children.iter().all(|child| { let child_node = tree.get(child).unwrap(); child_node.parents.len() > 1 - }) { - true - } else { - false - } - } + }) }) .count(); Some(count as u64)