use std::io::{self, BufRead}; use std::path::Path; use std::fs::File; fn main(){ println!("Advent of Code #1!"); println!(); let path = Path::new("./1.txt"); let display = path.display(); let file = match File::open(&path) { Err(why) => panic!("Couldn't open {}: {}", display, why), Ok(file) => file, }; let lines = io::BufReader::new(file).lines(); let mut n = 0; let mut prev = 0; let mut line_vec = Vec::new(); for line in lines { if let Ok(l) = line{ let i: u32 = l.parse().unwrap(); if i > prev { n += 1; } prev = i; line_vec.push(i); } } println!("Number of increases: {}", n - 1); println!(); prev = 0; n = 0; for i in 0..(line_vec.len() - 2) { let sum = line_vec[i] + line_vec[i+1] + line_vec[i+2]; if sum > prev { n += 1; } prev = sum; } println!("Number of increases with shifting window: {}", n - 1); }