Function aoc::y23d11::y23d11

source ·
pub fn y23d11(input: &str, modifier: i64) -> i64
Expand description

The solution for the day eleven challenge.

We start with the input as a string and then the second parameter is for how much the empty spaces are supposed to expand (which allows us to easily test the answers given in the prompt’s example as opposed to the usual part one or two). We start by parsing the input to find the coordinates of all of the galaxies. We also initialize vectors for the empty rows and columns and fill them with all of the rows and columns to start. After finding all of the galaxies we do a single pass over them to eliminate their x and y coordinates from the lists of empty columns and rows. Then, we generate the combinations for each galaxy to every other galaxy and calculate the Manhattan distance. Then we generate ranges for the x any y coordinates from one galaxy to the other and check to see if we pass over any of the empty rows or columns. For each that we pass over we add our modifier parameter. Then, we add the distance to our running sum, which we return after processing all of the galaxies.

§Example

// probably read this from the input file...
let input = ".#...\n.....\n..#.#\n..#..\n#....";
assert_eq!(y23d11(input, 50), 428);