mirror of
https://github.com/Smaug123/advent-of-code-2021
synced 2025-10-07 04:58:40 +00:00
Faster algorithm
This commit is contained in:
@@ -27,9 +27,20 @@ pub mod day_1 {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn part_2(numbers: &[u32]) -> u32 {
|
||||
pub fn part_2_naive(numbers: &[u32]) -> u32 {
|
||||
part_1(&mut numbers.windows(3).map(|x| x[0] + x[1] + x[2]))
|
||||
}
|
||||
|
||||
pub fn part_2(numbers: &[u32]) -> u32 {
|
||||
let mut count = 0;
|
||||
for i in 0..numbers.len() - 3 {
|
||||
if numbers[i] < numbers[i + 3] {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
count
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Reference in New Issue
Block a user