use std::error::Error; use std::fs::File; use std::io::{self, BufRead}; use std::vec::Vec; fn main() -> Result<(), Box> { let file = File::open("inputs/day3.txt")?; let lines = io::BufReader::new(file).lines(); let trees: Vec> = lines .map(|l| l.unwrap().chars().map(|c| c == '#').collect()) .collect(); let width = trees[0].len(); let height = trees.len(); println!("Map dimensions {} x {}", width, height); let slopes = vec![(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)]; let mut overall = 1u32; for (x_step, y_step) in slopes.iter() { let mut x = 0; let mut y = 0; let mut count = 0; while y < height { if trees[y][x % width] { count += 1 } x += x_step; y += y_step; } println!("Count for {} {} : {}", x_step, y_step, count); overall *= count; } println!("Final result: {}", overall); Ok(()) }