From 773bdd5fb9bb389841a110d219d6a54864f2a22e Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Sat, 16 Dec 2023 10:17:56 +0100 Subject: [AoC2023] day14 part1 --- AoC2023/day14/eg-in | 10 +++++ AoC2023/day14/input | 100 +++++++++++++++++++++++++++++++++++++++++++++++ AoC2023/day14/solve.lisp | 35 +++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 AoC2023/day14/eg-in create mode 100644 AoC2023/day14/input create mode 100644 AoC2023/day14/solve.lisp (limited to 'AoC2023') diff --git a/AoC2023/day14/eg-in b/AoC2023/day14/eg-in new file mode 100644 index 0000000..5a24dce --- /dev/null +++ b/AoC2023/day14/eg-in @@ -0,0 +1,10 @@ +O....#.... +O.OO#....# +.....##... +OO.#O....O +.O.....O#. +O.#..O.#.# +..O..#O..O +.......O.. +#....###.. +#OO..#.... diff --git a/AoC2023/day14/input b/AoC2023/day14/input new file mode 100644 index 0000000..a83b74f --- /dev/null +++ b/AoC2023/day14/input @@ -0,0 +1,100 @@ +...O.....#O#....O###...#..OOO.O#....#.O.O.....O...OO##.#..O.O...........O........#...#.#O........##. +#OO..O.##..#..........#.....O...##..O#.#O#O..##.....#.......O....##.#..#OO.O#O#....O..OO.O.....OO#.# +.###..O.#...O.#......O.#.......#.........#OO##.....#...#...O....#..O.O.O.#.O..O...##....O.O#.O....O. +O.O......OO.O#..#....O...#..##...O.#..##O.#...O.O....OO#......O...#...OO#O......O.....#O.O.#.#O.#O.. +.#....#.O#...O..O#..O.##..##.O..O...#...#....O#.#..OOO##..O#.#...#.#O.O#...#...O.O...#...O#O.###.... +.#.....O..#...#..#.##.OO.#O.#........................#...#OO.O.OO.##....O..#OOO#........O.....OO.#OO +O....#.O.#O#O..#...#O.O.OO#O.OO......O.O.OOO...O..O.#....#.OO.......OO..#.....O.#..#.OO#.....#.#.... +.#..##.O....##O#.O...O...#.O..#.O.O.......#..........O#.O#.O..O..O#.#O...#O.#......O.......#.####..O +....#......#...##.OOO##O.#.O##.....O.....O.........#...#.#.#.#..#.OO#O.#.###...O...O#O.O.#O..O#O.... +..O....##O#.....#O..#O..O...O..O....O..O..O..O...OO#...#O....#.#...#O.#..O.O#O..O........O#O......## +..O....#.##OO.O..O##..#..OO#.....#O.#.#..#.OO......#.#..O.....O..#.O.O..O.O..........O...#.O#O...O.# +O.#.#.O.#OO...OO.......OOO..OO......#..O.OO.#............OO...#O....O.OO#.O....O........###..#...O.# +..#.O#...........O.#..O..OO.O#..#OOO.O#...OO..OO....O...#.O#.O.....#.OO.O.O...O.....#.##O.O.....#... +#......OO.O#..O.......O...#.O.O#......#.###.#.#.O.......O.#.#..O..O...O#....OO..OOO.O....##...#.#.## +.#..O...O.O..OO.....O#...#..O....O..#.....OOO...O##.........O..OOOO#........#OOO#.....O#.O.......#O# +#..OO#.O#O...O......#.....#O.#........#.....O.OO..#O#..................#OO.#..O..#...O.....O..##.#.. +.#.#O..#..OO.O.....OOO......O.O#..O...#....##...###O..OOO.....O....O.....#..#.#....OO..##.......O... +...O.OO....#.##O#..O..O.#...O.............O#...O#.##.O....OO.......OO..#OO...O#O#......O....#..OOOO. +.O..OO..#..O...#.O#.....##..#.........O.##.....O...O.....#.#.#O.....#OO......#..OO...O......#O.OO.#. +.O#OO.......O##...#............OO##....OO.O#.#O.O...#..#...#.OO.O..O.O.O#O..O...#........#.#O...O... +.#.#.O#OOO.##OO...O..O.O##.O.O#....#O....####.O.O..#..O..O.O.#....O..#....O..#......O.O.#OO..#.O.#.. +...OOO...O.....O....O......OO#...#....OO.#.O#O....O#.O.O...#.O....O.#...#.....O#..#.O#.#.O.....#OO#. +OO..O....O.O#.O...#....O.#........#.#....#....O...OOO.#.....OO..#.........O..##.........OO.........O +#...##.....OO#...#..O...#.O#.#.#O....OO.O..O#.##.O.....O.O#.#OO..#...#OOO..#....OO..#O..#O#...#.#OO. +OO.#.#....#..O.....#..OO......O......OO.OO.#..OO.#..#..#.........O#......##.##O...O#..OO.OO...#O.... +....O..#.O#.O#..##O.O...#......O.......#....#..#..##...OO.O..O#.O.....OO##.#..O.....O#.O#....O...#O. +.#.O..#.OOOO#...#O......O.#..##...#.O#...O.##OO.O.O.O...#..O#.#O...O..#O.O..OO.O.OOOO#O..O...O#..#.. +....O#..#..###..O#O....OO...#.O.O..#....#O...#O.....#OO...O...OO......##.OO.....O.O..#.....O.O.....# +...###.O....O..#..#.#OO.#.O..O.#OO.#...#....O.....#O.....#.#...OO.......O.#...O##O.......O.##.O...O. +.......#....#O#O.#...OO..#OOO.....OOO.....##....###...O...O...#OO.O.##..#OO...#..#.....O.....O.O#O.# +#O.O..O.#.O....#OO.OO....OO.....OO.OOO..##O.#.....O#OO....#O...O#..O#..#.OO.O......O...O......O#..O# +O.......#..O............#O.#O.OO.##....OO.#OO..##O...#OO....#...#..#....O#..O......O..O.#......#.O#. +O.....#O#O......#..#...OO#.....#.#.....OO#..OO#.O..#.O....#..O..#.....O...O...#......O.....OO....#.O +...#...#......O....#..O..O#O..#.##O.#O...O....O..#.O###.#.#..........O...#.....O........#..#..#...O. +.#....#.....O.#.OOO........O......#...#.O..#..O.O...O#.......O.O.#..#..O.....O......O#OOO...O#...... +.O...O#....O.....O.O...#O.#....#.##......O.O#OO#.....O..O..OOO..#...#....##.....#O.O.#.O#..........# +#....#..#..O..O#.O#O.........O..O.#.O.OO..#O....O.OO.#.OO......#.#..O...O.#.#O.#.#..O.O#..O.#...#O.# +OO...#...O...O.#O.O.#....OO##.#.#...O#....O.#..O...O...#......#.O.O...O.O.OO.#..O..O.#O..O#.#..#...# +.....O..#...O#.O.#.O.#O##O.##.OO#..O.O#O#...O#........#........OO.OOO.O.O.........#..O...........O.. +..O...O.O..O..O......O#..##.O..#.#.#......O...#...#O........###..##......O........#.#...OO.......... +.....OO#....O.#.O.O..OO#...O.....O..OO.#O..........##..##..#.O..#O.O#OO#O#.O.O#.OO....#O..O....O.... +#.O.#.#.O........#..OOOO..O.O#.#.#.....O#.O#..##.....#..O..O#O#OO...#..O#O..OO.O........#......#.#.. +.##.....O.#.......O......O##O#.........OO#..###..#............O....O.#.OO......#.....OO#..#..O...O#. +O.O..#.O.O.....O...O....O..OO....OO#...#.OO........O.O...O.....#.#....#O..#.#......#.#....#....#.O#O +..O#..#.#.#....O..#..O.O.O...#..##...O..O##.......O...O...O..O.O#O......O..O.O.OO.##OO.OO........O.. +..##.....#.O......#.O....O.O..O#..O....OO#O...O.#.O.OO#.OOO#.#.OO..#O.O#..##.O.#...#O.#.....#.O#.O.. +#O..#..O..#.O..O...O....#OOOO..O.O#.##O.O#O...#OO...O.#OOO.#.#......#...#.O#.O..##.#..#..O.#.......# +..O.#.#OO...O...O#...O...O#...O.........#...#.O..#...##..O..O.....#...OOO.##..........O..#O#O.#.O... +...#..O....#...#.O.......O...##...O..O....O.......O.....O..#..OO.....OO..#....OO#O.O#..#OO..O....#O. +.....#O.O#.#...#.O.....##..###..O......O.O#.O#.....O......#....O.O.......O#...##.O....O#O...#..##..# +....#.#..#..#..##O.##.#.O.....O..#OO..O#.O.#OO.#O#..OO..OO#.#.....O..#.OO###.##.......O...#......#.. +..O..#O.....O......#...O.#...O..O.#....#.#.O...O.#.OOO...O.O.##.....O..##....#O...##.O.O#.##O#...OO. +..#O.#...O#.#............#.O..O.#.O.#O#.#...##.O#..O##..#..#OO.O............O.#.OOOO......O.O.....## +..O...OO..#......OO.#OOOO.O.#.#..#..O..OO.O.O.....#.##O......O...O.#....O....#.OOO.O..#..#.##.O.#O.. +O.#.#.O...#..##O.OO......O.O..O.O.#O...........O...OO#O#...OO..#..O..#O...##.O......OOO.......#O..#. +......OOO....#..##O#....O.O.#.O...O#OO..#.O.......O.O..OOO.#...O.#OOO.O.OOOO#...#.....OO..O.O.OOO#.. +..OO.....#.O#......#.O..##..O..OO.O#..O#....O...O.....#..#......O.....O#.O.O#OO.OO.O.OO..#.OO.O.#O#. +.##........O.OO..#...#..#.#O.....#O..#O..O.O..#.O.OO...O.#O#...#.OO.O...#.O#....OO#...##..#O........ +O.#..O.#O.#..#..O#.......O.#.OO..OOO#..##.##.....#..#.OOO..OO#...#O.O#.O..#........##...O....O.O.OOO +.O..#..#O...OO......#...OO#.#........OO..O.#O.........O..#O.#O...##.#O..#...O...O........##..O##..O. +.O.#.....#O....O....OO....#....O..#..O......#..OOO.O.#O....OOO.#....OO.###.#....O.O..#..#..#..#..... +.#..O..#.##....#..#O.O..O.OO#..#....OO...O.O...........O#....O....O......#...O#O.....O.O.....OO.O... +##......O#...................O..O.O....#.........#....O###.#...#.OO.O..#.OO.O....OO.#.O...O...#...## +##...................O...........O.O##....##O...OOOO.O..#.O....O.#...#..OO......O.O.#O.#....#.#.O..# +...#O..O....#......#.#.#.....#.O#..###.#.#...O#OO.O..O.O...#OO#.......#.O...O.#...#...O..O..#O...#.. +O..O....#..O...#.O.O#......O.......#.OO...O...OO....O#O.OOO...O#....O...O..OO.O#.......O.O..O#...... +#...OOO.O..........#..O.#...#..O.#O.O#O.#....#.O.##....#..OO##OO.O.....OO.....OO.#.O...O.......#..O. +.O...O.O...O..O#.....##..O#.O#....OO..###O#..O#..#.#.#..O.O#..#.....##.O.#O#.O.#O.....#.O...OO...#O. +#O#.O...O#...#...O....#.O.##O#...O#.#.#O#.....O.O.O...OO#OO#...O............###....O..#OO#....O..#.O +..#..O.O#..#......#..#........O..O....#...O.O........#.#....#..#.....OOO#.#....OOOO.#O.#..##O...#..O +......O..O..O.#..#...O...#..#..O...OOO.O.OO.O...#.OOO.#...O.#...O...OO#.##..#.##.O...O.OO...OO....## +..#....O..#.#..##O.....O..O...#OOO#..O....#.......##.O..OO#.OO#O..O....O.##O..O....O##O#OO#O...#..O. +....#.#OO.#.#O...#OOO....OOOO.#..O....O...O.........#O#...###...#..OO..O.....O.O.#O..#....###O..##.. +#..O.#.O.O....OO.#..#.OOO....O.#....###O.#.##.O....#O......O..O..OOO.#..O......OOO..O.....OO.O.#.#.O +#.O.#....O..#O.##.O......OO....O.....O#O......#.O...#.##..O#..O.OO#..##..O...#.#O.O..O.O#OO.#..##O.. +....OO.O....#....O#...O..#.O..O.#.O.#.#....#.O....O#OO..O.O.O....#...#...O#O...O...O....#....O.O.O.. +.....#.OOOO.....#...#OO...O.#....###...O.O...#..#..OO..O.O#..O#OO.O.#.O#O.OO....#.#O#OO...O.OOO...#. +.O..#.#.###OOO....#..O....OO.#..O..OO..OO#O#O#..#...O...#...##O..#.......#O...##O..#...##......O.O.# +.O.###..O....O..OO#O....O#....O...O...O..#....O...#.......O.......#.O.O.#......#.OO#..O.OO..O.O.#..O +....#O...#.O.#.O.........#...#....O...#.O.#...O..#.#..O............O...O.#O..O..##.O.O...OO.#O.O...# +#.#.....OO#...O#OO.#..#..........#........O.O#.O.....O...#..#.OO#O.............O.O.##...##OO..#....# +O.OO...O#.OOO#O..O.......O##O#O###.##..#..O...#.#.....O...#..O.O..O..O#.O##.OOOO#...#.....##........ +#............#O....#....O#.....O.OO.O...#....O.#O.#...##.....O..OO#...##.O...#.O....#....O....OO#O.. +#..OO...O.....O.#..O#OO........O.......O....O#O###.#....O#O..##.###O..#O.O....O.O....O.#O..#...O##.# +..OO..#.......#...OO.#OOO#..#OO....#...OO..#O...O....O...#...O#......O.O...O##...OOO.#........O.O..O +O#.OO..O.O..#...O#O..#OO..#.#.....O.##.O.O.O.#..O.O...#O...#.......#..OOO##OO.#..O....OO....#OO.#.O. +.......#...#.#O.OOO#..#......OO.#O...##..O#.O...#O.....O..#....OO.O...OO..OO.OO..O...#.O#..OOOO#.O## +.#.#.O..O...O..#.....#..O........#.O.#..O...#.O..O..#.O.#..#..O.....O.O#...O....O....###..O.#....#.. +..O..OOOO#...#...#...O....#O##.O.#..#...#O...O....O.....#..O..O...##O..O.##O.....O...##....#..#..... +...#.#.....#.......O...O#....#..O........O......#...#.#..##.O..O....#.O.....O.O#.##..O..#..#...#..#O +..OO......O..#...#.......#.O....O.##.#O.#O..O.O.OOO..O.##.#O..#..O#.O..#O..O.#O.....#..#..O.O....... +##O#O.....O......OOO..........O#OO...OO...#..#......#.O.....O#....O..OOO......#...O..O..#O......#... +..O....O...O...##O.O#O.#.#...#.O#O...#.#......##..O#O.#.OO......##O..O#.#..O......##...#O...#..OOOO# +....#O..##.....#........O...O..###..#...O...#O.O..O.O...#..#O......O#....OO#....O.#...#..OO..#..O.O. +OOO.#O.#.#.#..O.#.#O.....#.O##............#........O..OO#O##..O...O..#..O......O....OOO..O..OO...... +..O.#......O.O..#O..O.#.O.O##...OOOO..O...#OO#.....O...OO......O.O...#.O.....OO.O.O..#.O..O.O.O...## +..OO.....#..#.....OO.#.O..#.........O..#..O.......O.##..OOO.......##.....O..#.#.O....#.O#....#..##.. +..#..OO.OO......O.O....#...O.#..#...O..O##...O.OOO....O.O#..O.#..#......#.....O.O.O#.....##.....#O.. +OO...#.##....OO.O...O..O...O..#.O.#.#.#.O.##.#...#.........O#.OO...O...#O...#....OO....#......#O.O.. +.O...#.....O.OO.O##......O...#..#..O.#.....O.#O.O.##O.O.OO.OOOO...#O.#.O....O.#..O........#..O..OOO. diff --git a/AoC2023/day14/solve.lisp b/AoC2023/day14/solve.lisp new file mode 100644 index 0000000..5c463a2 --- /dev/null +++ b/AoC2023/day14/solve.lisp @@ -0,0 +1,35 @@ +;; 9:39 start +;; 10:17 part 1 +;; +(ql:quickload '(fiveam)) + +(defun roll-rocks (field) + (loop for row from 1 below (array-dimension field 0) + sum + (loop for col below (array-dimension field 1) + when (and (eq #\O (aref field row col)) + (eq #\. (aref field (1- row) col))) + do (setf (aref field (1- row) col) #\O + (aref field row col) #\.) + and count t))) + +(defun array-slice (arr row) + (make-array (array-dimension arr 1) + :displaced-to arr + :displaced-index-offset (* row (array-dimension arr 1)))) + +(defun solve (input) + (let* ((rows (length input)) + (field + (make-array (list rows (length (car input))) :initial-contents input))) + (loop + for result = (roll-rocks field) + until (zerop result)) + (loop for row below rows + sum (* (- rows row) (count #\O (array-slice field row)))))) + +(fiveam:test solutions + (fiveam:is (= 136 (solve (uiop:read-file-lines "eg-in")))) + (fiveam:is (= 108935 (solve (uiop:read-file-lines "input"))))) + +(fiveam:run!) -- cgit v1.2.3