commit 9c7d442a8c160ee59e815001d865082616b8bfdc parent 9320fac455489ef7263b15f3a6336c7ed34a7934 Author: Lukas Henkel <lh@entf.net> Date: Thu, 12 Dec 2024 07:29:49 +0100 Day 12 Diffstat:
A | input/12.txt | | | 140 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | src/day-12.lisp | | | 68 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | t/day-12.lisp | | | 43 | +++++++++++++++++++++++++++++++++++++++++++ |
3 files changed, 251 insertions(+), 0 deletions(-)
diff --git a/input/12.txt b/input/12.txt @@ -0,0 +1,140 @@ +CCCCCCCCCBBBMMGGGGGGGGGGGGGYWWWWWWWWWWWWOOOOOOOOOOOOOOOOHLLHHHHHHHHHHTHUUUULBBBBBBBBBBBBPPPPPPPPPPPKKWWWWCCCWWWWWWWWWWWWWWWWWWWWEEEEYNNNYYLL +CCCCCCCCCBBBBBBGGGGGGGGGGGGGWWWWWWWWWWWWOOOOOOOOOOOOOOOOHHHHHHHHHHHHHHHHUUULBBBBBBBBBBBPPPPPPPPPPPPPPPWWWCCCWWWWWWWWWWWWWWWWWWWBEEEYYYNYYLLL +CCCCCCCBBBBBBBBGGGGGGGGGGGGWWWWWWWWWWWWWOAOOOOOOOOOOOOOOHHHHHHHHHHHHHHHHUUULLLLLBBBBBBBBPSPPPPPPPPPPPMMWWCCCCCCCWWWWWWWWWWWBWWWBBBBYYYYYYYLL +CCCCCCCCBBBBBBBGGGGGGGGAAGWWWWWWWWWWWWWWWWOOOOOOOOOOOIOOHHHHHHHHHHHHHHHHUUULLLLLLLBBBJBJSSPPPPPPPPPPMMMMMCCCCCCCWWWWWWWWWBBBBBWBBBBYYYYYYYYY +CCCCCCCCCBBBBBBGGGGGGGGGAAWPPWWWWWWWWWWWWWOOOOOOOOOIIIOHHHHHHHHHHHHHHHHUULLLLLLLLBBBBJJJSSPPPPPGGGGPEEMCCCCCCCCCCCCCCCBBWWBBBBBBBB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RRRRRRTTTTTNTNNNNNNNNNN +UUMMMMMMMMMMMMMUMMMMMMUUMMMNNNNNNNZZZZOTTFTTTTTQPPPPPPPPBYYYYQQQQQQQQQQQQYYYYYYYYYNNNNNNNANCCJCCCCCCCCCCTSTTTTTTTTTTTTRRRTTTTTTTNTNTTNNNNNNN +UMMMMMMMMMMMMMMUUUUUMUUUMMMNBNNNNZZZZZZZFFFFTTTTPPPPFPPPBYYYQQQQQQQQQQQQCQYYYYYYYYYNNNNNNCCCCCCCCCCCCCCCCCTTTTTTTTTTTTRRTTTTTTTTTTTTTNNNNNNN +UUMMMMMMMMMMMMMUUUUUUUUUUMMMBNNNZZZZZZZZFFFFUUTPPPPPPPPBBYYYQWQQQQQQQQQQQQQYYYYYYYYNNNNNNCCCCCCCCCCCCCCCCCTTTTTTTTTTTTTTTTTTTTTTTTTNNNNNNNNN diff --git a/src/day-12.lisp b/src/day-12.lisp @@ -0,0 +1,68 @@ +(defpackage #:aoc/day-12 + (:use #:cl #:aoc/utils) + (:export #:day-12)) +(in-package #:aoc/day-12) + +(defparameter *neighbour-diffs* '((0 . -1) (-1 . 0) (1 . 0) (0 . 1))) + +(defun walk-line (pos-1 pos-2 positions visited diff) + (loop for current-1 = (point+ (or current-1 pos-1) diff) + for current-2 = (point+ (or current-2 pos-2) diff) + for set = (list current-1 current-2) + while (and (gethash set positions) + (not (gethash set visited))) + do (setf (gethash set visited) t))) + +(defun find-straight-fences (positions) + (loop with visited = (make-hash-table :test #'equal) + with fences = 0 + for set being the hash-key of positions + for diffs = (if (= (point-x (point- (first set) (second set))) 0) + '((-1 . 0) (1 . 0)) + '((0 . -1) (0 . 1))) + do (unless (gethash set visited) + (loop for diff in diffs + do (walk-line (first set) (second set) positions visited diff)) + (incf fences) + (setf (gethash set visited) t)) + finally (return fences))) + +(defun region-properties (map point visited width height) + (setf (gethash point visited) t) + (loop with plant = (map-cell map point) + with fences = 0 + with fence-positions = (make-hash-table :test #'equal) + with todo = (list point) + with area = 0 + while todo + for current = (pop todo) + do (incf area) + (loop for neighbour-diff in *neighbour-diffs* + for neighbour = (point+ current neighbour-diff) + for in-bounds = (point-in-bounds-p neighbour width height) + for neighbour-plant = (and in-bounds (map-cell map neighbour)) + do (if (and in-bounds (char= plant neighbour-plant)) + (unless (gethash neighbour visited) + (push neighbour todo) + (setf (gethash neighbour visited) t)) + (progn + (incf fences) + (setf (gethash (list current neighbour) fence-positions) t)))) + finally (return (values area fences (find-straight-fences fence-positions))))) + +(defun day-12 (input) + (loop with map = (make-map input) + with visited = (make-hash-table :test #'equal) + with cost-1 = 0 + with cost-2 = 0 + with width = (input-map-width map) + with height = (input-map-height map) + for y from 0 below height + do (loop for x from 0 below width + for point = (cons x y) + unless (gethash point visited) + do (multiple-value-bind (area fences straight-fences) + (region-properties map point visited width height) + (incf cost-1 (* area fences)) + (incf cost-2 (* area straight-fences)))) + finally (return (values cost-1 cost-2)))) diff --git a/t/day-12.lisp b/t/day-12.lisp @@ -0,0 +1,43 @@ +(defpackage #:aoc-test/day-12 + (:use #:cl #:lisp-unit2) + (:import-from #:aoc/day-12)) +(in-package #:aoc-test/day-12) + +(define-test test-day-12 + () + (multiple-value-bind (task-1 task-2) + (aoc:run-day 12 "AAAA +BBCD +BBCC +EEEC") + (assert= 140 task-1) + (assert= 80 task-2)) + (multiple-value-bind (task-1 task-2) + (aoc:run-day 12 "OOOOO +OXOXO +OOOOO +OXOXO +OOOOO") + (assert= 772 task-1) + (assert= 436 task-2)) + (assert= 1930 (aoc:run-day 12 "RRRRIICCFF +RRRRIICCCF +VVRRRCCFFF +VVRCCCJFFF +VVVVCJJCFE +VVIVCCJJEE +VVIIICJJEE +MIIIIIJJEE +MIIISIJEEE +MMMISSJEEE")) + (assert= 236 (nth-value 1 (aoc:run-day 12 "EEEEE +EXXXX +EEEEE +EXXXX +EEEEE"))) + (assert= 368 (nth-value 1 (aoc:run-day 12 "AAAAAA +AAABBA +AAABBA +ABBAAA +ABBAAA +AAAAAA"))))