Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
BakerNet committed Dec 22, 2023
1 parent 20bedfc commit 242f13a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "advent_of_code"
version = "0.9.3"
authors = ["Felix Spöttel <[email protected]>", "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
Expand Down
23 changes: 8 additions & 15 deletions src/bin/22.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -131,7 +131,7 @@ fn drop_floating_blocks(blocks: Vec<Block>) -> (Vec<Block>, Vec<Vec<Block>>) {
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 {
Expand All @@ -144,7 +144,7 @@ fn drop_floating_blocks(blocks: Vec<Block>) -> (Vec<Block>, Vec<Vec<Block>>) {
}
};
b.lower_to(new_z);
tops[b.highest_z()].push(b.clone());
tops[b.highest_z()].push(*b);
max = b.highest_z();
}
});
Expand All @@ -158,7 +158,7 @@ struct BlockNode {
parents: Vec<usize>,
}

fn build_tree(supports: Vec<Vec<Block>>) -> (HashMap<usize, BlockNode>) {
fn build_tree(supports: Vec<Vec<Block>>) -> HashMap<usize, BlockNode> {
let mut map: HashMap<usize, BlockNode> = HashMap::new();
supports.iter().flatten().for_each(|block| {
let bottom = block.lowest_z();
Expand Down Expand Up @@ -200,18 +200,11 @@ pub fn part_one(input: &str) -> Option<u64> {
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)
Expand Down

0 comments on commit 242f13a

Please sign in to comment.