aboutsummaryrefslogtreecommitdiff
path: root/src/day11pt2.rs
diff options
context:
space:
mode:
authorAleksa Vuckovic <aleksa@vuckovic.cc>2023-12-15 00:57:58 +0100
committerAleksa Vuckovic <aleksa@vuckovic.cc>2023-12-15 00:57:58 +0100
commitb987ec6481ea40e257dc81a8b3ebfc5f0483afe5 (patch)
tree230b8fdd76ae89dc8ab9142d68a5bb7047d9b143 /src/day11pt2.rs
parent261fccb18f48f5a058e8d5487cab252b4727ba36 (diff)
day10 & day11
Diffstat (limited to 'src/day11pt2.rs')
-rw-r--r--src/day11pt2.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/day11pt2.rs b/src/day11pt2.rs
new file mode 100644
index 0000000..87d80b7
--- /dev/null
+++ b/src/day11pt2.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 += 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);
+}