Commit Diff


commit - 64be7f4d0436cbe686a8db7b23012a8bb94c031e
commit + 55b5b1cbe2d68e849b2fd9eb9db939156e74dbce
blob - /dev/null
blob + 1956e5372df6dcaa7febfedd88b736f42ad5a619 (mode 644)
--- /dev/null
+++ input/11.txt
@@ -0,0 +1,140 @@
+............#..................#..........................................................#..........................#......................
+.................................................................#...............#..............#...............#......................#....
+...................................#.....................#..................#............................#...................#..............
+#.....................#.....................#...............................................................................................
+........................................................................................#............#......................................
+.....#..............................................#.......................................................................................
+.......................................#................................#..........#...........#......................................#.....
+..................#...........#.............................................................................................................
+.............................................#............#.................................................................................
+.#............................................................................#..................................#..........................
+............#......................#....................................................................#...................#.............#.
+.......#............#....................#........#...................................#......................#..............................
+...................................................................#................................#.......................................
+..............................#.................................................................................................#...........
+..#...........................................................................................#.......................#.....................
+..............................................................................#.............................................................
+.......................................#.........#............#...........................#................#..............................#.
+........................................................#.............#.....................................................................
+.....#..........................#....................................................................#....................#.................
+....................#.......................#...................................#...............#...............#......................#....
+...............#..................................................................................................................#.........
+..#......................................................................#...................................................#..............
+.................................................#............#.........................................#.............#.....................
+....................................#.......................................................................................................
+...........#..........................................................................#.....................................................
+.................#..........................................................................................................................
+.............................................#............................#....................................................#............
+.........................#.......#..........................#...............................................................................
+.......#............#....................................................................................................#..........#.......
+...................................................................#................#...........................#...........................
+..............#....................................#..........................#..............#..............................................
+..#....................#....................................................................................#........#......................
+.........................................................................#......................................................#...........
+......................................#.........#...........................................................................................
+..........#.................................................................................................................................
+.....................#......................#...............#.................................................#.............................
+...............................#...................................................#....................................#.................#.
+.............................................................................................#..............................................
+...................................................................#........................................................................
+................#..........#.....................#..................................................................................#.......
+...................................#............................................#..................#........................................
+.....#.....................................................................#...............................#.....#..........................
+............#.........................................................................................................#.....................
+.....................#.............................#.......................................................................#................
+..............................................................#...............................#..........................................#..
+.....................................#.......#.................................................................#............................
+...............#...................................................................#.....#..............................#...................
+...#.....................#.........................................#......#...........................#.....................................
+.........#......................................................................................#.............................#.............
+..........................................................#.................................................................................
+..................................#.......#...........................................#......................#......................#.......
+.............................................................................#..............................................................
+.....#...........................................#..................................................#....................#..................
+............................................................................................................................................
+............................................................................................................................................
+.................#...................#........................#......#..................................#...................................
+..........................#.........................#.....................................#......#.........................#................
+..............................................#...........................#.....................................#...........................
+#.....................#.................#............................................................................................#......
+...............................#..........................#.....................................................................#...........
+..........#.........................#.............................#...........#....................................#........................
+.....................................................#......................................................................................
+.............................................................................................#..............................................
+............................................................................................................................................
+...............#...........#..........#.....#..................#.......................#......................#.......#..............#......
+........#...........#.............................#.....#...................................................................................
+............................................................................................................................................
+.#................................#.............................................#................................................#..........
+............................................................................................................................................
+..........................................................................#...............................................................#.
+..............................#...............#......................................#........#.............#.........#.....................
+...#................................................#.......................................................................................
+............................................................................................................................................
+.......................#...............#...........................................................#..........................#.............
+.................................................#...........#......................................................#.......................
+...........#............................................................................#...................................................
+.....#..................................................#.....................................#.............#..............................#
+..................#..........#..............................................#..........................#..............................#.....
+....................................................#.......................................................................................
+..#............................................................................................................#................#...........
+.............................................................#........#..........#.....#....................................................
+...........#..........#............#.......#...............................................................................#................
+............................................................................................................................................
+......................................................#..............................................#......................................
+.........................#.....#...............................................#................................#................#..........
+...#.......................................................................................................#...........................#....
+........#...........................#....................................#...............#..................................................
+..........................................#.......................#.........................................................................
+............................................................#.............................................................#.................
+...........................#...................................................................#.....................#......................
+...............#.................#............#.............................................................................................
+...#......#..........................................#..................................#...............#...................................
+.................................................................#......................................................................#...
+.......................#..................#...............#..................#..............................................................
+.................................................#...................................#.............#............................#...........
+................#...........................................................................................................................
+...................................#.........................................................#........................#.............#.......
+.............................................................#..........................#......................#............#..............#
+...#..................#.............................#..........................#............................................................
+........#......................................#............................................................................................
+..............#............#...........#............................................................#.......................................
+....................................................................#.......................#...............................................
+.#....................................................................................#........................................#.......#....
+...........#...................#............................................................................................................
+.........................#..........#.......#.........#..................#..................................#...............................
+................................................................#....................................................#......................
+...#.............................................................................................#.....#....................................
+.................................................#....................#.....................................................................
+.......................#.........#..................................................#.......#...................#........#..................
+........................................................................................................................................#...
+...........#................................................#..............................................#................................
+.....................................#..........................................................#...........................................
+....#.......................................#....................................................................................#..........
+...................#..............................................#.........#..........#.............#......................................
+............................................................................................................................................
+............................................................................................................................................
+.............#.......................................#...............#......................#......................#...............#........
+...............................................#............................................................................................
+....#.................................#.......................................................................................#.............
+............................#.................................................#......#.....................................................#
+...................#..............#.......#...............#.....................................................#.........#.................
+..................................................................#.....................................#...................................
+...................................................#..............................#......#.......#..............................#...........
+.......................................#.....................#..............#......................................#........................
+.................#..........................................................................................................................
+..............................................#.......#.................#.................................#.................................
+.........#...............#.............................................................#.................................#.............#....
+..#..............................#..................................#.......................................................................
+...............................................................#...........#.......................................................#........
+............................................................................................................................#...............
+................#...........#............#.........#........................................................................................
+........#.............#........................................................................................#...........................#
+..........................................................#...............................#..............#...........................#......
+...............................#................................................................#...........................................
+..................#.............................................#.........#..........................................#......................
+.....#................................................#.........................................................................#...........
+............................................#.....................................#.........#...............................................
+.......................................................................................................................................#....
+#..........#.............#......#.................................#...................................#.....................................
+.....................................#.........#.........................#.....#............................................................
blob - /dev/null
blob + 37cac3da68d8361d396ec08d10a505983d1073ca (mode 644)
--- /dev/null
+++ src/day-11.lisp
@@ -0,0 +1,36 @@
+(defpackage #:aoc/day-11
+  (:use #:cl #:aoc/utils)
+  (:export #:day-11))
+(in-package #:aoc/day-11)
+
+(defun find-galaxies (map)
+  (let (galaxies
+        empty-rows
+        empty-cols)
+    (loop for x from 0 below (input-map-width map)
+          for contains-galaxy? = nil
+          do (loop for y from 0 below (input-map-height map)
+                   when (char= (map-cell map (cons x y)) #\#)
+                     do (setf contains-galaxy? t)
+                     and do (push (cons x y) galaxies))
+          unless contains-galaxy?
+            do (push x empty-cols))
+    (loop for y from 0 below (input-map-height map)
+          unless (loop for x from 0 below (input-map-width map)
+                       thereis (char= (map-cell map (cons x y)) #\#))
+            do (push y empty-rows))
+    (loop for galaxy in galaxies
+          collect (cons (+ (point-x galaxy)
+                           (count-if (curry #'> (point-x galaxy)) empty-cols))
+                        (+ (point-y galaxy)
+                           (count-if (curry #'> (point-y galaxy)) empty-rows))))))
+
+(defun day-11 (input)
+  (let* ((map (make-map input))
+         (galaxies (find-galaxies map))
+         (sum 0))
+    (map-combinations (lambda (p)
+                        (incf sum (apply #'manhattan-distance p)))
+                      galaxies
+                      :length 2)
+    (values sum)))
blob - 56b3ca8cc742f7c814b1e309330b436f4dd1bb5e
blob + 1b1bf5c0c4e5bf66be9a275669b2ec6b4c5a0015
--- src/utils.lisp
+++ src/utils.lisp
@@ -16,6 +16,7 @@
    #:point-x
    #:point-y
    #:point-neighbours
+   #:manhattan-distance
    #:do-map-neighbours
    #:read-number-list))
 (in-package #:aoc/utils)
@@ -138,6 +139,12 @@
   (mapcar (curry #'point+ point)
           *map-neighbours*))
 
+(defun manhattan-distance (from to)
+  (+ (abs (- (point-x to)
+             (point-x from)))
+     (abs (- (point-y to)
+             (point-y from)))))
+
 (defmacro do-map-neighbours ((neighbour-point map start-point) &body body)
   (with-gensyms (width height lb? rb? tb? bb?)
     (once-only ((sp start-point)
blob - /dev/null
blob + 3cf65c3db1804db632606104d0ba0515e96dc01d (mode 644)
--- /dev/null
+++ t/day-11.lisp
@@ -0,0 +1,18 @@
+(defpackage #:aoc-test/day-11
+  (:use #:cl #:lisp-unit2))
+(in-package #:aoc-test/day-11)
+
+(define-test test-day-11
+    ()
+  (multiple-value-bind (task-1)
+      (aoc:run-day 11 "...#......
+.......#..
+#.........
+..........
+......#...
+.#........
+.........#
+..........
+.......#..
+#...#.....")
+    (assert= 374 task-1)))