streamline day1

This commit is contained in:
Dan Ballard 2021-12-04 01:15:28 -08:00
parent bf9a293136
commit 78f3b7cf23
1 changed files with 3 additions and 5 deletions

View File

@ -1,4 +1,3 @@
fn parse_input(input: &str) -> Vec<i32> {
input.lines().filter_map(|n| n.parse::<i32>().ok()).collect()
}
@ -7,11 +6,10 @@ fn count_up(input: Vec<i32>) -> usize {
input.windows(2).filter(|w| w[1]> w[0] ).count()
}
fn count_up_window(input: Vec<i32>) -> usize {
input.windows(3).map(|w| w.iter().sum()).collect::<Vec<i32>>().windows(2).filter(|w| w[1] > w[0]).count()
fn denoise(input: Vec<i32>) -> Vec<i32> {
input.windows(3).map(|w| w.iter().sum()).collect::<Vec<i32>>()
}
#[cfg(test)]
mod tests {
use super::*;
@ -23,6 +21,6 @@ mod tests {
#[test]
fn part_2() {
println!("Part 2 Solution: {}", count_up_window(parse_input(include_str!("../input/day01.txt"))));
println!("Part 2 Solution: {}", count_up(denoise(parse_input(include_str!("../input/day01.txt")))));
}
}