use std::fs; fn parse_contents(contents: String) -> Vec> { let mut map: Vec> = Vec::new(); for line in contents.lines() { map.push(line.chars().collect()); } map } fn count_trees(map: &Vec>) -> i32 { let mut x = 0; let mut y = 0; let mut count = 0; let x_max = map[0].len(); let y_max = map.len(); while y != y_max - 1 { y += 1; x = (x + 3) % x_max; if map[y][x] == '#' { count += 1; } } count } pub fn get_solution() { let contents = fs::read_to_string("data/day03.dat").expect("Could not read data"); let map = parse_contents(contents); let count = count_trees(&map); println!("Day 3, part 1: {}", count); } #[cfg(test)] mod tests { use super::*; #[test] fn part1() { let contents = fs::read_to_string("data/day03_test.dat").expect("Could not read data"); let map = parse_contents(contents); let count = count_trees(&map); assert_eq!(count, 7); } }