main.rs (582B)
1 fn main() { 2 let input = std::fs::read_to_string("input.txt") 3 .unwrap() 4 .trim() 5 .split('\n') 6 .map(|x| x.parse().unwrap()) 7 .collect::<Vec<i32>>(); 8 // 1226 9 println!("Part 1: {}", part_1(&input)); 10 // 1252 11 println!("Part 2: {}", part_2(&input, 3)); 12 } 13 14 fn part_1(input: &Vec<i32>) -> i32 { 15 (1..input.len()).fold(0, |acc, i| acc + (input[i] > input[i - 1]) as i32) 16 } 17 18 fn part_2(input: &Vec<i32>, window_size: usize) -> i32 { 19 (window_size..input.len()).fold(0, |acc, i| acc + (input[i] > input[i - window_size]) as i32) 20 }