use std::cmp; #[path = "../lib.rs"] mod lib; fn main() { let mut rows: usize = 0; let mut map = vec![]; for line in lib::iter_input() { rows += 1; for c in line.chars() { map.push(match c { '.' => false, '#' => true, _ => unreachable!(), }); } } let cols = map.len() / rows; let mut count1 = 0; let mut count2 = 0; for y in 0..rows { for x in 0..cols { if map[y * cols + x] { for d1 in 1..cmp::min(rows - y, cols - x) { for d2 in 0..cmp::min(rows - y - d1, x + 1) { if map[(y + d2) * cols + (x + d1)] && map[(y + d1 + d2) * cols + (x + d1 - d2)] && map[(y + d1) * cols + (x - d2)] { count2 += 1; if d2 == 0 { count1 += 1; } } } } } } } println!("part1: {}", count1); println!("part2: {}", count2); }