aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022/16
Commit message (Expand)AuthorAgeFilesLines
* reorder cleanupOscar Najera2022-12-201-104/+105
* orderOscar Najera2022-12-191-38/+41
* early exit for unpromissing pathsOscar Najera2022-12-191-35/+57
* compactOscar Najera2022-12-191-38/+32
* reduce no loopOscar Najera2022-12-191-9/+12
* reduce instead of sortOscar Najera2022-12-191-5/+4
* Create directly next moves listOscar Najera2022-12-191-14/+17
* denest moreOscar Najera2022-12-191-24/+26
* isolate and denestOscar Najera2022-12-191-36/+34
* appropriate only does check no next-options redefOscar Najera2022-12-191-14/+10
* run test on makefile not on scriptOscar Najera2022-12-181-1/+0
* Logical path test instead of memberOscar Najera2022-12-181-23/+21
* unify solution with part1Oscar Najera2022-12-181-42/+13
* track current flow in place not on sorting. SpeedupOscar Najera2022-12-181-13/+23
* test cleanupOscar Najera2022-12-181-16/+23
* ??graph to hashtableOscar Najera2022-12-181-9/+13
* some cleanupsOscar Najera2022-12-181-50/+61
* Solving day 16Oscar Najera2022-12-181-24/+95
* Return optimal path tooOscar Najera2022-12-181-17/+21
* LISP solve part 1 day 16Oscar Najera2022-12-181-99/+35
* traverse but not optimumOscar Najera2022-12-181-24/+120
* lisp try day 16Oscar Najera2022-12-183-0/+125
="s">.......#.. #...#.....") (defun indexes (array) (loop for v across array for i from 0 when v collect i)) (defun shift (coord spacers) (count-if (lambda (idx) (< idx coord)) spacers)) (defun expanded (point free-rows free-cols multiplier) (destructuring-bind (y x) point (list (+ y (* multiplier (shift y free-rows))) (+ x (* multiplier (shift x free-cols)))))) (fiveam:test parts (fiveam:is (= 1 (shift 5 '(3 6)))) (fiveam:is (equal '(7 4) (expanded '(5 3) '(1 2) '(2) 1)))) (defun expanded-galaxies (rows &optional (multiplier 1)) (let* ((free-rows (make-array (length rows) :initial-element t)) (free-cols (make-array (length (car rows)) :initial-element t)) (galaxies (loop for row in rows for y from 0 nconc (loop for col across row for x from 0 when (eq col #\#) collect (list y x) and do (setf (aref free-rows y) nil (aref free-cols x) nil))))) (map 'vector (lambda (galaxie) (expanded galaxie (indexes free-rows) (indexes free-cols) multiplier)) galaxies))) (defun manhattan-dist (s x) (destructuring-bind ((sx sy) (bx by)) (list s x) (+ (abs (- bx sx)) (abs (- by sy))))) (defun solver (rows &optional (multiplier 1)) (loop with gals = (expanded-galaxies rows multiplier) for g across gals for i from 0 sum (loop for j from (1+ i) below (length gals) sum (manhattan-dist g (aref gals j))))) (fiveam:test solutions (fiveam:is (= 374 (solver (uiop:split-string eg-input :separator '(#\Newline))))) (fiveam:is (= 1030 (solver (uiop:split-string eg-input :separator '(#\Newline)) 9))) (fiveam:is (= 8410 (solver (uiop:split-string eg-input :separator '(#\Newline)) 99))) (fiveam:is (= 10154062 (solver (uiop:read-file-lines "input")))) (fiveam:is (= 553083047914 (solver (uiop:read-file-lines "input") 999999))))