2023 Day 11 Complete!

Added a todo file to track changes to my helpers that need
to be propagated through previous days/years
This commit is contained in:
2023-12-11 08:43:32 -06:00
parent be17b84517
commit 77d53011a1
6 changed files with 284 additions and 11 deletions

140
2023/day11/input Normal file
View File

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

72
2023/day11/main.go Normal file
View File

@@ -0,0 +1,72 @@
package main
import (
"fmt"
h "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := h.StdinToStringSlice()
part1(inp)
fmt.Println()
part2(inp)
}
func part1(input []string) {
m := h.StringSliceToCoordByteMap(input)
for y := m.Height() - 1; y >= 0; y-- {
if !m.RowContains(y, '#') {
m.InsertRowAfter(y, '.')
}
}
for x := m.Width() - 1; x >= 0; x-- {
if !m.ColContains(x, '#') {
m.InsertColAfter(x, '.')
}
}
galaxies := m.FindAll('#')
var result int
for i := 0; i < len(galaxies); i++ {
for j := i + 1; j < len(galaxies); j++ {
result += galaxies[i].Distance(galaxies[j])
}
}
fmt.Println("# Part 1")
fmt.Println(result)
}
func part2(input []string) {
m := h.StringSliceToCoordByteMap(input)
expansion := 1000000
galaxies := m.FindAll('#')
for y := m.Height() - 1; y >= 0; y-- {
if !m.RowContains(y, '#') {
// For every '#' coordinate on a row _after_ y, add 1000000 to it's y coord
for i := 0; i < len(galaxies); i++ {
if galaxies[i].Y > y {
galaxies[i].Y += (expansion - 1)
}
}
}
}
for x := m.Width() - 1; x >= 0; x-- {
if !m.ColContains(x, '#') {
// For every '#' coordinate on a col _after_ x, add 1000000 to it's x coord
for i := 0; i < len(galaxies); i++ {
if galaxies[i].X > x {
galaxies[i].X += (expansion - 1)
}
}
}
}
var result int
for i := 0; i < len(galaxies); i++ {
for j := i + 1; j < len(galaxies); j++ {
result += galaxies[i].Distance(galaxies[j])
}
}
fmt.Println("# Part 2")
fmt.Println(result)
}

10
2023/day11/testinput Normal file
View File

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