day11 part2

This commit is contained in:
Andrew Glaze 2023-12-13 16:01:37 -05:00
parent 8a40f62cf6
commit 78aab8ab5e
2 changed files with 228 additions and 32 deletions

View File

@ -1,10 +1,140 @@
...#...... .......#.....#.....................#.............#.................#.........................#..............................................
.......#.. #.....................#.......#.................................................................................#.......#...................
#......... .......................................................................#.........................#..................................#.......
.......... ................................................................#..............#..............................................#.............
......#... .........................................#............................................................#....................................#
.#........ .................#..................................................#.......................................................................
.........# ...........................#...............................................................................#................................
.......... ....#.......#...........................................#..........................#.............................#..........................
.......#.. ....................#.............#........#................................................................................................
#...#..... ...................................................#...................................................#...................#................
.........................#........................................#..................................................#......................
......#..........#...........................................#...........#............#.....................................................
......................................#..........................................#.........................#.....................#..........
.#...................#..................................#.......................................#...........................................
............#.................................#.....................#.......................................................................
............................................................................................................................................
..............................#.....................................................................................#..................#....
....................................................................................#........#......#.......................................
.........................#.........................#............#...........................................#...............................
.#......#.....#.......................#.................#........................................................#.....#....................
...........................................................................#.................................................#..............
...............................................#.......................................#...............#..........................#.........
......................#..................#..................................................................................................
..........................................................................................................................#.................
......#...........................#.........................................................#........................#......................
..............................................................................................................................#.............
..#.......................#.................#............................................................................................#..
..................#....................................................#................#...................................................
....................................................#.....#....................#............................................................
...............................#............................................................................................................
..............................................#...............#..........................................................#...........#......
.#.........#........................#..................................................................#....................................
..........................................................................#.......................#........................................#
...................#......................................................................#.................................................
.............................................................................................................................#..............
.....#......................................................................................................................................
........................................................#........................#..........................................................
.............................#...............#.....................#.....#............#..................#..............................#...
............................................................................................#......#...........#............................
.........................#........#...................................................................................#.....................
...........................................................................................................................................#
.....................................................#.....#.................................................................#..............
#.........................................................................................................#.......................#.........
................#...........................................................#.....................#.........................................
..............................#..............#...................................#.......#...........................#......................
........#................#.........#............................#............................................#.............#.........#......
............................................................................................................................................
.......................................................#...............#.............................#...........................#..........
.............#.................................#............................................................................................
............................................................................................................................................
..#.............................................................................#...........................................#...........#...
............................................................................................................................................
......................................#..........................................................#................#.........................
............................#................#......#......................#...........#....................................................
............................................................................................................................................
....................................................................................................#................#..........#...........
.#............#...................#...............................#........................................#.............................#..
.........#...............................................................#..................................................................
.......................#....................#........#...........................................#..........................................
............................................................#.....................................................#.........................
..............................#.......................................................................#...................#.......#.........
............#.......................#...................#............................#......................................................
...................................................#......................................#..............................................#..
.#................#...................................................#........................#............................................
......#....................................................................#................................#...............................
...............................#....................................................................................#.......................
.........................#.....................#......#.............................................#.................................#.....
............................................................................................................................................
...............#.....................#....................................................#.................................................
..................................................................................................................#.........................
....#......#.....................................#..............................#............................#............#.....#...........
....................#.............................................#....................#.........#.......................................#..
.........................................................#..............#.............................#.....................................
............................#...........#...........................................................................#.......................
............................................................................................................................................
#..................................#...............................................................#..........#.............................
.......#......................................................................................#.................................#.......#...
.....................#....................#...............................#.....#......................................#....................
................................#..........................#......#....................#..........................#.........................
..............#...................................#........................................................................#...............#
....#....................................................................................................#..................................
.......................#....................................................................................................................
......................................#................................#..................#.................................................
.....................................................#............................................#...............................#.........
............................................................................................................................................
............................................................................................................................................
....#.................#..................................#.........................#..........................#.............................
.............#........................................................................................#..................#..................
......................................#............................................................................#........................
.........#....................................................#.........#............................................................#......
.............................................................................................#..............................................
.............................#...........#............................................................................#.....................
#..................#................................................#....................#.......................................#.........#
...................................................................................................#......#.................................
...........#.............................................#...........................#......................................................
....................................#.......................................................................................................
..................................................#..........#.........#......................#.....................#.......................
.#......#....................................#..............................................................#...............................
.............................#.............................................#................................................................
.......................#...............................................................................#....................#...............
....................................................#.....................................#...........................................#.....
................#.....................#..................#.................................................................................#
...#.....#..........................................................#................#......................................................
.............................................#...............#................................#......#......................................
...............................#...............................................#............................................................
.............................................................................................................................#.........#....
.....................#................................................#.................................................#...................
...............#.........................#.......................#..................#.......................................................
.....#......................................................................................................#.......................#.......
....................................#.................#.........................#..................#........................................
........................................................................................................................................#...
.........#..............#.....................................#........................................#.....................#..............
...............................................#...................#........................................................................
......................................#.............#..................................#.....#.......................#......................
............#.....#...............................................................................#.........................................
...#...................................................................................................................................#....
.......................#.........................#..........................................................................................
.........................................................#...........#.........................#........#..........#.............#..........
............................#..............#....................#........................................................#..................
.......#.................................................................#................#.................................................
.................#..................................................................................#........................#...........#..
...................................................#.......#................................................................................
.........................................#......................................#......................................#....................
....................................#...........................................................................#...........................
..............................#.............................................................#...........#.......................#......#....
.........#...............................................#..............#...................................................................
........................#....................#.....................................#........................................................
#...........................................................................................................................................
............................#......................................................................#.......#................................
......................................#.....................................................................................................
.....#............#.........................................#..........................#..........................................#.........
...........................................#......................#..............................................#..........................
..............#..............................................................................#............................#.............#...
..#......#...........................................#..............................#..................#.....#..............................
....................#..........#.....#...............................#......................................................................
............................................................................................................................................
.................................................#..........................................................................................
.............#..........#...............................#...............#.............#..........#.........#........#.......................
............................................#................#.................#............................................................
....................................#....................................................................................#.............#....

View File

@ -6,38 +6,48 @@ fn main() {
.map(|x| x.chars().collect::<Vec<char>>()) .map(|x| x.chars().collect::<Vec<char>>())
.collect(); .collect();
let mut rotate: Vec<Vec<char>> = vec![]; let mut y_expand: Vec<i32> = vec![];
for line in &input {
if line.iter().all(|char| char == &'.') {
y_expand.push(1);
} else {
y_expand.push(0);
}
}
let mut x_expand: Vec<i32> = vec![];
for j in 0..input[0].len() { for j in 0..input[0].len() {
let mut tmp: Vec<char> = vec![]; let mut is_empty = true;
for i in 0..input.len() { for i in 0..input.len() {
tmp.push(input[i][j]); if input[i][j] != '.' {
is_empty = false;
}
} }
if is_empty {
if tmp.iter().all(|x| x == &'.') { x_expand.push(1);
rotate.push(tmp.clone()); } else {
x_expand.push(0);
} }
rotate.push(tmp);
} }
// println!("{:?}", x_expand);
let mut expanded: Vec<Vec<char>> = vec![]; let mut galaxies: Vec<(i64, i64)> = vec![];
for j in 0..rotate[0].len() {
let mut tmp: Vec<char> = vec![]; let mut y_offset: i64 = 0;
for i in 0..rotate.len() {
tmp.push(rotate[i][j]); for (i, line) in input.iter().enumerate() {
if y_expand[i] == 1 {
y_offset += 1000000 - 1;
} }
if tmp.iter().all(|x| x == &'.') { let mut x_offset: i64 = 0;
expanded.push(tmp.clone());
}
expanded.push(tmp);
}
let mut galaxies: Vec<(i32, i32)> = vec![];
for (i, line) in expanded.iter().enumerate() {
for (j, char) in line.iter().enumerate() { for (j, char) in line.iter().enumerate() {
if x_expand[j] == 1 {
x_offset += 1000000 - 1;
}
if char == &'#' { if char == &'#' {
galaxies.push((i as i32,j as i32)); galaxies.push((i as i64 + y_offset, j as i64 + x_offset));
} }
} }
} }
@ -52,4 +62,60 @@ fn main() {
println!("{:?}", dist_total); println!("{:?}", dist_total);
} }
// use std::fs;
// fn main() {
// let input = fs::read_to_string("input.txt").unwrap();
// let input: Vec<_> = input.split('\n')
// .map(|x| x.chars().collect::<Vec<char>>())
// .collect();
// let mut rotate: Vec<Vec<char>> = vec![];
// for j in 0..input[0].len() {
// let mut tmp: Vec<char> = vec![];
// for i in 0..input.len() {
// tmp.push(input[i][j]);
// }
// if tmp.iter().all(|x| x == &'.') {
// rotate.push(tmp.clone());
// }
// rotate.push(tmp);
// }
// let mut expanded: Vec<Vec<char>> = vec![];
// for j in 0..rotate[0].len() {
// let mut tmp: Vec<char> = vec![];
// for i in 0..rotate.len() {
// tmp.push(rotate[i][j]);
// }
// if tmp.iter().all(|x| x == &'.') {
// expanded.push(tmp.clone());
// }
// expanded.push(tmp);
// }
// let mut galaxies: Vec<(i32, i32)> = vec![];
// for (i, line) in expanded.iter().enumerate() {
// for (j, char) in line.iter().enumerate() {
// if char == &'#' {
// galaxies.push((i as i32,j as i32));
// }
// }
// }
// let dist_total = galaxies.clone().into_iter().enumerate()
// .fold(0, |mut acc, (i, gal)| {
// for next in &galaxies[i + 1..] {
// acc += gal.0.abs_diff(next.0) + gal.1.abs_diff(next.1);
// }
// acc
// });
// println!("{:?}", dist_total);
// }