Use .retain().
This commit is contained in:
parent
639fe1a3b8
commit
2e0eab1c03
|
@ -64,10 +64,8 @@ fn part_2(input: &str) -> Result<String> {
|
||||||
.get(index)
|
.get(index)
|
||||||
.ok_or_else(|| eyre!("Could not find most common bit"))?;
|
.ok_or_else(|| eyre!("Could not find most common bit"))?;
|
||||||
let most_common = if bit >= &0 { '1' } else { '0' };
|
let most_common = if bit >= &0 { '1' } else { '0' };
|
||||||
most_common_lines = most_common_lines
|
most_common_lines
|
||||||
.into_iter()
|
.retain(|line| line.chars().nth(*index) == Some(most_common));
|
||||||
.filter(|line| line.chars().nth(*index) == Some(most_common))
|
|
||||||
.collect();
|
|
||||||
most_common_bits = count_bits(&most_common_lines.join("\n"))?;
|
most_common_bits = count_bits(&most_common_lines.join("\n"))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,10 +74,8 @@ fn part_2(input: &str) -> Result<String> {
|
||||||
.get(index)
|
.get(index)
|
||||||
.ok_or_else(|| eyre!("Could not find least common bit"))?;
|
.ok_or_else(|| eyre!("Could not find least common bit"))?;
|
||||||
let least_common = if bit < &0 { '1' } else { '0' };
|
let least_common = if bit < &0 { '1' } else { '0' };
|
||||||
least_common_lines = least_common_lines
|
least_common_lines
|
||||||
.into_iter()
|
.retain(|line| line.chars().nth(*index) == Some(least_common));
|
||||||
.filter(|line| line.chars().nth(*index) == Some(least_common))
|
|
||||||
.collect();
|
|
||||||
least_common_bits = count_bits(&least_common_lines.join("\n"))?;
|
least_common_bits = count_bits(&least_common_lines.join("\n"))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,11 +43,7 @@ impl Bingo {
|
||||||
return (self.boards.first().unwrap().clone(), number);
|
return (self.boards.first().unwrap().clone(), number);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.boards = self
|
self.boards.retain(|board| !board.has_won);
|
||||||
.boards
|
|
||||||
.into_iter()
|
|
||||||
.filter(|board| !board.has_won)
|
|
||||||
.collect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
|
Loading…
Reference in New Issue