fn main() { let input = lib::read_input(8); part1(&input); part2(&input); } fn part1(input: &str) { let input = input.split_whitespace().map(|x| x.bytes().collect::>()).collect::>(); let mut ans = 0; for (y, line) in input.iter().enumerate() { for (x, c) in line.iter().enumerate() { if visible(&input, x, y) { ans += 1; } } } println!("{}", ans); } fn part2(input: &str) { } fn visible(heights: &[Vec], x: usize, y: usize) -> bool { for (dy, dx) in &[(0, 1), (0, -1), (1, 0), (-1, 0)] { let height = heights[y][x]; let mut sx = x as i32; let mut sy = y as i32; loop { sx += dx; sy += dy; if sx < 0 || sy < 0 || sx >= heights[0].len() as i32 || sy >= heights.len() as i32 { return true; } if heights[sy as usize][sx as usize] >= height { break; } } } return false; }