diff options
Diffstat (limited to 'src/day11pt1.rs')
| -rw-r--r-- | src/day11pt1.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/day11pt1.rs b/src/day11pt1.rs new file mode 100644 index 0000000..5f1eb67 --- /dev/null +++ b/src/day11pt1.rs @@ -0,0 +1,45 @@ +pub fn main() { + let txt = std::fs::read_to_string("./input/day11.txt").unwrap(); + let input = txt + .lines() + .map(|s| s.chars().collect::<Vec<char>>()) + .collect::<Vec<_>>(); + + let mut coords = vec![]; + + let mut off_y = 0; + for i in 0..input.len() { + if !input[i].contains(&'#') { + off_y += 1; + continue; + } + + let mut off_x = 0; + for j in 0..input[i].len() { + if !input + .clone() + .into_iter() + .map(|s| s[j]) + .collect::<Vec<char>>() + .contains(&'#') + { + off_x += 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); +} |
