Browse Source

streamline day1

main
Dan Ballard 6 months ago
parent
commit
78f3b7cf23
  1. 8
      src/day01.rs

8
src/day01.rs

@ -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")))));
}
}
Loading…
Cancel
Save