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