A 2023/11.lua => 2023/11.lua +20 -0
@@ 0,0 1,20 @@
+local xs, ys, y, G = {}, {}, 1, string.byte'#'
+for line in io.lines() do
+ for x = 1, #line do
+ if string.byte(line, x) == G then
+ xs[#xs + 1] = x
+ ys[#ys + 1] = y
+ end
+ end
+ y = y + 1
+end
+table.sort(xs)
+
+local ans, off, oldx, oldy = 0, 0, math.huge, math.huge
+for i, x in ipairs(xs) do
+ local y, n = ys[i], 2*i - #xs - 1
+ off = off + (i-1) * (i-n) * (math.max(x-oldx-1, 0) + math.max(y-oldy-1, 0))
+ ans = ans + n * (x+y)
+ oldx, oldy = x, y
+end
+print(ans + off, ans + off*999999)
A 2023/11.pdf => 2023/11.pdf +0 -0
A 2023/11.tex => 2023/11.tex +18 -0
@@ 0,0 1,18 @@
+\documentclass{article}
+\usepackage{amsmath}
+\usepackage[letterpaper]{geometry}
+
+\title{Advent of Code 2023 - Day 11}
+\date{}
+
+\begin{document}
+
+\maketitle
+
+Given the number of galaxies $n$, expansion scale $k$, sorted $x$ coordinates $x_1$, ..., $x_n$, and sorted $y$ coordinates $y_1$, ..., $y_n$, the sum of the distances between each galaxy, accounting for expansion, is
+
+\begin{equation*}
+\sum_{i=1}^{n} (2i-n-1)(x_i + y_i) + (k-1)(i-1)(n-i+1)(\textup{max}(x_i - x_{i-1} - 1, 0) + \textup{max}(y_i - y_{i-1} - 1, 0)))
+\end{equation*}
+
+\end{document}
A 2023/11.txt => 2023/11.txt +140 -0
@@ 0,0 1,140 @@
+........................................#...........................#..........................................#............................
+.................................#.....................#...........................#.................#..............................#.......
+............#................................#..................#...........................................................................
+..#.........................................................................................................................................
+................#.........................................................#..............#..................#.......#.......................
+......................#....................................................................................................................#
+......................................#.........................................................#.............................#.............
+.......................................................................#................................#..........................#........
+.......#.................................................#..................................................................................
+...............#................................#...........................................................................................
+........................................#............#.........................#...........#..................#.............................
+.............................#......................................................................................#.................#.....
+......................................................................#..............#.....................................................#
+.......................#................................#.....#............................................#.............#..................
+.......#..................................#......................................................#............................#.............
+.#..........#..................#............................................................................................................
+.....................................#.................................................................................................#....
+............................................................#...........................#..........................#.............#..........
+.................#.......#...............................................#.......#..........................................................
+..........#.................................................................................................#...............................
+..#............................................................................................#......#................#..................#.
+................................#.................#..........................................................................#.......#......
+.......................................#.....#......................#.......................................................................
+................#...........................................................................................................................
+.....#....................#.............................................................................#.................#.................
+........................................................................#....................#..............................................
+.........#........................#..................................................................................#......................
+..............#..................................#................#...............#........................#...........................#....
+......................................#...............#.....................................................................................
+.......................................................................................#....................................................
+.#.....#.......................................................#..............#....................................#........................
+................#.........#...................................................................#..................................#..........
+..................................#.........#...............................................................................................
+.....................................................................................#..................#...................................
+.........................................................................#.......................#..........................................
+#........................................#.....#......#.........................................................#...........................
+..............#..............................................#...........................................................#..............#...
+..............................................................................#..........#..................................................
+..................................................................#.........................................................................
+.....#...............#............#................................................#........................#........................#......
+...........................#............................#..................#....................#...........................#...............
+..........#................................................................................#...........................#...................#
+........................................#...................................................................................................
+.....................................................................#....................................#.................................
+.............#..................#..............................................................................#..........#.................
+.....................................#..........................................#...........................................................
+..................................................#.......#.........................................................#...................#...
+....#.......................................................................................................................................
+...........#............................................................................................#...................................
+..............................................#.....................................#......#......#..................................#......
+...................................#.......................................................................................................#
+..........................#...........................................#......................................#...............#..............
+........................................................#.......#.......................#...................................................
+......#.........#...............................................................#...................#...................................#...
+.........................................#................................................................#.................................
+#......................#.....#..............................................................#...............................................
+............................................................................................................................................
+...........#.........................................................................#........................#.............................
+.......................................#.........#.................#...................................................................#....
+...#..............#.........................................#..................#...................#........................................
+..........................................................................#........................................#........................
+....................................................................................................................................#.......
+.....................#.......#.............#...................................................#............................................
+...................................#..................................................................#......#..........#..................#
+.......#.......................................#.........#...........#............#...........................................#.............
+............#...............................................................................................................................
+.........................#..............................................................#.........#.........................................
+.....................................................................................................................#......................
+................#..........................................................#............................................................#...
+#...........................#............#..................#.....#............................................#............................
+.................................#..........................................................................................................
+.......................................................#.................................#.......#......#..........#......#.................
+..............#..........#.....................#.....................#........#.....#.......................................................
+............................................................................................................................................
+....................................#...........................................................................#..............#............
+..........#..........#.......#............#...................#...........................................#..........................#......
+........................................................................#...................................................................
+...............#..............................................................................#.....................#.......................
+.........................#...........................................................................#......................................
+...................................#............#.................................................................................#.....#...
+.........................................................#....................#.......#.....................................................
+...........................................#..........................#.....................................................................
+....#......#...........#.............................................................................................#.......#..............
+..............................#..............................................................#........#.............................#.......
+.....................................................#...................................................................................#..
+.........................................................................#..............#...................................................
+............................................................................................................................................
+...................................#......#.....................................................................#................#..........
+................................................#...........................................................................................
+......#.....#......#........................................................#...............................................................
+........................#......#...........................#...........#.....................#................................#.............
+....................................................#............#......................#....................#..............................
+............................................................................................................................................
+........#......#.....#......#...........................................................................#..............................#....
+...#....................................#..............#....................................................................................
+..............................................................#..................#..............................#.................#.........
+.........................................................................................................................#.................#
+..........................................................#.....................................#...........................................
+................#..................#.......#..............................#...........................#.....................................
+.......................................................................................#...........................#........................
+...............................................#............................................................................................
+........................#....................................................................................#...........................#..
+.....#........................#.....................#..............#........................................................................
+#...................................#.....................................................................................#.................
+...........................................................#....................#....................................#......................
+...................#......#..................#......................................................................................#.......
+......................................................................................#...................#.................................
+.........#.......................................................................................#..........................................
+.....................................#.......................#......#......#.............................................#..................
+...............................#................................................................................#.......................#...
+............................................................................................................................................
+..................#.......................................#.................................................................................
+....#...................................#............#..................#...........................#...............................#.......
+......................................................................................#............................#......#.................
+......................#......................................#..............................................................................
+.............................................#................................#.........................#......................#............
+..........#........................................................#.......................#..........................#................#....
+.............................#.....#........................................................................................................
+..#..............................................#.....................................#..........#.............#...........................
+..............#....................................................................................................................#........
+....................#.....................................................................................#.................................
+................................#.......................................#...................................................................
+.........................#...................#...........#..................................................................................
+...................................................................#......................................................#.................
+.............#...............#....................................................................................................#.........
+.......................................#...............................................................#........#...........................
+.....#............................................#............#.............................#.......................#....................#.
+........................................................#...........................#.........................................#.............
+...........................................................................#................................................................
+.#...................#..............#.....................................................#................#................................
+..............#..........................#..........................#...........#...........................................................
+......#......................#.............................#..................................#........#............#.......................
+........................................................................#...................................................................
+.................................................#..........................................................................#...............
+.......................#........................................#...........................................................................
+....#......#.........................................#.............................................#..............................#.........
+....................................................................................#....................................................#..
+...........................#......#.....#...................#............#.................#.......................#........................
+........................................................................................................................#...................
+.......#...............................................................................#.................#..................................