blob: 87d80b7aba352f6b9a0fd06f77bbdc8842825b4f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 += 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::<Vec<char>>()
.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);
}
|