day 6 part 2 Use rotate_left
This commit is contained in:
parent
6acaaf8b7a
commit
60b77d5d3d
@ -88,16 +88,10 @@ fn part2(input: &str) -> Result<usize> {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.for_each(|n| counts[n] += 1);
|
.for_each(|n| counts[n] += 1);
|
||||||
for _ in 0..256 {
|
for _ in 0..256 {
|
||||||
let mut tmp = [0; 9];
|
let ready = counts[0];
|
||||||
for i in 0..9 {
|
counts.rotate_left(1);
|
||||||
if i == 0 {
|
counts[6] += ready;
|
||||||
tmp[6] += counts[0];
|
counts[8] = ready;
|
||||||
tmp[8] += counts[0];
|
|
||||||
} else {
|
|
||||||
tmp[i - 1] += counts[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
counts = tmp;
|
|
||||||
}
|
}
|
||||||
Ok(counts.iter().sum())
|
Ok(counts.iter().sum())
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user