pub fn main() { let txt = std::fs::read_to_string("./input/day11.txt").unwrap(); let input = txt .lines() .map(|s| s.chars().collect::>()) .collect::>(); let mut coords = vec![]; let mut off_y = 0; for i in 0..input.len() { if !input[i].contains(&'#') { off_y += 1000000 - 1; continue; } let mut off_x = 0; for j in 0..input[i].len() { if !input .clone() .into_iter() .map(|s| s[j]) .collect::>() .contains(&'#') { off_x += 1000000 - 1; continue; } if input[i][j] == '#' { coords.push(((j + off_x) as isize, (i + off_y) as isize)); } } } let mut sum: u64 = 0; for coord1 in &coords { for coord2 in &coords { if coord1 != coord2 { sum += ((coord1.0 - coord2.0).abs() + (coord1.1 - coord2.1).abs()) as u64; } } } println!("{}", sum / 2); }