From 435987a86bfe924f0e9e504074aa8637a8b02b1c Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Fri, 15 Dec 2023 20:10:17 +0100 Subject: solve part 2 with cache --- AoC2023/day12/input | 1000 +++++++++++++++++++++++++++++++++++++++++++++ AoC2023/day12/solver.lisp | 82 ++-- 2 files changed, 1048 insertions(+), 34 deletions(-) create mode 100644 AoC2023/day12/input diff --git a/AoC2023/day12/input b/AoC2023/day12/input new file mode 100644 index 0000000..14c0a31 --- /dev/null +++ b/AoC2023/day12/input @@ -0,0 +1,1000 @@ +.#?#???????.????# 1,2,3,2,1 +?????????? 1,1,4 +????.??.??.??? 1,2 +??????#??????.? 2,4,1,1,1 +?.?#??.?.#####???? 2,9 +???#?.??.???? 3,1,1 +.???????.?# 2,3,2 +?.#????#??.#? 4,3,1 +..?????.??????###?? 1,6 +.####?????#.?.?#? 7,1,2 +#????#????.??????.#? 1,1,5,2,1,2 +.??#?.#???#? 1,1,1,1 +.??#???##.?????? 7,2,1 +????????????.??#???. 1,1,7,1,1 +?????????# 1,5,1 +?#?.#????#????#???? 2,2,1,4,1 +?.??#????### 3,3 +????##??????##??. 1,3,9 +.????????. 1,2 +?#.????#.. 1,2,1 +?.??#????.##??. 1,1,3,1,4 +.??.??#?##?##?? 1,5,2 +?#.?????.?#?? 1,1,2,1 +?#??.?#?#??????#?#? 3,14 +#???##??.?? 8,1 +#?.#??????##?.? 1,1,7,1 +??.#??#??# 1,1,5 +??#???##?###??.??? 13,1,1 +?##????#????? 9,1 +?.??.##?.?? 1,3 +?#??#?.??? 5,1,1 +???#?#?.???#?#?#. 6,8 +??..?#?#????? 2,5,1,1 +#?#?##.??.?#??#?.?? 6,1,5,2 +?.??#.#????????? 1,3,1,1,2 +?.??.????#?.???#??? 1,1,1,3,7 +??###?.??##?#? 5,5 +????#???.???#?? 7,2 +????.?????# 3,1 +#?##??.?.?##??#?#?# 5,1,7,1 +??##.#?.#?..?? 4,1,2,1 +????.???..#?#? 4,2,3 +???????#.????? 1,6,4 +#??????#..?.??.?#??? 3,4,1,1,3,1 +?#?##?..#?? 4,1 +?##???.#???#?#??? 4,1,3,1 +.?#??##?????#? 8,3 +?.?.?????#??????#?? 1,8,3,1 +????#?.??#????. 4,5 +?#..#??????#?.? 1,1,5,1 +??##??#??.?. 2,3 +.??????.#??? 5,3 +????????#??? 2,2,1,1 +..#?#?##???????#?? 8,4 +?????.??????.#?#??? 3,6,1,1,1 +.??.??.#?#.#?????#.# 2,1,1,1,7,1 +..??.????????#??? 1,9 +??.?????#?.???? 1,3,1,3 +???.?.#????? 2,1,3 +.#????????? 1,5,1 +????#??.???#????? 2,8 +????.??.??#???? 2,1,1 +..?.?????? 1,4 +?#?#.#??.?#??#.??? 3,3,4,1,1 +.#..???.?? 1,2 +?.??#??#???# 2,2,1 +##???.??????? 5,1,2 +.#???##??????.??# 1,5,2,1,3 +#.?.??#????? 1,1,3,1 +.??##?#.?#?#??# 5,1,1,1 +?????#?.??.?.?#??? 1,2,2,1,1,1 +??##?????? 1,5,1 +.?.???????#.?? 1,3,1 +..???????#?##?#?? 3,9 +??.?#????????#?..#?? 1,12,1 +..??#?#??..????.? 1,5,3,1 +.#?.?...?.??. 1,1,1 +??#??.?#??????.?? 4,1,1,1 +.#??##??#?? 1,6 +??..#???.???.? 1,1 +???#??..?. 6,1 +??.??.#?????#.?#?? 2,4,2,2 +???..?????.?#??#.?? 1,4,5 +...?#??#??..??#?##? 6,4 +.?#?##?.??.??##??#.. 6,7 +???????#???? 2,4 +#?.#?????#??..??? 1,2,4,3 +?????????#? 1,6,1 +?.?##??.#.? 4,1 +#?????#.?.?#??#??? 1,5,1,1,2,1 +???.?????.#??#.?# 1,4,1,1,1 +..?..?#???..?.?#? 4,1 +##.??????##??#???? 2,1,1,2,1,2 +#?.#????#?#????#? 2,1,3,7 +.?#?##?#????#???? 12,1 +?????????#??? 1,3 +????##?.#?????#. 1,2,2,2 +#.?.????#???.#??#??? 1,1,3,4,5 +?#??#?#.?##.?####? 7,3,4 +????????#?#. 3,2,1,1 +??????#?#??#?? 6,2 +???.????...?? 2,4 +??##???##..?? 5,2 +??#.#?.?#??? 1,2,2,2 +?#????#??#?????? 1,1,2,1,2 +??.?#?#?#??..?????? 6,2 +???????#??.??????#? 1,4,3,2,1,2 +..#??#???##??? 9,1 +???...????? 1,1,2 +??#??..???#???.#? 1,3,1,4,1 +??.#?.???#?#?.? 2,2,1,4,1 +#????##??#..?? 1,5 +.????.?#??? 2,1 +?#?#.?.?.????## 1,1,1,1,2 +???#?????.?#??#.? 4,1,4,1 +?.??.?.?##?? 1,1,1,4 +##??#????#.?..#?# 3,4,1,1,3 +.#..??.??#?? 1,2,3 +????.##.?? 1,2,1 +#..?????????# 1,5,2,1 +?#?#????#?????? 2,1,3,2,1 +?#?.?##?#?? 2,5,1 +??#????.??? 7,1 +?#???#?.?.?.??. 1,4,1,1 +.????##.#.??#??#??? 6,1,1,7 +.???????#?##?? 2,7 +?.?#?#???#?#.??.???. 1,1,1,5,2,3 +????#?#?.?????.# 6,2,1 +???..#??.?..#??.??. 2,1 +?.?.???#?.. 1,3 +?#????..???.?? 3,1,1,1 +#??.?.?#?? 3,1,1 +?????.????? 4,5 +??????????#??#??? 4,1,1,1,4 +??#?.???#??.?????#?# 2,1,4,1,1,1 +###.??.?#???#?? 3,1,6,1 +???##???.?##???##?? 5,8 +..???##???#?.# 6,2,1 +??..???????#???? 1,1,3,1,1 +..????#.???. 1,1,3 +???..??#??#???#??? 2,4,2 +??#??#???????##? 1,1,5,2 +.#??#?###..?????#.. 8,2,1,1 +.?????????? 1,4 +??##???????.##?.?? 5,2 +?###?.????#??##??#?? 5,11,1 +.?##??????? 3,1,2 +.?##???.?#?#?## 4,7 +?????##??? 2,4,1 +????##????#??????? 10,1,1 +????#???#.?..???? 1,1 +#??#????.?.????? 4,1,1,2 +?#?.?.??#?? 1,1,2 +?????.?#?. 4,1 +?.???????.????? 1,1,1,1,2 +?.???..?????#??#.? 3,8 +????#?.??? 3,1 +???#?#??#???##??? 1,12,1 +?#?..#???.?????????? 2,4,8 +?#???#?????#????? 3,1,5,3 +?..?.#???.?##?? 1,1,2 +?.??.??#?#?#?? 1,7 +.?##?#??.?# 5,1 +#??#?##??#?#?. 1,4,2,1 +.????####. 2,5 +????#???????? 7,3 +?#?.?#.????.? 1,2,1,1 +????????????#??? 1,10,1 +.??.???#???????..?? 1,6,1,1,2 +??.??.?????? 1,3,1 +?##?????#???.? 3,2,1,1 +?.??#??.?.????.??.?? 1,4,1,1,1,2 +??##????????#????? 1,2,2,8 +???#??##..?.?? 8,1,1 +??????..?#? 3,1 +??.??????#?#?.?.? 1,6 +?#????#???#?#?.?? 13,2 +#?????#???##??? 8,2 +???.??##.?.. 1,4,1 +?.?????.##???###?#?? 1,10 +?#?.#.?#??????. 1,1,8 +?.???#???.?.#?#?#.? 6,5 +#???#??#???? 1,7 +??###????#?##?#.#?? 12,1,1,1 +????.#.?#???.?.? 1,1,2,2,1 +??????#??????..?? 1,1,8,1 +.??????#??? 2,1,3 +.???.????? 2,1 +.?#?#???#???#?#?.# 4,1,3,1 +##?.???????.??? 2,1,2,2,1 +?????..???? 2,2 +?##?#???????#.? 7,1,1,1 +?#.#???.?.##??###??? 1,1,1,1,10 +???#?#?????????##? 1,1,5,1,1,3 +??.??????. 1,4 +?#??##???# 5,1 +?.??.#?#???????##?? 1,1,3,1,1,4 +??.????#???#?#????? 6,7 +?..#?#?????? 5,1 +??????.??????? 3,4 +???#?#?#??##??? 1,1,1,7 +????#?.?#??.?? 5,3 +???#.#????##???? 3,8,2 +?#?#??.??#.?? 4,3 +##??#???..? 5,1,1 +?##?#.?##? 4,3 +??..?.?#??.?????#?? 4,3 +#????#?##??#?.?.???. 1,7,3,1,1 +?.#?#??##??.#?#?? 8,4 +?#..??#?#? 2,1,2 +????##??#? 1,2,2 +.????#??##??????? 5,3,2,1 +###?????#?.??????? 3,2,1,2 +?.#?.?#?#??#? 1,4,2 +???.????##...?????? 2,3,2 +?#??##??????#? 5,1,1,1 +???#?????? 5,1 +?.###?????#?? 3,5,1 +.???.?????#?.?? 1,6 +.???????.. 1,1 +??????#????#?# 7,1,1,1 +??.???#?????#???. 1,13 +.???#????? 1,4,1 +????#??##.?# 1,1,2,2 +.?#???#???##??..#.# 7,4,1,1 +..????.?????#? 3,3 +??#?#..??? 5,3 +??????????.? 1,6 +?.?#.??..?##??????#? 2,1,8,1 +??...#??????##? 1,2,1,3 +.????.??#.???#?? 1,1,3,1,2 +?#???????? 1,3 +.?#.??#.???#?.? 2,1,3,1 +?#????..????.# 1,2,2,1 +??.?##???#...#?? 6,2 +??#???#????.? 3,2,2 +?????#???#????? 2,6 +.#?.?.#.???? 1,1,1,3 +?###?#??#??#.??? 3,1,1,1,2 +.??##??????#??#??.#? 6,1,1,2,1 +...?????#?##????? 1,1,8 +.#??.###???#? 2,3,3 +?.#?.??????#??##? 1,8 +??#?##????????#? 6,1,2 +??.??#?.######?.?.? 3,7,1 +?#??#????.?????####? 6,1,2,6 +????????#.???#?? 4,2 +.##??#?#???????.?#? 3,1,3,1,1,3 +.??.?????? 2,1,2 +??.???.????. 1,1,1,1 +#?.?#??#???. 1,4 +??#??#????##?? 5,4 +#??????????? 1,2,2 +???.?#??.??#?? 3,3,3 +?????.???? 1,1,2 +?...??.#.????##??? 1,1,1,7 +.????????.? 2,2,1 +?.?#.#?#?????#???? 2,1,3,5 +????.#?.????? 2,1,3 +??.#???.??????##?##? 1,2,1,1,7 +??#?????.??#?#.. 5,4 +.##?#?#??#????.? 6,5 +??..??????#???#.#?? 2,1,1,7,1,1 +#???.??.?? 3,1 +.??#??#??? 4,3 +#????.#??.????? 2,2,1,1,3 +.?#.???.??.??.?. 1,3,1,1,1 +?????#????#? 1,1,1,1 +.??#???.#.? 5,1 +?.??#????#?#??#??#?# 1,4,4,2,1,1 +?.????.???#? 3,4 +??#?.????#???###?#?? 2,2,1,8 +##???.?#?#??? 2,2,1,3 +?.???.?#??? 1,3,1 +??????????? 3,2 +#.??#????## 1,8 +??#?#?.??.?? 1,4,1,1 +??#????#?.#??? 7,4 +?????#????#??#???.? 6,6 +???..#.????#????#.? 1,1,1,2,7,1 +#?###???????????.?. 5,4,1,2,1 +..???##?.???#??#??? 3,7 +.#???#.?#.?.? 2,2,2,1 +##?????????????###?? 4,2,1,2,5 +??.?#??#???? 1,2,1,1 +?.#.??????.?#?##?#? 1,1,2,2,7 +???..????. 1,3 +#????#?.??#?#. 2,3,2,1 +?.?##.???.? 3,1 +??#?#####?##?##.???. 9,5,1,1 +.????????## 3,2 +??#????#.????#????? 3,2,5,1,1 +??.??##??? 2,2,1 +.??#??.??#??#? 4,5 +???????#.?#. 1,1,1,2 +?#.??#?????#??#.?#.? 1,12,2 +?.#???#.?.?. 1,1,1,1 +.????????#?#??#?? 2,8,1 +??..?#?.###? 1,4 +??##????#??.???#? 4,3,1,1,2 +?????.????? 2,3,1 +???#????#????#??? 1,10 +??????##?#???.?????? 6,4 +..??..#?????#?#??? 2,7,1,1 +#?#?????.#?? 1,1,1,1 +?.???#???#??#?? 1,1,10 +?????#?.#...? 5,1,1 +?????.??.????????## 2,1,1,10 +.???.?????. 1,1 +???#?????.?????###. 1,2,2,2,4 +?.??????.??#???? 1,2,1,2,2 +????.????. 2,2 +?.????.?#??????? 1,3,2,4 +.?????#?.??#???? 1,4,1,4 +???.?.??..? 3,2 +?.??#?????? 4,1 +##????#????#. 9,1 +??.????????? 2,3,1 +?#????#.??.?????? 4,1,2,3,1 +????..??#?#? 1,5 +#???###???.????. 1,5,3 +??.???#.????#??#.# 1,4,2,5,1 +.??##?????.?##??. 4,3,3 +??.#.##?.?????? 1,1,2,1,1 +?#.?????????? 1,1,1,3 +?#..??#???#??#?.?#?? 2,4,3,2,2 +?.?..???.#??. 1,2,2 +?.#?#?...?????? 3,5 +.#?.???????. 2,1 +??????.????#?## 1,2,7 +???.????#?????? 3,4,1,1 +.????#?#??.#? 3,4,1 +?.?#??#??#??#.????# 10,1,1 +??.??.??????#? 1,1,4,2 +.#?????#??? 1,5,2 +?.????????? 1,1 +?#?#??????? 6,1 +.#?##?.????????## 5,1,5 +????##?#???????? 5,4 +..?#.#??#?#???#??#?# 2,4,1,1,4,1 +.?##?.?#.??? 3,2,2 +?.??#??##.?##??? 7,3 +?.#????.???? 4,1,1 +#???.??.????##? 2,1,2,1,3 +.##?..????????#?? 2,4,1,2 +????#?#.????? 5,2,1 +???#?.?????#?????#. 3,11 +?????###.#???. 8,1,2 +??.???..?#??#.?.??? 1,1,1,4,1,3 +..???.??.? 1,1,1 +?###???.#???#???# 6,1,2,2 +#?.????..???????? 1,1,1,1,5 +??#???#?.?#??.?#? 7,3,1 +??##?.????#??.????. 5,5,1,1 +?????#??##?#?? 3,8 +.???###??????.??# 8,1 +??##??.???# 4,1 +?.??#?#??#?. 2,5 +#???.#??????. 4,1,1,1 +???#.???#.#??#? 2,3,1,3 +?????##???#.??..# 1,6,1,1,1 +.#?.?#?#????##???? 2,13 +??#????.#??#??#??? 1,1,1,1,7 +.#.?.#?.???. 1,2,2 +?#???#?#?.???#??#??? 8,7 +??????.??? 2,1,3 +#??????.???#? 3,3,1,2 +???.#????? 1,1,1 +???..?##?#?#??.?.# 1,9,1,1 +..????#??#?????? 3,5,1 +.???.??#?????.. 1,6 +?#???#???????# 5,4 +..?#????#?. 2,3 +????#..#??# 4,1,1 +.???##?#????#?#? 1,5,6 +???##??#???#?#..? 7,4 +???#??????#??.?? 6,1,2,1,1 +.???????..??.. 1,5,1 +?????.????# 4,2,1 +.???#??#??#??.? 5,2,1 +??.#?????. 1,1,2 +.?.????.??#.???# 1,1,1,1,4 +??##???.?.????? 4,1,1,1 +.?#?.?????????? 3,2,1,1 +???#???.??##??# 4,1,7 +?????????###????. 7,6 +????..#?????#???? 1,1,4,3 +??#?#?##?????# 3,2,3,1 +???.??????.##.? 2,1,1,2,1 +.???#????? 3,1 +?????.???#???#? 5,2,3 +##????????#???#??##? 2,1,2,4,1,3 +.?.#??????.?. 1,2,1,1 +.?.?#?.??.?# 1,1,1,2 +??#?.???.?? 2,2,1 +??????##.????#???? 1,6,5,2 +.?????.???#??#?#.. 3,9 +?##???#..#?.??? 6,2 +??..??.????#?# 1,1,3,3 +#??#???.?#?? 1,3,1,2 +.#?#.#???? 3,1,2 +?????..???## 2,1,2 +???#??#???.#???#.? 5,1,1,2,1 +?##????.#?#?#??#?.?? 5,1,9,1 +?.?????#?.?##???#?## 4,1,9 +.#???#...??.?. 5,1 +.#??#??#?.#??..#??? 1,6,2,3 +??##..?.##?#??.? 3,1,2,2,1 +?????##????#????.? 9,4 +#?.??????.?. 2,1,3,1 +#???????????????#?. 3,12 +???.?..??#?#?????? 2,7,2 +?#####????#???#??#?? 11,5 +??.?.#????? 1,5 +????#..?#???? 1,1,3 +#????#?.??#..?#.? 6,3,2 +??###???##???..??? 9,1,2 +??..?#?#???????.? 1,7,1,1,1 +?#?.##?##??.#??. 2,5,2 +????????#...? 6,1 +#?????#??##?.?..#??? 7,3,1,1,1 +?#?.????????? 1,7 +#???????#.??? 5,3,1 +?#?#???#.??? 7,2 +??#??.?#????.?? 1,1,1,3,1 +?.#???.??? 1,1,1 +?????.???##?? 1,5 +.??##???.? 6,1 +??.###?##? 1,6 +??.??????#?##. 1,1,1,4 +????.???.?#??##?. 1,6 +?????#??#?#?.#?????? 3,4,2,2 +?????.?.?#? 3,1 +#???#????.?#? 1,2,1,2 +##??.????#??##??? 2,9 +??#???????????.?.??? 1,1,9,1,2 +???#?##?.?##? 8,3 +?.?#?##????????.#.?? 7,2,1,1,1 +?#??????#??#?#?? 2,11 +????.?#?#?#????????. 3,6,5 +????.??#.???..??.. 1,2,1,3,2 +?#.??.?.??.??? 1,1,1,3 +???#??##???.#?#?? 3,3,2,5 +.#??###???? 1,3,1 +.?.????..? 1,1,1 +.?#???#..? 1,1 +###?#?.#?#.???.?? 5,3,1,1 +?.???.####?#?#? 1,4,3 +.#?#?.#???.???? 1,1,2,1,1 +.????????.???? 2,1,2 +??##????#??????#???? 4,12 +?#?????#?????.??? 2,3,6,2 +.????????#??? 1,4 +?????????###??###?? 3,8 +???????#?.? 5,2,1 +###.??.?##??###. 3,1,7 +?????#?#??#???#.? 1,12,1 +.????#????#??#.?? 13,1 +..???????#??.??.?? 4,1 +?????#?#?#???#??? 1,9,1,1 +??##.????.? 4,1,1 +????.??..##????#. 3,1,7 +.??.?#.???. 1,1,1 +??#??#?#?.???# 5,1,1,2 +?####??#???.????#.? 5,3,4 +?#???#????## 7,2 +.#??#??#??.##? 4,2,3 +?.#???#???.?????? 1,2,6 +?..?????#?##???????? 10,3 +?#?.?????###??#????? 3,1,7,2 +??????##??#?#???#.. 2,3,8 +#?#?????#?. 4,1,1 +????#?#?.#.??????? 2,3,1,4 +?????????#??????.? 1,9 +?????#??????? 2,3,1 +#?#??..?##???. 3,5 +???#???...??#??#?? 1,1,1,3,1,1 +#?.???.???? 1,1,4 +##?#??#?###?.??. 4,6,2 +#??????????#?#??. 1,14 +.?#???##???.??.???? 3,3,1,1,1,2 +#?.????#???#?.????? 1,1,4,1,1,1 +#??#?..??#??#. 2,2,6 +??.????????#??.??? 1,1,1,1,3,1 +.?..?????###?. 1,2,4 +??#?#?#?#???#? 8,1 +.#?#??.?#??#?????? 4,8 +?.??###??.?. 5,1 +???##????.#? 1,4,1,1 +??.???.??????.? 3,4 +?.????.??#? 3,3 +??#??##?.#?.? 1,3,2,1 +??#?????????#?? 4,4,1 +?#??????.##????. 2,1,1,2,1 +?###??#??#?????#??# 6,10 +???.#???????? 2,8 +????????#???#????. 1,1,3,2,2 +.?????..??#?#?. 1,1,5 +?.????#???.? 1,1,5,1 +##??#???.#?. 3,3,1 +????.???.?????#?##? 2,1,1,1,4 +?#?##.????...?? 5,1,1,2 +#?.?.??.#????#??#??? 1,1,10,1 +????????##??????#?? 4,6,4 +?????#??.#.. 1,4,1 +?????#??#?.. 3,4 +??#?????????#??# 1,11 +?????.??#??.????? 1,4,3 +?.?#.?????###?#.??. 1,2,1,6,1 +.???.???#??.???##?# 2,4,5 +?.???#.???#?###??# 1,1,1,1,5,1 +??#.#?????????? 1,1,2,5,1 +.??.????##????.??? 2,2,7,1 +??..??#???????.??..? 1,7,1,1 +???.?.???..? 1,1,3,1 +????..??.?#???.??. 2,1,1,2,1,1 +?###???#???????## 4,2,3,2 +.?##??.#??? 5,1 +?#??##?#?#??#?#???. 9,4 +.##?#?.##?????. 4,2,1 +??#???????? 3,3 +??#??#???#?..??#? 5,3,1,1 +.??#??#?????.?.#??? 10,1,1 +??#???.???? 5,1 +#????#???.?? 4,3,1 +.?##?????#? 6,2 +.##?#?##???????. 7,5 +?#??.??#????#??#??? 1,5,2,4 +???#???.#??#..?#??? 7,2,1,4 +?????.???.?.??.??. 1,2,1 +???.#.?.????? 1,1 +????????#?#?# 2,2,1,3 +?#???????#.???## 1,4,1,3 +?.????.????????? 1,1,1,5,2 +???.?????#. 3,1 +???.?#????.?# 1,2,1,1 +??#?.#??.? 1,3 +.?.??????#.????? 1,4,1,1,2 +#????.#?#???? 1,2,6 +..#?##??#??.#??#? 1,6,2,1 +.???????#?#???##??# 12,3,1 +.??#?.??#???????.# 1,1,1,1,3,1 +?..?????##??.?#????? 8,5 +.#?..?.??. 1,1 +...#??#?.? 1,1,1 +???#..?.????.#?## 1,1,1,2,4 +#?.???#??#???.#?#??? 2,2,1,2,2,4 +.##?#.??.??????? 4,1,1,1,1 +.?#?#????? 1,1,2 +???#???.??#.??? 4,3,2 +?#..#???###?#?#?#? 1,13 +#??#??#??????#???? 1,7,1,1,1,1 +#?.#??#????.??.?###? 1,2,2,1,1,4 +?#?#?.??????.????. 3,4,1 +.???.#?.??#.?.???# 2,1,1,1,1,3 +.????.?????#?#?. 2,8 +?#????###??? 1,4 +??#?##?????????.? 9,2,1,1 +???#??????????#.? 6,1,1,1 +.??#???#????##??#? 5,6 +??##???.??.#? 2,1 +?#?#?##???????????#? 10,1,5 +?.#?????.?.#????#?? 1,2,7 +?##?.???????? 2,3,1 +???.###????.#? 2,4,2 +??????.??? 1,1,2 +#???.????????.#? 1,1,2,2,1 +#.???????#? 1,3 +.?.##??.?#?.. 3,2 +#.?#.????##?#????.# 1,1,3,5,1 +?#?????#?#????? 5,1,1,1,2 +??.#??.?.???.?.#.??# 1,3,2,1,1,3 +.?.?#???#?? 1,4 +??.#??#?.?#???? 1,4,1,1 +?.?#????.?.#?# 2,2,3 +?##?.??#?#?.?#. 3,1,2,1 +?.??.???.???#???.? 1,2,3,3,1 +??##?#???####?#??? 4,1,5,1,2 +#.#??????????????#?? 1,1,3,1,1,6 +#?.?.?.#.#?.?????? 1,1,1,1,1,4 +???#?#.??? 1,3,2 +#?#??#??.##? 1,2,1,3 +??#??#????? 6,1 +???.?#???.? 1,1,2 +?.#..???#??##??? 1,4,4 +?..#??.#?... 1,1 +??...????#????.? 1,3,1,3 +???????#?#??????# 1,1,2,5,1 +?#???????##?.??? 3,6,2 +?#????#???? 2,2,1 +??????#???# 1,5 +?.????#??.?.??.. 6,1 +.??.??#????#? 1,1,1,5 +?##.???.?.?# 2,1,2 +????#??????? 1,2,1,2 +.#.???#????? 1,7 +???????#?#.? 2,2,3,1 +?.???#????????#? 1,3,4 +????????..? 3,2,1 +?.????#?.????????? 1,1,3,6,1 +??.#.?#????. 1,1,3,1 +.??#???????#?..? 5,1 +#?.??##?.????# 1,5,1 +???.?????#??. 3,6 +?.????..???????##? 2,9 +.?##..??????? 2,1,4 +?#?????????????#.? 6,4,1,1 +??#?##?#?? 5,1,1 +??#????#??????#?? 3,3,1,3 +????.?#..?#????? 1,1,3,2 +??#???...#?.?.??. 6,1,1,1 +?.????#?.#?. 1,1,2,1 +???#?#?????#?????.?? 6,1,1,1,1,1 +?????#?#???#??#?#?.. 7,8 +#..#.??.#??#?##??.. 1,1,1,1,6 +????.?#?#?? 3,6 +?#.?.#?????? 2,1,2,1 +??#?#??????????# 11,1 +?.#??####?????????#? 1,1,4,2,1,2 +?.?.?#?.??#?? 1,2,3 +????#???#????#?.???? 1,3,1,5,2 +???#?.???? 3,3 +?##??##.???.#?.##. 3,2,1,2,2 +?###??#?.?#.#??? 4,3,1,2,1 +.?????????##????? 2,8,2 +?.?#?..??#?????? 3,5,1 +#.??#???#????#.??? 1,12,1 +..?#????##? 2,2 +???????#???##???. 2,5,5 +???#??#??.#???.#.# 3,3,2,1,1,1 +.???#.#?????#??.?## 1,1,1,1,3,2 +#????????#. 3,1,1 +???#.#??#? 2,4 +????.##???#???.??? 1,1,9,1,1 +?.???#?#?.?#???? 6,4 +????????#?...#? 2,1 +????#????##???? 1,8,1 +?.???????#.. 2,4 +?..?#??#?##? 1,7 +?#???.#??.???##?? 2,2,4 +?##.????##??? 2,5 +??.?#..?.#?#??? 1,2,1,6 +???#??.?#??????# 4,9 +.?????.????### 5,6 +.##..#??#????... 2,8 +??#??.?????#?#? 1,1,1,3,4 +##??#.??#?? 2,1,2 +??##?###.##?#? 1,6,4 +.???????#?# 2,1,3 +??.???#?#.??##? 1,2,1,1,5 +?#???#?#.?#?#??#.? 2,4,2,4 +??????.??? 1,1 +??????????? 1,1,4 +???#?#?????##?? 7,4 +?##??????. 3,1,2 +?.#?.???.?.###?? 1,2,3 +???..??..#.##??. 3,2,1,2 +?.??.?????#?????# 1,1,1,7 +??.#.#..#?#? 1,1,1,4 +##?##???.?????##??.? 2,2,1,8,1 +.?.???.??.?????.?.?? 2,4 +??.???????.. 1,2 +?????#????????.#.??? 1,4,3,1,3 +?????.??#????. 1,2,6 +?##???##.??.? 8,1,1 +.##??????? 3,1 +?#?#??????????#?##?. 3,7,1,2 +#????#??.###?##.?? 1,4,1,6,1 +??#.??#??.? 1,5 +.?#?#???#???## 1,2,7 +??????#?###??.? 2,9,1 +???.??##?##.?? 1,4,2 +?????..????? 1,1,1,1 +??.?.????#??#?.? 1,1,6,1,1 +...?.#??#?#?#?? 2,5 +.????#???????.#. 6,1,3,1 +?.???#????. 1,7 +.?#???#????#?##?? 5,7 +????..?#??#??#???.? 1,9 +???##?#.???.?.? 6,1 +#??#??.??##?#???? 1,2,9 +?.????#??????? 2,9 +???????.?#. 1,2,1 +#?..??#???.??#?# 2,3,5 +????..??.??.? 1,1 +??????##.???? 3,2,1 +???.?????#?.##? 2,4,3 +#.??#???#.?#?????#?? 1,4,1,1,1,2 +??.?#????.??#? 2,6,1,1 +#?#.?????.??####??? 1,1,1,2,6,2 +??.???##?#???## 7,3 +.???.??#?? 1,3 +.??##.?????? 3,1 +##????#???#?#??#?? 13,2 +.??#??#?..# 7,1 +.?????#?.?#????#?? 7,1,3 +??#??.??????# 4,3,2 +??#?#...??###..??.?. 3,3,1,1 +?#.??#??.?#?..?? 2,3,2,1 +.??#?#?#?## 1,5,2 +?.#???.??#???#??#? 4,4,5 +?.??#??.#?.?#??#?. 1,2,1,2,1,3 +??#??.???????#?#?.?? 3,7 +?.??#?#?.????# 5,1,1 +??#?..?##.#?? 1,2,3,3 +.???.#???? 3,1,2 +???#?.???????? 2,6 +?.??###???.#.????. 5,1,1,4 +.??#??.?????? 4,2,1,1 +??.????#.?. 1,2 +#???.?.????????# 1,2,1,2,1 +???#???????#??#?.?? 2,2,4,1,1 +#??#???#?#??#.???. 5,1,4,2 +?##??????# 7,1 +?#?????.?.. 6,1 +????.?#.???###??. 1,1,7 +????#.#??. 2,1,3 +??.#????.??. 1,4,2 +.????#??.???#?.. 6,4 +?.????#??#?##?.?..?? 11,1 +?????#.?.????????.# 1,2,2,4,1 +?????###?#????? 1,1,3,1,1 +?#??##?#??##. 2,8 +??..?????#??##. 1,1,1,2,3 +.????#.???#??### 1,1,1,1,3 +??..##?????##.??.? 1,5,3,1,1 +??#?#?????# 6,1 +?????#??????????? 8,4 +?.???????# 4,1 +??????.???? 5,1 +????????#?.??????. 6,3 +.???#???.???# 5,2 +.??????..????#??## 2,9 +#???#???.?? 5,1 +???????#..??##?? 1,2,6 +???#????##???????? 2,9 +?#?.????#??#???#??. 2,1,11 +#??????#???####??.? 8,6 +????#?#???? 3,3 +??###.?.?????? 5,1,1 +????#???#?#?#?##?.. 1,2,9 +?####?.?.# 5,1,1 +??##?#??#? 2,1,2 +?.??##?.?.?##?##??? 5,3,3 +#??#.##?####?#??? 4,9 +?#??.#????#.?.?? 3,2,3,1,1 +?????##????#?#??##?# 9,4,2,1 +.????#??????? 3,2,3 +???????#?#??##?#? 2,1,7,1 +????????#?#???? 2,1,4 +.?#.#?##??##. 2,5,2 +??#?#?????#.?#?.?# 9,3,1 +??.?#???##?????.?? 11,1 +?.#??????##???#?? 1,1,1,3,3 +?#???.??????????#?. 3,1,3,1,4 +?#.?????.#?. 2,1,1 +????.????? 3,1,2 +#?.#?????#???? 2,7,1 +??#.?#?#?##??.#?.? 1,1,2,5,1 +??????#????.. 2,3 +.??#??.?.?..??.? 3,1 +?#?#.#?.???? 2,1,1,3 +#.?..????#????? 1,1,1,4,1 +??#???????? 4,4 +??????.????????#?? 4,1,1,3 +?#?....????. 2,2 +??#??#...??# 4,2 +??????.?????#? 4,1,1,3 +.##?#???#?????.#? 2,7,1,2 +??#?????#.??#? 4,3,3 +???#???????? 9,1 +?.?.#????#??#??.??## 1,10,3 +.?###?#..#.?. 6,1,1 +?#??..????#?#? 1,1,6 +..#.?????##?#? 1,1,6 +???.?.#????##?#?. 1,1,1,1,4 +?????????.?#??? 1,1,2 +????#??#??##? 1,2,1,2 +??#??.?###??????.? 3,8 +?#????????. 3,1,1 +???#?#???#??.?#.. 4,4,1 +?.#??.????#???????? 1,1,7,1,1,1 +???.??#?##????#? 1,8,1 +???.?.???????#????? 1,1,1,1,6,1 +..??#?.???#??? 4,4,1 +????????#?.???.???? 1,2,3,3,4 +?????????#??##???. 3,9 +#????..???????.???. 5,4,1,1 +??#?##???????. 6,5 +????.?#?.??...#??? 1,1,3,1,1,2 +?.??.##??.#?????.? 1,2,4,1,2,1 +?#?????????#???.???? 2,1,9,1,1 +??.?.?????.?# 1,1,4,1 +.??##?.#?? 4,3 +.??#??##.#???????? 1,1,3,4,3 +#???????#?#?.??.?? 1,3,1,1,1,1 +????##?#???????????# 1,9,3,1 +??#??..????????#?.?? 2,9,1 +??##?#??#.??.#? 5,2,2,1 +?###?????????.??.??? 4,4,1,1,1 +????.????????? 2,2 +????????##?..?. 2,1,3,1 +?.?.#?#???#??..????? 1,9,3 +??????#??.?#?#?.?? 1,1,4,1,1,1 +..????#?????????#?? 1,5,1,7 +?????????#?#??#..??? 4,8,1 +#??#???#.???.?..? 8,1 +?#??#?????.#??? 1,6,1 +???##??#???##???#.. 9,2,2 +?#????#..#??????#.. 1,4,2,4 +?????#.?.#?#? 3,3 +????.#.????.?? 3,1,1,1 +???#?..#????#??# 2,9 +???.###????#???????? 4,1,3 +??.??.?##?#?#???? 2,2,2,6 +???.???#?#???#??#?? 1,1,1,2,5,3 +.????##?##?##???#?? 1,13 +??????#????#.#?#? 9,1,4 +?????#??.#.??????#?? 7,1,8 +??#??????.??. 1,5,1 +??##?##????#??. 1,2,5,1,1 +??###??????.? 4,2,1 +#??????????..??#?.? 11,4 +??.??#?.???#?##?? 1,1,1,4 +.???.?#??????? 1,3,2 +.#?#??#.????### 6,2,3 +..??#???##.??#? 1,2,3,3 +??#?#?.#?#.?..?### 6,1,1,1,3 +??#????#??????.#. 1,1,4,2,1 +?????.??##?#??#?##?? 2,1,12 +??.?.?#???? 1,4 +??#???#?.???? 2,3,1,1 +.??.#.???..?????#??? 1,1,3,1,6 +???.?##?#? 2,3,1 +???????#????? 1,3,1 +??.????#.#. 1,5,1 +??..??#??? 1,3,1 +.#??##????#???#?.? 1,12 +#.#?#?????#??##??? 1,4,1,8 +??????#?#....? 8,1 +?.?.#????#?????? 1,3,3,1,1 +????#???.##?#.??.## 7,4,1,2 +#.?.???#?.?# 1,1,1,2 +?.#???#?#????#??? 3,1,8 +.????.##???.#???? 1,2,4,2,1 +.#??#..???#. 2,1,2 +???...???#?#????. 2,6 +??##?.??#.??? 1,3,2,1 +?#?##????????#?.? 7,4 +????#.??????. 4,3,1 +?#??????#. 5,1 +???.???#??#? 1,7 +?#????..?#??#? 5,4 +#????????????.?? 1,1,7,2 +?????#.???#? 1,3,1,1 +.???????????#??? 3,1,1,6 +??#????#????? 2,2,2 +.#???#??#??????? 2,7,4 +??????????##???.???? 1,1,9,3 +????..??.?#? 1,1,2,2 +#?????#?#??#???????? 3,14 +??#???.?#.? 1,1,2 +?????????????#?# 2,1,3,3 +???#.?????##????. 2,6,1,1 +?????.##???.? 3,4 +?.#????#?????. 2,7 +.###?????.. 3,2 +.??#??????.#?#. 4,1,1,1,1 +.###?#?##?##????. 11,2 +??????.??????##????? 1,1,1,9,1 +???#?.?.?.?? 4,1,1,1 +??#?##?.??#?????.#? 7,2,3,2 +???.###??.#??#? 1,1,5,1,2 +?.?#.?#?.?#????? 1,2,1,2,1 +#??????.##????? 6,3,1 +?#?#.????. 4,2 +?.????..?# 2,1 +?.?.?.##??#????##??? 1,1,14 +????#?.#???##?#????? 3,1,9,1,1 +??##????.#?#.#???? 1,5,1,1,5 +??#??????..?? 3,1,2,1 +#?.??#?###??#.?. 2,2,4,1,1 +?.#.??#?????? 1,3,1 +??.???##???.#??? 1,5,1,2,1 +#??##?#?#?.????? 5,1,1,1,1 +???.???###?? 2,6 +?#????#?.?#???#???? 2,3,1,5 +??#?####?????##???. 6,4 +##.??#???.??????? 2,3,1,4 +??????.#????#? 1,3,2,4 +#?.?????.???????#?# 2,1,1,10 +.??.?????#???.? 7,1 +?###.?#.?.?# 3,1,1,1 +#????????.??#????#?# 1,5,2,1,1,1 +??##?#?#??#?#???# 8,7 +???.?.???????#.??#? 2,1,1,6,1,2 +??.?????.?#?? 1,1,1,4 +.????#????##?##??. 3,8 +?.?????????? 2,4 +?????????#?#? 4,2,3 +#..??#????#??#.? 1,1,2,2,1 +?#.???????.??.? 1,1,5,2,1 +??#?.???????#.??##?? 2,1,2,2,3,1 +???.???.#??.??? 1,1,1,3,3 +#?#.???#..??? 3,1,1,2 +.#?##.?????#???.? 4,1,3,1 +#?.???????????##?? 1,1,2,8 +?#??.????? 2,2,1 +?#?##???#?##??..#? 1,2,1,2,1,1 +.????????#?. 2,4 +.#?.?##???????.?? 1,6,2 +#.??..##???#???.? 1,1,6,1,1 +?????.###?.??##??#? 1,1,4,1,3,2 +.???#?.??????.?#? 4,6,2 +????#?#????? 7,3 +???...#??. 3,3 +.#.?#??????#????#??# 1,7,1,5,1 +.???#???.?? 2,2 +.????.?#.?#??? 3,1,4 +??.#???#???????. 1,1,7 +??#?..??????# 2,1,1,1 +??##????..???.?# 7,3,2 +?#????#???#??..?##? 1,3,2,3 +?#.#??????##??###??? 2,4,1,9 +.??#.??###?? 1,1,7 +??????????? 1,3 +.?????#???. 1,4 +??????.??#?#???#?? 1,1,9,1 +#?.##?#.???#??? 1,4,1,2,1 +?###??##????##???? 7,8 +#???..?????.?. 1,1,3,1 +#??????#.?#? 1,2,1,2 +?.?#??#????.??? 1,4,2 +#.#????##.###?? 1,1,2,3 +?.?..????.#?..? 1,1,1,2,1 +?????.#???#???? 3,8 +??##?##?????#??#.? 4,2,4,2 +?????????# 1,1,5 +??.??#???#?????. 1,5,3,1 +?.#??.#?#????#??? 2,5,3 +.????.?..# 2,1,1 +?.?.??????#?#? 1,1,7 +?##????##????###??.? 16,1 +.??????#???#..?..??. 10,1,1 +?.#?#??.#???? 5,5 +?????.??#??#??????? 1,1,1,4,1,1 +???????.?..???..?? 5,1 +??????##????????? 2,8,1,1 +??????##???.????# 2,8,2,1 +##.?#?.#?? 2,2,1 +#?.?#.???????#??? 2,1,7 +?.????..??#???????? 4,6,1,1 +???#?##???? 2,6 +???????....#??#???. 4,4 +.?????.??? 5,2 +?.##??????? 2,4 +?##??##?????#????? 8,3,1,1 +.?.#??#?.? 1,3 +?#?????##?.?#??????? 3,3,1,1,3 +??.???##?????? 1,11 +???????#?.?#???? 9,2,1 +??.?#????#?#????? 1,7,1,1,1 +?.?????????#??#?#?? 1,1,11,1 +??.?##????? 1,3,1 +?#?#?????.##??###?? 2,2,2,8 +????#???#???#??. 2,11 +?.????#????## 5,3 +????#??#?#??.????? 1,1,6,1,1,1 +.??#?#??.???.? 5,2 +#??#?.?#?? 2,1,4 +?.??#???#.?? 1,5,1 +??##???#?.???##???? 7,6 +#?.?????###??? 2,1,8 +??#?#?#???.#??? 1,7,2 +#.?#??#.?? 1,4 +????????#????.#? 1,5,1,1 +?#?.???.??? 3,2 +?????#?.??#?##..#?. 2,1,1,6,1 +??#?..###???# 2,3,3 +?.?#.?.?#????# 1,2,7 +?.##?##??#??.#????## 6,3,1,4 +.#??###??????#. 8,3 +????#??#..? 4,2 +.???.????.???#?? 3,1,5 +.?#????#?#?#?#????# 1,13 +?.?#.#..?.???#??# 1,1,1,7 +???..?#??.??##? 1,2,1,5 +?.?#?#?#.###??? 1,1,1,1,6 +???.???#???#?.#?.?. 1,6,2,1,1 +.?.?##..???????? 1,2,6 +.#.?#???#?.?????? 1,3,1,2,2 +#?????#???##??# 3,7,2 +#.?#??#??.??.?? 1,1,4,1,1 +??#??#???##.??##? 4,2,3 +.?#?.#??#??.???? 1,6,2 +##.???.???##?? 2,1,5 +.?.#???##?#??? 1,9,1 +????#?##.????# 4,2,1,2 +???????##?#?????.? 4,8,1,1 +????##?#?#??. 1,8 diff --git a/AoC2023/day12/solver.lisp b/AoC2023/day12/solver.lisp index c93a351..245a188 100644 --- a/AoC2023/day12/solver.lisp +++ b/AoC2023/day12/solver.lisp @@ -16,45 +16,59 @@ (cl-ppcre:split "[\\s,]" line) (cons row (mapcar #'parse-integer damage-list)))) -(defun solve-row (line) - (destructuring-bind (row . damage-list) (parse-line line) +(defun solve-row (parsed-line) + (let ((cache (make-hash-table :test #'equal)) + (row (first parsed-line)) + (damage-list (rest parsed-line))) (labels ((options (row-idx damage-group) - (cond - ;; commited to all options - ((= damage-group (length damage-list)) - ;; If commited to all slots too, is valid option - ;; If still damaged springs are left, then - ;; it was a wrong arrangement, otherwise counts - (cond ((>= row-idx (length row)) 1) - ((find damaged (subseq row row-idx)) 0) - (1))) - ;; Not enough space to fit the current damaged-group - ((< (length row) (+ row-idx (elt damage-list damage-group))) 0) - ;; Probe options. Either commit to a damage-group at row-idx or skip position - (t - (let* ((damaged-count (elt damage-list damage-group)) - (next-slot (+ row-idx damaged-count))) - (+ (if (not (or (find operational (subseq row row-idx next-slot)) - (and (< next-slot (length row)) - (char-equal damaged (aref row next-slot))))) - ;; commits to the damage group, because in condition it has space - ;; Skips one slot, because it checked that it wasn't damaged - (options (1+ next-slot) (1+ damage-group)) - 0) - (if (not (char-equal damaged (aref row row-idx))) - (options (1+ row-idx) damage-group) - 0))))))) + (or (gethash (cons row-idx damage-group) cache) + (setf (gethash (cons row-idx damage-group) cache) + (cond + ;; commited to all options + ((= damage-group (length damage-list)) + ;; If commited to all slots too, is valid option + ;; If still damaged springs are left, then + ;; it was a wrong arrangement, otherwise counts + (cond ((>= row-idx (length row)) 1) + ((find damaged (subseq row row-idx)) 0) + (1))) + ;; Not enough space to fit the current damaged-group + ((< (length row) (+ row-idx (elt damage-list damage-group))) 0) + ;; Probe options. Either commit to a damage-group at row-idx or skip position + (t + (let* ((damaged-count (elt damage-list damage-group)) + (next-slot (+ row-idx damaged-count))) + (+ (if (not (or (find operational (subseq row row-idx next-slot)) + (and (< next-slot (length row)) + (char-equal damaged (aref row next-slot))))) + ;; commits to the damage group, because in condition it has space + ;; Skips one slot, because it checked that it wasn't damaged + (options (1+ next-slot) (1+ damage-group)) + 0) + (if (not (char-equal damaged (aref row row-idx))) + (options (1+ row-idx) damage-group) + 0))))))))) (options 0 0)))) -(solve-row "???.### 1,1,3") - (fiveam:test partial (loop for line in (cl-ppcre:split "\\n" eg-input) for solution in '(1 4 1 1 4 10) do - (fiveam:is (= solution (solve-row line)))) ) + (fiveam:is (= solution (solve-row (parse-line line)))))) + +(defun solve (lines &optional (unfold #'identity)) + (reduce #'+ lines :key (alexandria:compose #'solve-row unfold #'parse-line))) + +(defun unfold-input (repeats) + (lambda (parsed-line) + (destructuring-bind (row . damage-list) parsed-line + (cons (format nil "~{~a~^?~}" (loop repeat repeats collect row)) + (loop repeat repeats append damage-list))))) (fiveam:test solutions - (fiveam:is (= 7090 - (reduce #'+ - (uiop:read-file-lines "input") - :key #'solve-row)))) + (fiveam:is (= 7090 (solve (uiop:read-file-lines "input")))) + (fiveam:is (= 525152 + (solve (cl-ppcre:split "\\n" eg-input) + (unfold-input 5)))) + (fiveam:is (= 6792010726878 + (solve (uiop:read-file-lines "input") + (unfold-input 5))))) -- cgit v1.2.3