From 2c6a12bc996a47c8be27ac8fb4e18073841f3391 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Fri, 29 Dec 2023 23:32:16 +0100 Subject: [AoC2023] day21 part 1 lisp --- AoC2023/day21/eg-in | 11 ++++ AoC2023/day21/input | 131 ++++++++++++++++++++++++++++++++++++++++++++++ AoC2023/day21/solver.lisp | 43 +++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 AoC2023/day21/eg-in create mode 100644 AoC2023/day21/input create mode 100644 AoC2023/day21/solver.lisp (limited to 'AoC2023') diff --git a/AoC2023/day21/eg-in b/AoC2023/day21/eg-in new file mode 100644 index 0000000..9e1d842 --- /dev/null +++ b/AoC2023/day21/eg-in @@ -0,0 +1,11 @@ +........... +.....###.#. +.###.##..#. +..#.#...#.. +....#.#.... +.##..S####. +.##..#...#. +.......##.. +.##.#.####. +.##..##.##. +........... diff --git a/AoC2023/day21/input b/AoC2023/day21/input new file mode 100644 index 0000000..efff1a5 --- /dev/null +++ b/AoC2023/day21/input @@ -0,0 +1,131 @@ +................................................................................................................................... +..#...#....#.......#.#..##......#...............#..#....#......................................#....##.........#...##..#.#.....#... +.....#..#............#....#.#...##..#.................#..#..................#...#.#.......#.#..#....#.....#...#.#..............#... +.#........#...........#......................#..........#................#...#..............#......#...........#..#.....#.#........ +..#.#.#..........#.......#....#....#......#.......#...#..................#.###...........#...........##...#..........#.##.#.#.#.#.. +.#.#.........#.....#.#...........#.......##.###.....#.#.........#.#.........##.................##.........##.#.............##.#.... +...#.#...#.#...........#.#.####....................##.#........##..........#......#.............##.#...............#............... +......##...#.##....#.......#....#...#....#..................................#......#.#.#..#.........#..........#..#...#............ +.#..#..#...#........................#......#...##.................#...............#..........##.........#.......................... +......#...#..#...#................#....#.....................#..................#...#.............#..#..#.......##.#.....#......... +.#........#..........#...#........#...........##..............#...#..#.................#............................#.....#....#... +...............##..####...........###..#...##.#................#.......#.................#......#........................#......#.. +....#............#.........#...........#..#.#.#..........#..........#...............#....#....###...##.........#................... +.#.....#..#....#.#..............#..#.....#.#........................................##..#.....#....#...#..##.##...#................ +.....#.....#....#..#......#...............#....#.......#..#..............#...................#............................#........ +................#........#................#.#.........................#.....#.......#.....#.................#.....#.........#...... +......##....#..#...#....#..#............#....#...........#..##............#..#.........#.......#...#.#..........#.....#...#....#... +....#.#...#.........#..#....#...#......#................#..##.......##.................#..#....#..........#......#................. +..........#..#..#..#..........#........................#.................###..............##.#..#.#......#...#.##...........#...... +.###...#.......#..................#....#...............#.......#..#..#...#..#.......................#.#...#..#........#...#......#. +.......#...........#.#..##......#................#............#.#.#......#................#.........#.....#..........#..#..#...#... +....#.....................##....#......##...................#...............#.....#...............#..#........#.#....##.....#..#... +.......#..#.##..#...###...#........#.............##........#......................##.........#...............#....#.#.............. +..###.......#..#......#........#...#...............###.###.........#.#.#........#...........#.........#...........#....#....#.#.... +.....#..........#......#...#.........#........#........#...#...........#.....#.#.............................#.#.......###.##.#.##. +..#.................#.............#................#.#............#.#.....#........................#........#.................#.... +.#..##..#.#......##..........................#..#.........#.....#......#.....#.....#............................###.....##....#..#. +.......#.#.......#............#...........#....#.......#....#...............#.#..##..##.........#....#..............#....###...#... +...#.......#..##..#..#......................#......##......#........#...#........##.##.#..................#...#.#....##..##......#. +...#.......#.........#.........................#...................#......#.......#...#...#.......#............#........###........ +.#.#.#...#.#........##..................#...#.#.........................#......#.....#..#.#........##............#...........#..... +.#.#...#.....###.#........##...........#..#...##.........#...###..#.#...#....##........#...#.............#...#........##...#.....#. +..............#..........#...#........#.......##..##........................#................#........##.........#................. +....##.................#..................................#.............##..#.#....#...#..#...................#.....#....#.#.#..... +....#####...##...#..##..#..#.......###.....#.#......#..#..#.##.....#..#.................#..........................#.#.##.#........ +..........#..#....##.#.................#......#...#.#.......#......##.........#..#.#.....................................#..#...... +..##..##.....#.....#....#...........#.#..........#............#.......###....................#..#..........#....#............#...#. +......#..........#.......................#...#......#...#...#..#....#..#.....#...........#..#....#............#.....#....#.#....... +.#..#......#...#..##................##..#...#.........#.........#.#..#..................#..........................#...#..#.##..... +..#......#..#..................................#.....#.###.#.........#......#.#...#................#..........#....#............... +........#..##....#...................#........#....#...#..........#...#...#..........####.....#..##.#................#.........###. +....#..............................#..#..#..#.##......#...#...................#.##..........#..#...#..................#....###.##.. +.#..........................#.#..#...........#..#......#..#..#........................#........................##...#.#..#......#.. +............................#..#...#..................#................#..............##.#.#.#..................#...........##.#... +.........#..###............#.....##...#..#...#.##.....##....#.....#.#.......#.#...#........##.........#.#..............#.#.....#... +...........#............#.........#.....##...##......#.........#...##...............#.##................#............#.....#...#... +.#####.#..#...............................#..#...............#...................#.....#.#............#................#...#....... +.#..#...#....#....................#...........#.................................................#......##................#....##.#. +....#......#..........#..##...#..#.##....#...#.....#.#........#...#.....#.....#......#...#..#..#..#........................#....#.. +...#.....#..........##......#..#.....##...#...#...#.#..........#..............#.....#..........#..#.....###.................###.... +.....................##...#....#....#......#...#.#.......#...........#..........#..............#.......##.................#..#..... +..##.................#.......#...........#.##........#..##.#...........#.#....#.#.......#..##....#.#..#....#....#.................. +.....#...........#.#........#..........#..#.##.....#............#.......#..#.....##....#.#...........##.......#............#....... +.....##.#.............##........##...........#..#.#..##.#.......#.......#..................#.#..#..#.......#.................#.#... +.#.#..............##....#.......#......#..#........#..................#.#.##..#...#....#.#...........##.....#..#..#.........##..... +..............##................#....#....#........#.......#...##...#.#.#........#.#...#...#..#.#.......#.#...#.................... +.............####.....#..........................#.#..................................#........#.#..##...#...#..#.................. +.#......................#.....#####.#...........#.#............#.............##....#....#.#...........##..........##...........##.. +...........#.#.#..#...##...##........#.......#.......#.#........#.......#......#............#..###....#.......#..#.....#........#.. +............#....#...............#.##............#...##....#.#...........#........#...#...##...........#..........#................ +......................#............#..##......#......#....#.......#..##......#...#....#....#....#..#..#..........#.....#.#......... +................#.....##.......#....##..#.......#......###......#.......#....#.......#....##...........#.#....#....##....#......... +................#..#...#.##...#...#....#.........#....#...##......#.#...#....#.............#.....#............##...#............... +......................#....#......#.#....##...#...#...#.#.......#.....#..#.......#...#.#.##..#........#.....#....#.........#....... +.....##..#..#......................#.#........#....#......#....#..#....#.........#..#.......#.......#.......#.#.......#.###..#..... +.................................................................S................................................................. +..................#...#.....#....#...........#..#.#..........#............................#....................##.....#....#....... +.........#....#......#..#......#...#.#......#...#...#..............#....##.##........#..........##...##...#.......##.#....#........ +................#.##.#..#..............#.....#..#......#....#............#.#...###..#......#......#....#........#..##.............. +.........#.....................................#...#.#.............#.....#...........#........###.....................#.#.......... +.........#....#...........#...##..#........#..........#.#.....#.................#.#.#.##..#...#.#................#....#............ +...................#...................#...#..............#.....#.#.......#..............#......#..........###.......#..#.......... +...........#.#.............##...#...#....#.#.....#....................#.....#..#.....#........##.#....#....#...................##.. +.#................#.#.#.##.............#..#...#....#.#..####.#.......##......................#.......#....#....##................#. +...##..............###...#.#..#..#.#...................#....#...#..#.#....##.....#.....#........#...#...#.#.#...................##. +................................##.#..........#........#..........#.#....#.........##.......##........#............................ +...#............##......#.........#.....#.#................##......#.......#....##...#....#.....#.#..#....#.#.....#.............#.. +......#.........#.....###.##...#..#...#..#.##....#.#.....#.#.#........##...#..#..........#.............#...................#....... +.#....#............#.....#..##....##...##.....#.#......##..#........#..........#.................#.......#......#.............#.... +...#.....#........#......#...........#..#......#.#.#...#....#.###.....##...##..#...#......#..#..........#..#..#..........#.....#... +..#.#..#...........#.###...#.......#..........#...#.........#.#....#......#.........#...#....#...#.##....#....#..........##....#... +......#.#...#............##.......#.......##...............#..................#.#....#..#..#..#..#...#...#...#..................... +....#.......................#........##..#........##.....#.............#........#.#...........#.....#....##...........#..#......... +...#.......#..#.......#......#....#......#..........#.#.#.#.......##....#....................##.........#................#..#...... +..#....................###.......##.#.....#.....#.#............##..#....#..#.................#...#..##.###............#...#..##.... +.....#......#..#...............#.....##......#.....#.......#..#.#..#....#..##.................##....#....##................#....#.. +.............##..#.........#..#..#........#..#..........#...#................###..........##.#.#.........#........#....##..#..#.... +.#.#.#.......#..............#....#...#............#.......#....#.........#........#....#............#............#...#.#..#........ +.............#.....#.........................#....#.#...........#.................#.#..#....#..........................#.##...#.... +...#......#........#.............#..................#.###....................#.#.....#........#.....#.........#.#.#.....#.#........ +.#.............#...##...........#.....#.....#.............#.........#...............###....#...#..#.#............#.#.............#. +............##..#................#....#.......#............##.........##..................#......................#.#..#....#....... +............#......#.....................#.#.#.#..#.#..#......#.............#.#....##.....#....#...............#.#............#.... +..#..#.#.#.#....#......#............##..............#....##.........#.......#.....#...##.....#....................#.......#.....#.. +...#...........#.......#...................#......#...#.##....##....#..#.#...##..#..........#...##............#..#........#.....#.. +.....#....#..#..##................#...#...#....#.#....#.#.............#...#..............#.##.............#..#..#....#.#...#...#.#. +.......#..#.........#.....#..........#......#.#...#.........#.#.....#...#..........#....................#....#..........#.......... +..#.#.#.....#.........#..###...........#.##.#.......#..#..........#.#.......#......#......#.#.........#.#....#..#..#.......#....#.. +.#.........#...#......#...............#......#.#.....#.....................#.......#.#......#..................#...............##.. +..#....#..............................#.....#.##.....#........#....#......#....#....#..#....#........###..#..#..........#....#..#.. +....#.......##........##..............................#.........#...###.#........#...#.##.............##.....#.#......#..........#. +...#.#.##.....#........#.................#...#..#........#............#..#.#........#....................#.....#........#.......... +.........#....#.........#.......##...........#.#.#.#..............#......#..#.......................#.#......................#..... +............#........#..##..#................#..#.............#.............####....#..#.........#............................#.... +....#......#..##...#...#.#...................#.....#.....#.........#.............#...............#...............###.......#.#..... +.#.....#..........................#...........#...............#............##......#.#..........#.......#.......................... +...##.....................#....#...#.........#...............#..#......##.#...#.#..................#.......#....................... +...#........#....#....................#............#.#...#...............#................................##..........##....#.#.... +.#...##.....#........####....#......#.#......................#.............#..#....#.......#...........#..#.........#.............. +......#..............#...........#..##.....................#.#.......#.#..###.............#......#.......#..#...#...............#.. +...#....#...................##...................#.#.#.#...##.....#.#.......#.#..........#............#..............##.......#.... +...........#.................##.........#..............#.......##..##..#.#................##.#.#..#.#.#.............#.............. +........#..##.....#.#.......#.........................#....##.........###.....##........#..........#..#...#............#...#....#.. +...................#.#.#......#..#.........#............#..#........#........#............#....#...........#....................... +.......#..........#.............#.#.#..#....#...............#..............#...........##..#...#..................#..........##..#. +..............##....#....#..#.....#..........#.........#.#...#.....###..#.............#...................#..#.#.#....##..#....#... +...##..........#.....#.#.#...##...#...#........#............#........#.#..............#.....#........#..##...........#.#........#.. +.#..#.#....#..##.##....##.#....##....#...#...#..........#..##.......#...................#.......##..........#........#...#.#....#.. +.#..#....#........#......#...............###.............#..........#...#...............#........#...#...###....#..#.#.........#... +.....#.........#.#..#....#...#.....#......#.................#...#....#...............#.........#.........#...........#.#........... +..##.....#..........#...#..#.....#....#.#.....................#...#.................#.....#..#...#.#................#.........##.#. +.........#..#.##........#...####......#.......#................#...#............#..#.#...........#....#.....#.#....#...###......... +.........#......#...#...#....#...#.....##..#..##.....#..............#........#........#.........#...........#.....#......#.#..#.... +...##.......#.....#....#.............#.##...#.#....................................#.#...#...............#...................#..... +......................#.###.............#........#.................................#.##........#..#.#.............##...#........... +...#........#....#.....#.#...........#.#.......#....#.............#................#.....#..#..#..#.#.......#...#.....#.....##..... +.##.#....#.........#........##......#................##............................#...#..................#...##............##..... +......#.......#........#..#.#...#.........#............#.#........................#..#....#.#...##.........#...#..........##....... +............#.#...#.....#..#..........#.....#..........................###.#.......##..#......#...#......#.........##...###.....#.. +.#.#......#.#..............#............#..........#.#....................#......#..#...#....#..#.#......#...............#.#....... +................................................................................................................................... diff --git a/AoC2023/day21/solver.lisp b/AoC2023/day21/solver.lisp new file mode 100644 index 0000000..f901d54 --- /dev/null +++ b/AoC2023/day21/solver.lisp @@ -0,0 +1,43 @@ +(ql:quickload '(fiveam)) +(defpackage :day21 + (:use :cl :fiveam)) +(in-package :day21) +;;22:55 +;;23:32 + +(defun find-start (field) + (destructuring-bind (rows cols) + (array-dimensions field) + (loop for row below rows do + (loop for col below cols do + (when (eq (aref field row col) #\S) + (return-from find-start (list row col))))))) + +(defun next-moves (field) + (destructuring-bind (rows cols) + (array-dimensions field) + (lambda (pos) + (destructuring-bind (row col) pos + (loop for (dr dc) in '((0 1) (0 -1) (1 0) (-1 0)) + for nr = (+ row dr) + for nc = (+ col dc) + when (and (< -1 nr rows) + (< -1 nc cols) + (not (eq #\# (aref field nr nc)))) + collect (list nr nc)))))) + +(let* ((lines + (uiop:read-file-lines "input")) + (field (make-array (list (length lines) (length (car lines))) + :initial-contents lines)) + (walker (next-moves field))) + (labels ((all-places (positions) + (delete-duplicates (mapcan walker positions) :test #'equal))) + + (loop + repeat 64 + for positions = (all-places (list (find-start field))) + then (all-places positions) + ;; do (print positions) + finally (return (length positions)))) + ) -- cgit v1.2.3