streamline day1
This commit is contained in:
parent
bf9a293136
commit
78f3b7cf23
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
fn parse_input(input: &str) -> Vec<i32> {
|
fn parse_input(input: &str) -> Vec<i32> {
|
||||||
input.lines().filter_map(|n| n.parse::<i32>().ok()).collect()
|
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()
|
input.windows(2).filter(|w| w[1]> w[0] ).count()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn count_up_window(input: Vec<i32>) -> usize {
|
fn denoise(input: Vec<i32>) -> Vec<i32> {
|
||||||
input.windows(3).map(|w| w.iter().sum()).collect::<Vec<i32>>().windows(2).filter(|w| w[1] > w[0]).count()
|
input.windows(3).map(|w| w.iter().sum()).collect::<Vec<i32>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -23,6 +21,6 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn part_2() {
|
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")))));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue