26 lines
646 B
Rust
26 lines
646 B
Rust
fn parse_input(input: &str) -> Vec<i32> {
|
|
input.lines().filter_map(|n| n.parse::<i32>().ok()).collect()
|
|
}
|
|
|
|
fn count_up(input: Vec<i32>) -> usize {
|
|
input.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::*;
|
|
|
|
#[test]
|
|
fn part_1() {
|
|
println!("Part 1 Solution: {}", count_up(parse_input(include_str!("../input/day01.txt"))));
|
|
}
|
|
|
|
#[test]
|
|
fn part_2() {
|
|
println!("Part 2 Solution: {}", count_up(denoise(parse_input(include_str!("../input/day01.txt")))));
|
|
}
|
|
} |