From 250417760b35fc878ac8b002014baf39775454b3 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Tue, 12 Dec 2023 14:35:19 +0100 Subject: [PATCH] 2023 - Day 12 --- 2023/input/12/input | 1000 +++++++++++++++++++++++++++++++++++++++++ 2023/input/12/test-1 | 6 + 2023/src/bin/day12.rs | 233 ++++++++++ 3 files changed, 1239 insertions(+) create mode 100644 2023/input/12/input create mode 100644 2023/input/12/test-1 create mode 100644 2023/src/bin/day12.rs diff --git a/2023/input/12/input b/2023/input/12/input new file mode 100644 index 0000000..fb9731f --- /dev/null +++ b/2023/input/12/input @@ -0,0 +1,1000 @@ +.???..??##.. 2,4 +??##.?#?.?#?# 4,3,3 +?????.??##?????????. 2,6,2 +????????..?????#?#?? 3,5 +?.???????###.????? 1,2,2,4,3 +#?#???.??#?? 4,4 +.????#?????.?????.? 8,3 +??#??#?????.?????? 7,5 +#??#??#???#..??? 1,5,2,1 +?.#.??##???### 1,3,4 +.????#?.?? 1,1,1 +??????#?.???.??? 4,3 +.???##?.???.?.??#??? 4,3,1,1,4 +?????#.??? 3,1,2 +????.???#.?..?? 3,1,2,1,1 +#..??????#?##??#??## 1,2,11,2 +?????.?.?????##?#.?? 3,5 +?.?#?.??#?#? 1,2,5 +.?##?#####??.????.?? 10,3 +?.??#????# 1,4,2 +????.?#??? 2,2 +??????#?#. 1,4,1 +#????#.?????#??????? 4,1,12 +????????????? 5,2 +?.??#???????.#.? 8,1 +?#.?.#?????? 1,1,1,2 +????##???.?#??.???? 2,5,1,1 +?????#...???#?#?##? 1,1,1,2,1,5 +?.#?#?#????.?????? 1,1,3,1,1,1 +?#?#??..??? 5,1 +?##?.#.?#??#?.#???? 3,1,1,2,5 +..##.?????.. 2,4 +??????????#. 1,5 +???????#..???. 7,2 +.#?.????##.? 1,2,2 +?.#?#????#?.#??.? 3,1,2,1,1 +??#?.???.?? 2,1,1 +#???..#?##? 3,1,2 +..??#??#?#????? 6,1,2 +?.???#?#??##?.???? 10,1 +?????????????.??? 2,1,7,1,1 +?..#???.?##???? 4,4 +???#????#???#.??? 6,1,1,1 +?##.##??.??????##??# 3,4,2,5,1 +????.#?#?.? 1,4 +#??#??#???#?.? 8,2 +?#??.?.??.?? 3,1,1 +??#??.?.??#??# 3,6 +?##.?????????#??.#?? 3,10,1 +??#???#??### 3,2,4 +?##??..??????#? 3,5 +?.?#..#??? 1,1,2 +?????#????.?.?.? 1,6,1,1 +#??##.?#?##?##.#? 1,3,8,1 +.???#???#??.??.????? 8,1,1,1,1 +.?.??????#??. 1,6 +?#.#?#??#?.????#??? 1,3,2,1,1,1 +???.??.????.#???? 2,1,2,4 +?#???#?????.?? 6,1,1 +??.??.??????? 1,2,1,3 +#??.????#.?.#.???? 1,1,3,1,1,1 +.#????..?#???. 2,3 +.?#?.?.????? 3,3 +?.?#??##??#?####???. 1,5,5,1 +..?###?..?.?#?.. 3,2 +???#??..?. 5,1 +#.#????#??#?????? 1,6,1,1,1 +???#????.???? 4,1,1 +??????###????.??.. 1,1,1,5,1,1 +?????????#??? 3,2,2 +.??##?.#?#? 4,4 +.????.??###?.? 1,5,1 +.??.?.??..???. 1,1,1 +??.???????.# 2,3,1,1 +??#?#????#?#??. 5,4 +?????.???? 2,2,1 +???..?#?###??..? 2,8 +##???.??##..? 2,2,2 +#??#??#?#?.?? 7,2 +.????????.????#?# 1,5,4 +#.##?.???.??????.#? 1,2,1,4,2 +#????..???#?? 1,3,1,4 +?.#?#??#???#?? 7,2 +??##?????. 5,1,1 +?##??????????? 3,1,1,2 +.?#?.?.##. 2,2 +.#.???#?.? 1,1,1 +??#??.?#??#.?. 2,5,1 +?????????? 4,1,1 +??#??##?.?.? 1,2,2,1 +#???.#?.?????#???#? 1,1,1,1,6 +????..#?#?#. 2,5 +???.??..??? 1,2,1 +????#?.?..? 4,1 +????#?#???????#??? 1,6,1,4 +?#?#?#???###??#? 6,8 +???????#????? 2,2,4 +????#???..??????#??. 6,8 +??#????#???.?.???? 3,2,2,1,2 +?#.???#??..?. 1,1,2,1 +?#?.???????..#???. 3,2,2,1,2,1 +?#?.?#.?.? 3,2,1 +??#????###?#????? 2,1,6,3 +.??##??.????????#?? 3,2,3 +???.?#????????.? 1,9 +???##?##??????.. 9,3 +#???#?#????#????? 12,2 +???##.???.??.????#? 4,1,1,1,3 +?????#.?#?#?#??????? 1,1,1,4,1,2 +?.??????.??# 1,2,1,1 +???##?????#????.#?# 1,3,3,1,1,1 +?.#?..##???#? 2,4,1 +?.??#???#??.#?.?##?? 9,1,3 +???.?#???#?#???#??? 2,7,3 +?????????#?...?? 1,2,4,1 +?#???#?##???? 5,2,1 +????????.?#?????#?? 3,2,2,1,5 +#?????#?#?????#???? 1,7,5,1 +??????.?#?? 2,1 +.?.?#????#?. 2,2 +???...?.??.##..#?? 1,1,1,2,2,2 +?????.???. 1,2 +.#??.#?????? 1,6 +.#.???#???# 1,4,3 +.?#????????#?.## 1,9,2 +?????????? 1,3 +???#?????#? 5,2 +?#?????#?????????#?? 3,8,2,1 +???..#.?????.?#????? 1,1,1,2,4,1 +??#?.???#???#.?? 4,1,1,3,1 +?????????#???.. 2,6 +???#???.???? 1,2,2,1 +.???#???#??#? 1,1,2,1 +.??.??.??????? 1,5 +??????????????#? 1,1,2,1,6 +?.??????#????#??.?.? 1,6,1,4,1,1 +?????#.?????.#. 6,1,1,1 +???????.?? 1,1,1 +?#??##???#.?#???? 1,4,1,1,1 +.?.??.?####??#??? 5,1 +.?????.?#.??#?#??.? 1,1,1,1,7,1 +.???##?..???#?.?.. 4,2 +..?.?#..?.#?... 1,1 +?.?????????#?# 1,4,5 +?.#??#.??#?????? 1,4,2,1,1 +.?.??#???????#???. 2,2,6 +.?#??????.?? 2,1,2,1 +??#?.????.??? 2,1,2 +?????#???#. 4,2 +????##.????#?? 2,3,3 +.?.???.#??# 1,1,1 +#??????.?#?##?.?##?? 2,3,2,3,4 +?#?.?#?#?? 1,3 +??##????.?#???# 8,1,1 +?###???.??. 3,2,2 +???#??????##... 4,2 +?#?.?#?.???????? 3,1,1,1,1 +???.??#???.??# 1,6,3 +#.??.???.#?##????#? 1,2,1,5,1,2 +????#?#?#.?#???.?? 1,4,1,3,1,1 +??#???#??????????..# 6,1,6,1 +?.?#?########???.# 12,1,1 +????????#?.???##???? 1,1,4,3,2 +??.#???#?..?????? 1,2,3,1,1 +?#????????? 3,1,2 +???.?#??#????###??? 2,6,6 +????????#?? 1,5 +#??##?#??#?.??????? 10,1,2 +?#?#????.? 1,2,2 +????.????? 1,3 +?.?????#?#? 1,1,3 +#.?#???????.#.?? 1,6,1,1,1 +#.????????. 1,3,1 +?.?#???????#??# 1,12 +??##..??#...?????# 2,2,1,4 +?#???????#.?# 6,2,1 +.?.#??#????#?#? 1,1,1,4,1 +?..??????#?##? 1,1,1,6 +.#??#??????#????? 4,3 +??##?###?.????#?. 7,2 +?#??#.??????#????? 2,1,7,4 +##.??#????##?? 2,2,6 +?#?#????#?????#.?.. 15,1 +????#??...#?? 5,2 +.???#??#????#?? 6,1,2 +#?##????##???#????? 6,2,6 +??##??????. 2,3 +?##????..????? 5,2 +??.?#?##?##?#???.??? 1,8,1,1,1,1 +??#??????#?.?.??? 9,1 +.???#?????#???#?. 1,1,9 +??????#?????.?? 8,1 +?#...?.?.?.#??#. 1,1,1,1,4 +.???.?#????#??? 1,1,1,6 +.??##??.??? 4,1 +???.#???????? 1,1,3,1 +?.??#??#??#?.? 3,5 +???????#??.??????# 1,1,3,1,1,1 +???.#?#??##??#????? 1,10,1 +??????#?????????## 1,1,1,1,1,5 +?.???#?#.?.???#??#? 6,1,4,1 +.????#??#??? 1,9 +?#???.?.#.???? 4,1,4 +????#???#????#?#??? 6,6 +#????##??? 1,3,1 +.??##??##?##?? 11,1 +#??##?#??#.?.???## 7,1,1,1,3 +.?????#??#?#?##??? 1,3,7,1 +???#?#???.? 3,2 +?##?...#???. 3,1,1 +?????.?#.? 5,1 +?#?????.????#? 6,1,2 +#??##??????.#.???# 1,5,2,1,2,1 +.#??.?#????? 3,6 +.##.??##?.?###?.# 2,4,5,1 +???#???.?#???..?. 3,2 +?.?#.????.???#???. 1,1,1,1,4,2 +.????#???.#?? 6,2 +?.?#????????.??. 6,3 +.?????????. 6,1 +?#???.?#?.?..?#?.? 2,1,1,1,2,1 +.#??.???#??? 3,2 +?????#????...? 3,1,1 +#??.????????##?#?.. 3,2,8 +?#???#?????????? 5,6,1 +.???????#? 2,1,1 +?????..??. 1,1,1 +.##.???.???? 2,2,1 +???##.#?.? 2,1 +.??.???##?????????? 5,4 +.?????????.??#????#? 2,1,1,1,2,3 +???##?#???????????. 4,6,5 +#?.#???.?. 1,1,1 +?#??#?#???.?#..??# 9,2,3 +??##?.?.?#?? 2,2 +#?#?#??..#?#?#.? 7,5 +?#?#?????#?#.?#????? 10,1,1,1,1 +?????##??#???#?#. 3,9,1 +.??#?#.??#?###?##??? 4,5,3 +##?#?.??#??.???. 4,4,1 +???.??#?#. 1,1,3 +?.?????.?????#??? 1,1,1,8 +??##??..??##.? 4,4 +????.????.??#??###. 3,1,1,1,4 +????.???###?????? 1,1,1,5,3 +.#??.#?.??. 1,2,1 +??.??##???? 1,7 +?#???.#???. 4,4 +??????.#?#??###?.?? 3,1,1,1,4,1 +???#?.???? 4,1 +.????#?#????.?? 2,7,2 +??.#??????.#? 1,2,2,1 +#??#????#?#? 2,3,4 +??..???#?????.?.#?.# 2,1,3,1,2,1 +?#??#?#????#??.??? 7,1,2,2 +#?.?.??????#?###? 2,1,1,8 +#??.?#?#.???.?????# 1,4,1,1,1,1 +..?##?#???..??? 6,1 +????????.?#??.? 1,4,3 +.?????.??.?# 1,1,1,1 +???##.?.??? 5,1,1 +???#?????? 4,2,1 +?.?#?.????##?. 2,3 +???????#??#???###.# 1,4,2,2,3,1 +??##?#.?#???# 4,2,2 +??.#####?..???#.##?. 1,6,2,1,3 +.#???#????##??.#? 1,3,3,1 +???#?????????#????? 4,1,2,1,5 +?#???.?#?.?#?? 4,3,2 +?####?????#?.??#?? 5,1,3,1,1,1 +?#???.#??###?.?..?? 2,1,6,1 +#????#??.?.?.?????# 4,2,1,3,2 +?#???????#?.??#?? 4,4,2 +?#??????###?#??.# 4,1,5,1,1 +?#.?#?#?#??##???.?? 1,9,2,1 +?.??.#???. 1,1 +???.?????#??#???.? 1,1,1,6,1,1 +#???#?#??##.. 1,7 +?????.???#????#. 1,4,2 +?#??##??????? 8,1,1 +???#?#.?#?#?????#.?? 4,1,2,7,1 +???#???.#???..??##? 1,2,1,4,5 +??.??#?.??.???.??.? 3,1 +???.#??#??.?#???#? 1,6,1,1,1 +.???.??????? 1,1 +????#?.?#?? 1,1,3 +?????##?#??.?? 3,6,1 +??#?#?#.?.????#.? 5,1,1,2 +#?????????.#??#??. 6,2,1,2 +..?#?.?#.#?## 2,1,4 +????#??????#. 2,7,1 +.#???.???????? 4,3 +?????..??? 5,2 +???#???#?.?##?. 1,3,2,4 +??.????#???????#??? 2,12,1 +?????##?##????.???? 1,9,2,1,1 +?#???#?##????#. 1,6,2 +#??.??.??????? 1,1,1,4 +???#??#??#?#????### 6,1,1,4 +??#??????#????#.??? 5,5,2,3 +????.#?.?#?? 2,1,3 +?#?.##?????#?#?#??.? 1,5,2,5,1 +#?#???.??#.???. 1,2,1,1,3 +????##???????.??.??? 7,2 +.#????????####.???.? 13,1,1 +???.?.????#??#?.?? 2,1,1,1,2,1 +??#??.?..???#?# 1,6 +??#?????.?#? 1,1,1,1 +?#?#??.???#?????#??? 1,2,4,1,3 +?#???##?.?????. 2,4,2 +#????###???#???.# 1,10,1,1 +??.???#???.? 1,1,4,1 +??????????###?? 2,1,5 +??????##?.?? 1,5,2 +?#??#.??#????????? 2,1,8 +#.???????##??.? 1,1,5,1 +#??.???#?#.???. 3,1,1,1,1 +???#?.????#?#?? 3,1,5 +???.###?.?# 1,3,1 +??????..?##?? 3,2 +?????#??????? 1,1,8 +#####..?.?????? 5,5 +.???.?????. 2,3 +#???#???#. 1,5 +.???..???????#?? 2,8 +????????????#???##? 2,1,11 +????#????? 1,2,1 +?#?##?#?#?..??#??.# 9,2,1 +??.?????#?#??.? 1,1,4,1 +?...?#?.#??. 1,3,2 +??#???.??#? 1,1 +?.??.?#???????#???. 1,2,7,1 +.#?##?#??.?#??##?#? 8,3,5 +?????.##?#????? 1,2,6,1 +?????.#???##? 1,1,1,5 +???#.?#??#?##???##?? 3,1,1,9 +.??...?#????#?..?.. 1,3,3,1 +?????.??.???.? 3,1,3 +??#?#?#?????..?? 9,1 +?.??#?#?#??#?????.?? 7,4,2 +.??#?..#????#??????? 4,1,8 +?##?#?????. 5,4 +????????..??????.? 5,1,1,1,1 +??##..#?????.??? 3,1,1,1,1 +?.###?#????#?.????? 1,7,3,4 +??#.???#?? 2,1,3 +.??#???????????###? 5,11 +??.?.????. 2,1 +????.#.?#??#?? 1,1,2,3 +???##?..#..##??? 4,1,5 +??#?????#.?????.?#?. 3,2,1,3,1,3 +?????#?#?# 3,5 +##?#???#?#?###..?.?? 2,11,1 +????.?..??? 3,3 +?#??##??.?????.??? 7,2,3 +.?#??????#??#???# 2,7,1 +????????.#?. 1,1,1,1 +#.?#???#????#?# 1,3,1,3,1 +...##???????#?# 2,6 +?#??#????????#?.#?? 7,5,1 +#?#???#.??.??.? 7,2,2 +?.?????#????#. 2,4,1 +.?#??#?#?.???#?? 2,5,3 +??#???????? 1,1 +.??????.??.#.? 6,2,1,1 +????#??.?.?????? 1,5,1,1 +.??.????????? 2,1,2,4 +???????#??? 2,2,4 +#??.???#?###??#?.?. 3,11 +?.??..#???????# 1,1,1,1,3 +????.?#????.?#?? 1,1,2,1,2 +???##???#??##?????.. 2,7,2 +?????##..?????#??..? 1,4,6 +.?#????#???.???? 5,1,1 +??.?.#?#?#???#????? 2,3,8 +##?##???##???? 5,3,1 +??.??#??#?.?? 1,1,3,1 +?#???#?????. 2,2,1,1 +.???#??.????. 5,4 +??.????#?#????. 1,11 +????.???##????? 2,4,2 +???.?.???.??? 1,3,2 +?..??..???? 1,2 +.??????????#.????? 1,1,2,1,4 +?##?????#??????? 3,3,3 +??#?.#?????#? 1,1,4 +???.?????. 2,2,1 +?.?#.##????# 1,1,2,1 +?#???????#???#? 1,4,1,2 +???????.????##??#?? 2,5 +?#???##??.?? 7,2 +?.?????.#..????? 4,1,2 +???#??.??????? 3,1,2,4 +??#??.???#? 3,2 +??####??..??? 6,3 +?#?.??..?????.? 3,1,5 +??##??.?.#???#? 2,1,1,1,2 +???##???.???????.?? 3,5 +#?.?.#????? 2,1,1 +##?#?#?.??#?#???# 6,9 +?.??.??.?#?.? 1,1,2,1 +.#????.????# 2,1,1,1 +###??.?#?#?? 5,2,2 +??????#???. 2,2,1 +??#???.#.??.?. 3,1 +??.?.??#????.???? 1,1,3,1 +..???#????? 2,5 +????###??#??.?.???? 9,1,1,2 +?.???.???#???#??? 1,1,5,1,1 +???.??.?#?#.??. 1,3 +##.????????.????? 2,1,1,4 +?.??##?.?.???# 1,3,1,1 +????#???#?#?###??? 2,9 +?##?#??.???##?#?. 5,1,1,4 +???###.?.???? 4,3 +.??##?..??.?#? 3,2 +???#????????.#?#? 8,3 +.??????#???? 1,1,4 +.?#???????? 2,2,1 +??????..???..?#? 1,3,2,2 +?##???.#????.?.??. 4,5,2 +#?#?..????#?????. 1,1,1,6,1 +?##???.??? 2,1,1 +#?##??#..?.? 4,1,1 +??##??#????#??. 7,3 +.??????????##??# 5,2,5 +???.???.?.??. 1,2,1,1 +.#?.???#???? 1,6 +?.##??.????? 3,3 +?????#?#??..???.??? 2,1,3,3,3 +#?????????.? 8,1 +?#??#??#?.??? 8,1 +??.?#?#?.?????? 1,4,1,1 +????#?????#?#?.? 1,10 +??###??.??????????.? 5,1,1,1,1,1 +???????#??. 4,1 +.?????#?.?? 1,3 +#.?#??.??. 1,1,2 +????.#?#.. 1,3 +.?.???#?#???# 1,7 +?..?????##??.?.???? 8,3 +???#.#?#?? 1,4 +?.?????###??#?#????# 1,8,3,3 +?#?.?.#?.??.?????## 2,1,1,4,2 +????.#????..? 1,5 +...????????###???. 4,8 +?#????##?##??..? 3,7 +????.?#???#??# 1,5,1 +??.??##.#??? 4,2 +.????????. 2,2 +?..#??..#?????????. 1,3,2,1,2 +????#?????.?#??##?.? 2,2,2,1,3,1 +#?.?????.##??#?.??? 2,1,1,5,2 +??#???????? 3,3 +??#?.???#???#.?? 1,2,3,3,1 +??#?????.?#????##??? 1,1,1,1,8 +??.??#???.?.?##????? 1,4,1,6 +?????#???#???. 6,3,2 +???????.???#? 5,3 +?#?##???.#?#?###?? 1,4,1,6 +????.???###???#???? 2,1,7,1 +????#????#.##?#? 7,1,5 +?.?#????.?#?#?? 2,5 +#??????.???.?.???? 3,1,1,1,3 +#??????###?#? 1,2,3,2 +????????..??#??#?##? 1,2,1,2,1,3 +??#??#????#??? 1,4,5 +?.????#?#??????### 1,2,3,4 +?#???#????#???##?##? 5,2,7 +?????#??.? 1,2,1 +.?#??????#???..??. 11,2 +.?#????????????.??? 6,3,2,2 +#???####??#?. 3,4,2 +???????????????? 2,1,4,3,1 +??????????#?.???#. 8,4 +??.?.??.?.? 1,1,1 +?.????#????##??## 1,2,7 +?#??.?.?.????#..#? 1,1,1,2,1,2 +??????.???????# 4,1,3 +??.#?.?###?#?.#???? 1,1,7,1,1 +#??#????#?. 5,3 +.?#??#?#??#?????#?.. 5,6,3 +.??#???#?.?.?? 8,1 +????..?.????##?#? 1,1,1,7 +.?#?#??????#.??#? 4,1,1,1,2 +.?#?????##???.?#?? 5,2,1,4 +#??##?????????? 1,9,1 +???#???.?.??##.? 1,4,4,1 +?#??????#.? 2,4 +???.??###?.??#?#.?? 1,1,4,2,1,1 +#??.????#?##?# 1,1,6,1 +???#..?#??????##??? 1,1,2,8,1 +.???#???.##???? 6,2 +?.????##???#?# 7,3 +???###???.???.??#?. 7,3,2 +?##?##.##????? 5,3,1 +???##???#?##?#?#? 7,1,2,1,1 +#.#?##?#??#???????? 1,1,2,9,1 +.????#???##. 1,2,2 +??#?#.#?#.??. 1,1,3,2 +?????????.?????#???? 3,1,9 +.??????##??#??.. 8,2 +?????.?.???.? 2,2 +??#?.??#?##? 2,4 +???##??#???. 1,2,1,1 +#?.??.?##? 1,1,3 +#?#?#????#?.?????.? 6,1,2,4,1 +.??.???#.?## 1,4,2 +??.?#.???# 2,3 +?#?#???##?????##??#? 10,5 +?##??????###??#?. 11,1 +.???.??.#.???.??. 2,1 +?#.?#???#?####????? 1,2,8 +??.?.??..??? 1,1,1,1 +.??????.?????.?. 4,2 +##?????????..?# 5,4,1 +#????.???? 1,2,1 +??????????? 1,5 +??.#?????#? 1,4 +.#??##?##?...#????. 9,1,1 +??????#???###?.? 5,2,4 +.#????#?#?#.?# 10,1 +?????.?#.??# 4,2,1,1 +???????????. 3,2 +?????.?????? 2,1,1,1 +???#?#?.#.#?? 5,1,1,1 +..#...?##??? 1,3,1 +?..#??????.# 2,2,1,1 +#??????#?????? 3,3 +??????.#??.? 6,3 +?????.????? 3,2 +????#.?????? 1,1,5 +#??#??.#..#?????? 2,1,1,1,6 +.????.??#?#?#. 3,6 +???????#???#. 1,4,2,2 +?#?#?##?.?.?.?..? 7,1,1,1,1 +?#?.?#??.?? 2,1,1 +??#.?????????. 1,1,2,3 +.?.???.?..#?#?##???? 1,1,1,1,7,1 +??..???#???#? 2,4,1 +?##.????#.???????? 2,3,1,1,1,1 +??????.??????? 4,6 +??????#?????? 1,5,1 +.?????##?????.?. 1,1,2,3,1 +?##?.?#?#???. 2,7 +?????##.??? 3,2,1 +???##????..???.? 6,2,1,1,1 +#???.??.?? 1,1,2 +.?.??#?##?????.?? 1,4,2,2 +??.#?.?######? 1,1,7 +.?.???#??????? 1,1,2,2 +??.###.?#??#??##?# 3,10 +.??#?.#?##?.???? 4,5,3 +??#.????.????.#?? 3,2,4,3 +???.##???????????.? 2,12 +?.???#??#????.???..? 1,4,2,1,1,1 +????#??#.? 6,1 +?????#?#????? 9,1 +?#???#??.?????????? 4,3,1,1,5 +?.???#.??????.? 1,2,1,2,1 +#???##.???????.???? 1,3,1,5,1,1 +??????#????#??#?.#.. 3,1,7,1 +#?#.??#??? 1,1,1 +..??????.????? 3,1,1,2 +???#.????#####??#?? 1,1,1,11 +??????#??? 3,1 +#..??.?????????#? 1,1,11 +???#?.??#.?????.?#?? 1,1,3,3,3 +.##..#?????#????? 2,10,1 +.??##?#???..## 7,1,2 +???.????#??? 1,6 +??#????????. 2,3 +.???????#?????? 1,1,2,2,1 +?????..??? 2,1,1 +#?.?#???.??# 2,2,1,3 +???#??#.?????#? 1,2,1,1,4 +???.???.?#?? 1,2,2 +??#??.##.????????? 1,1,2,5,3 +.##??...?????# 4,4 +???????#???? 1,1,2,1 +????.?.#?? 2,2 +???????.???. 1,1,2 +??#????..#? 6,1 +..??#?????? 1,7 +.?#?#?.#?#? 2,2,4 +?.?..??#?? 1,2 +#????????#.????## 3,1,1,5 +#?.?????##. 1,6 +???#.???.?????????# 1,2,1,1,7 +?.?##?..#. 3,1 +??????#???#??? 5,4 +?????.#.??? 3,1,1 +.?????##???? 2,7 +?????#???#???#.????? 3,6,3,1,2 +?.##???###?.???? 9,2 +???.??#??###?. 1,8 +?#.??###?.??... 2,4,2 +..?.???????#?##?# 2,2,6 +??.???###?????? 1,6,1 +??##?#????# 3,3,1 +##?#?#???#?????# 4,2,3,2 +?#?.#?#??.??. 1,1,3 +#??...???? 2,1,1 +??.??#?????#.# 1,7,1 +.?.?#?#?#? 1,6 +?.?##??????.#?? 8,1 +???..?.????#? 1,6 +?.?#??????????? 1,12 +??????????##?.??.. 1,2 +??#.??????????#???? 3,3,6,1 +.???#.?????.?.??#? 2,1,1,2,1,4 +?????#????? 5,3 +##?????.?##? 7,2 +##.??????.?.#??. 2,3,1,2 +?#??#???#.#???? 2,1,1,1,1 +.#.?..?????.. 1,5 +???.#??????.? 2,3 +?????#??..?###? 1,2,1,4 +?#?#????????????# 1,3,1,5,1 +??..#??#?.???#??.?? 1,2,1,5,1 +??.??#???##?.?? 7,1 +?????#?????#?? 2,3,3 +?#??#?#??##???#?? 1,2,6,2,1 +???????#???#???# 2,1,1,2,3 +???..????#### 1,1,7 +??#?????????#?.??. 3,4,2,1 +..????#????#??#?#? 1,8,3 +?.?#?.???#???? 3,2,1,1 +#?#?.#???????.? 4,1,1,2 +##?##??####.????#?.? 11,6 +?#?????#??#.?#??.. 2,7,2 +?#?.??????? 2,4 +??????..#??.??? 3,2,1 +.???#??#.??? 5,1 +??#??#????.?? 7,1 +#???#?????.?????.?? 7,1,1,2,2 +??#??#???.#?.#. 2,2,1,1,1 +????#?#?##??#?.?.??? 9,1,3 +?.???#??.##?#?? 1,3,4 +#????.?#?#??. 3,4,1 +??#?????.??.?. 5,1,2,1 +???##??????#??? 9,3 +?????#?#??#????? 10,1 +?.?.#?????.?????#? 1,1,4,5 +??.????#.#?#?.#?#??# 2,2,2,3,6 +??????..?###.???# 4,4,1,1 +?#.?#??????? 1,6 +???????#?? 4,1,1 +???#?????#????? 1,2,1,1,3 +??.#?####???##?#? 1,1,11 +???##?????.# 6,2,1 +??##?#.?#.? 5,2 +?#????.##???.# 5,2,1,1 +????????????????#??? 1,1,5,3,3 +?????#?????#????#??? 3,8,3 +.???.?##?? 1,1,2 +??#??????????????## 5,4,1,4 +?..??#.?????.#?.# 1,3,2,2,1 +??##?.???#?##???? 4,7 +??????#??#.? 1,3,1 +?#?????##? 3,2,2 +?..?????.?.?#.? 3,1 +????#?.??#? 3,1 +#.??##?????#?## 1,4,6 +.?.??#????#?..#?# 1,9,3 +.?.??##????#??. 1,8 +????#???##.????????. 6,7 +?.????##??#???##. 1,3,6 +??#??#???##. 2,1,2 +??.??##??#.????..# 1,5,1,1,1 +?????????.??? 7,1,1 +?.????????? 1,3 +??#???#?#??? 3,3,1 +?????????? 3,2 +???#??#????#???#? 4,1,1,2,1 +???#?#.?.?.??????#? 5,1,1,6 +.?#.??##?#?##????? 1,1,12 +?????.##??? 3,2 +?.?.?????#?# 1,2,3 +.??????##??##??#??? 1,8,2 +..???..????????.???? 1,1,4,2,1,1 +?#????.?#???#??? 2,6,2 +??????????????????? 1,1,7,4,1 +???#??.???? 3,1 +#.??#???.. 1,1,4 +#??#.??.????. 1,1,2,1 +?????#?####????? 10,2 +?.?.???##?#.?.??#?. 4,1 +????.?#.????#?# 2,1,5 +.##???#?#?.??.?? 9,1 +?#??#???.. 4,1 +?#?#???????.?#?.??.? 8,2,1,1 +?????.??????#???##? 1,12 +#?#?.???????? 4,6 +?.????###???? 1,6 +.??.#??.#?? 1,3,2 +.##?..????#?? 3,1,2 +?#?.#?..#??.?? 2,2,2,1 +#?..???#?#. 1,4 +??#???#?#???...#? 9,2,1 +??#????..#?#?#?? 3,7 +?.??##???#? 6,1 +.???#???????? 1,2 +?##?.#.?#???#?.??#?? 3,1,3,2,4 +?.?####.????????? 5,6 +???.##??#??#?##?. 2,2,1,5 +???.#??##?.?#.?? 1,6,1,1 +?##???????. 6,1 +.?????????#??? 2,2,1,1 +?#??.????##??#. 3,8 +.???????.?#?.????. 5,2,4 +?#??#.??.? 1,1,2 +?.?.##?.????. 1,1,3,1 +..#..?.?.?.?? 1,1 +#???.?????.???? 4,1,1,1,1 +?????.#??.???? 4,3,2,1 +?#?###?#??.?? 1,7,1 +???..???###??????### 1,1,2,12 +.#??????#??.#.??.?? 1,2,2,1,1,2 +#???.???.?.??###??? 2,1,1,1,1,4 +.#?????#??????#??.. 1,6,5 +?#???#?#??? 2,5 +??????.?.????????## 3,1,10 +#??.?#???????. 3,2,4 +??????.#.?#?#??# 4,1,1,1,1 +.?????.??#???????#.? 1,9 +#???#?##????.??? 3,1,5,1,1 +??????#.??? 1,3,1 +?#?.##?..?? 2,3,2 +#.???##???#???? 1,11 +#??#????#? 2,2,3 +????#?.#?.?#?##??? 5,2,1,5 +????#.?#???? 1,3,1 +?.#??#??.?.#??##.?? 5,5 +??..??#?.???????. 1,3 +??????#??#?#?.#?? 11,1 +???#???????? 1,1 +#??#??#??#.?????? 1,4,2,2 +??.#?????#?? 3,3 +??#?.?.????? 3,1,4 +???#???.??##?.?#?.? 2,3,2 +.??#?#?.?.##? 5,2 +???#.???.#??????#?? 1,2,2,1,3,4 +.???#?????. 4,1 +???#??#.?#??#??#??? 1,1,1,3,7 +#?.?.???#??# 1,1,3,2 +??##?????.###??#??? 3,1,9 +????##????. 3,2,2 +?.????#?????#??#?.?? 1,5,2,1,3,1 +..?#??????? 2,5 +#????#??..??##### 4,1,1,7 +????###????..#??.?? 4,2 +????#?##?##. 2,2,2,2 +???#?.???????? 4,6,1 +???##??????????? 4,6 +#?#?#.???#.???.?.??# 5,1,1,1,3 +??.???.?##.? 1,2,3 +??#??#????.?? 2,1,1,1 +?..???#???.?#?? 2,1 +???#?.??#??????#??# 4,4,4,1 +?????#?#?????..????? 8,1,2 +?.??#????#?#?????#?? 6,4,2,2 +??????.#?#?#?????. 1,1,1,10 +#??????#??? 1,2,1 +????.????? 1,1 +.#??#?..#?..???.?? 5,2,1,1,1 +?##?.???#??.??? 4,3,1 +.????.??????#? 2,1,5 +?????????##??? 2,6,1 +.??.?.#????. 1,1,2 +.?????.?.... 1,1 +????.??.???##..?##?. 2,5,4 +?#????.????.. 2,1,4 +????.#.???#?#??#.??? 2,1,1,6,2 +?#???.?..??? 3,2 +???.????.???.??????. 1,2 +..??#??#??##?? 1,2,2,4 +?????..???#?##?.? 2,7 +###??##??#?#?? 3,9 +??.?##?#?###???#?. 1,9,2 +?????.???.?? 1,1 +.??.???.#.#??????# 1,1,1,6 +?#?#???#???#???##.? 1,14,1 +##????.?#?#.#.????#? 3,1,4,1,1,1 +?#??#?.#?#?#???# 4,5,1 +#.?#?????#??? 1,7,1 +????#?.????? 2,2,1,1 +??##???#???????? 3,1,1,1,5 +.???????#?????. 4,4,1 +?.?#??##?? 2,2 +?#??.?????#.? 2,6,1 +?##?#..?#? 5,2 +??#?#?#?????# 3,5,1 +?.#????##...??#.???? 1,5,2,1,2 +.???????#.?? 8,1 +##.?#.????? 2,1,1 +#.?#??##??? 1,8 +????????????.## 1,4,2,2 +.#????##??...?.?.? 1,1,4,1,1 +???#???.?#? 3,1,1 +????????.#???????.# 1,1,1,4,1,1 +?#????#???#??.???? 8,3,2 +??##.?????#?. 2,4,2 +?#.?#???.?#???#?. 1,2,2,1,2 +??.??#?????.??# 1,6,1,1,1 +.?????#????#?????? 2,9,1,1 +???.???#???#. 1,6 +???#?..????? 2,1,3,1 +.?#?..???#??????? 2,9 +???#??.????#????? 6,8 +.????????##?????# 2,13 +?#????.?#??????. 3,2,4 +..?????..??#.? 5,3 +?#?##???##??#??..?# 1,11,2 +???#??##?.?##??? 6,5 +?#????#?????#.? 1,3,1,1,1 +#.#??????#????#. 1,1,8,1 +???.?#????? 2,2,1 +??.?#??????.?? 1,7 +.?#.????#?.? 1,1,2,1 +.??#.?#??#?????# 2,5,1,1 +??#.??#???.?##???? 3,2,1,6 +??##????#???#????? 8,1,1 +###?##??#.?.#??? 7,1,1,1,1 +?#?#?????#?.? 4,4 +?##?..????.??# 4,2,1 +..?#???..#? 3,1 +#?###?????? 5,2,1 +??.??..??????????? 2,5 +?#???????? 2,1,1 +??#.???#?#?# 1,3,1,1 +.??????#.?. 2,2,1 +..?.?.??#? 1,3 +?..???##??..???#??? 6,4 +?.##.?#??#??? 1,2,7 +???.?.#?#?? 2,1,5 +?.???#?#?? 1,6 +????.??#?..?? 4,4,1 +????.?#??? 4,2 +?.????.?#??#? 1,2,1 +#????#???#?#?#??? 1,5,3,1,1 +?????.??.???? 2,1,1,1 +????#??#????# 2,5,2 +??#???#?#?????.#? 1,7,1,1 +?#..#??.???#???? 1,1,1,3,1 +..??#.?????.???? 1,1,4 +.??????##??#?? 4,6 +??.??#?#???#??? 1,7,1 +#??#???#?#?????????? 6,3,2,1,1,1 +#??.???.?#.?.?#? 3,1,1,1,2 +???#??#?#? 3,3 +??????#?.?.?????.? 7,1,2,1,1 +??????.?#??.?????? 4,2,3 +?#???.?...???????#?? 1,1,1,1,1,5 +??.????.??? 1,4,1 +?###????????????#??? 11,7 +??#???.#?#.???#??# 1,2,1,1,1,6 +??????#?.??????#?#?# 1,1,3,1,7 +????.?????? 3,1 +????#?#?#.?##?? 2,5,3 +???????.#??? 3,2 +?#?????#??##?? 2,5 +????..#??.???? 4,2,4 +???????????? 8,2 +?#??.?????????#??? 3,1,1,4 +.??#?.????? 2,1,1 +??????.??.????.??# 6,1,2,1,2 +??????.?.?#?#??#???? 1,2,1,3,3,1 +??????.???#?. 5,2 +#.?.?#???????.??? 1,1,3,2,1 +?##????????.??# 5,1,2 +???.???#.. 1,1,4 +????..?####?#???. 4,7,1 +??.?.?.??#.#??. 1,1,1,1,2 +.???#???#??????.??? 13,1 +???##.####.?# 2,2,4,1 +????#?.#.??#?????? 3,1,6 +..?.??????#???.. 1,10 +??##?..??..#?? 4,2,1 +????##?#???#? 8,1 +??#???#.???.?????? 2,2,3,6 +?#..??.?#????. 1,1,2,2 +???.?..??##?????.? 2,7 +?????.??.? 1,1,1 +?????#?.?#??????? 1,2,7 +??##????#?????????? 3,1,3,1,3,1 +?..??.????#??? 1,3 +????#??#?#??#???? 9,3 +????.?#?#####???.?? 1,2,9,1,1 +#????#??#?#.?????? 2,1,6,1,2 +??????????.?? 1,6,1 +?????????.??.?.??. 6,1 +?????#?#???#??? 2,9 +#?#???##??#?????? 4,4,1,2 +?????.###?#?.????? 3,3,1,1,1 +#??.??#?#???????. 1,1,1,10 +??###?????? 5,2 +?????#?????..?.?#??? 9,1,1,2 +????.????#????? 1,10 +.???.?#??#???? 1,6 +??#?????#?.?#?##? 2,1,4,5 +???????.#?#??.? 5,5 +???.???#.??#. 3,1,1,2 +?#?#??#?#?????.?#?.. 12,1,2 +??#????#?. 2,3 +#?#?????#.? 3,1,2 +.?.#????#.???. 1,4,3 +.??##.?#??.#?#.. 1,2,3,3 +?#???.??##??##?.?.?? 1,1,9,1 +.???#?????#??? 5,2 +.??#???#????#?#..? 3,8,1 +.?????..???#??#???? 2,10 +?#?#?#.?#.?? 5,2,1 +??.???????????#??## 1,3,4,2,2 +?.??.??#???#?.?.? 1,1,4,2,1 +.#????....#?. 3,1,2 +..?.?###..????##??? 4,3 +?.?????#?????#????#? 13,1 +.?#????#?? 3,3 +.#?????.?????#?#?? 1,2,1,6 +....??#..?#?.???? 1,1 +#?#?.???##? 1,1,5 +??.?.##..? 1,2,1 +?.?.??.??.?#?#??. 1,1,2,1,5 +?.?????.?? 1,3,2 +?#????????.? 3,1,1 +##???##???????#.? 7,5 +#..???.??# 1,1,2 +.???.?????.?? 1,3 +??.#?.????? 1,1,2 +?????.#??#. 1,4 +?#???#..?#?# 2,3,2,1 +?????#???.?. 5,1 +.#??#???#. 1,5 +.?#?##?????#?#.?? 1,4,2,1,1 +.#??????#?????.. 9,2 +???#?...???#??#??#? 3,10 +??#??###?#?????#?? 12,2 +#?##?.???? 5,2 +???.?#???#???? 3,1,5 +?#???##??.????? 2,4,2,1 +.???######??#?? 1,10 +??##??#??###????.??? 12,2,3 +.???..??#???? 2,4 +??#?##?#.?#?#??. 1,1,4,1,1 +#.??#???????## 1,5,5 +?.???????##?#??.#?.? 8,1 +???.#???.?#?? 2,2,1,4 +?????????#?##?..# 1,11,1 +??#.???????? 2,2,3 +???#?#???? 1,3,1 +????#?.##?? 1,1,4 +.?#?????##??#??? 3,6 +#?????.???#? 1,2,4 +?????.?.##????#?? 1,2,8 +?????.#????#????. 1,1,2,5 +??..????#?#???.? 1,1,5,1,1 +?#.???.?.??. 1,1,2 +?#???.#..?#??#?? 1,1,1,2,2 +.??????????? 2,2,1 +?.???#?.#?? 1,4,1 +.??#??.##???.. 3,2,1 +???.?.???????.?#? 1,1,5,3 +??#?.######?? 3,6 +???.???.?.??????#??# 2,3,1,2,4,2 +????..?#.. 1,1,2 +??.?#??.?.#?#????? 2,5 +.???..??#??#?#?##.?? 1,1,1,1,7,1 +?.?.??#??#??#? 1,1,8 +?#?##???.??.. 7,2 +.??????#??? 4,1,1 +#..???#??#??#?#???? 1,1,5,1,1,1 +#?.?.?????#..?#?? 2,1,6,2,1 +??#??.?#??.#?#???? 2,2,1,1,2,1 +???.?#.#??#??#? 1,1,7 +?????##?#?? 2,6 +?.??#??????? 3,1,1 +??????#?###???. 5,1,5 +#???.?#??#?#? 4,1,2,2 +??.?#.???? 1,1,1 +??.?.????#.?#??# 1,1,1,2,4 +?#.??.??##??# 2,1,1,5 +??????#??? 1,2 +.???###???..?? 7,1 +?.?????##????#?. 6,2 +.??.#??.#?.?????? 1,2,2,4 +?##???????#????????. 3,10 +?????#.???.###????.. 3,2,1,7 +??.??????? 1,2,1 +????#???..????. 7,3 +#.???##..?#?#??#??#? 1,1,3,11 +??##???###?#..#?? 12,3 +?#????.??????.? 5,2 +#.?####??.?.????? 1,5,1,1,3 +?????#???. 2,2 +#????.?.???#?#??#? 2,1,1,9 +?.?##??##??..??????? 9,4 +.???.????.???????? 1,4,3,1 +??..#.?#?? 1,1,1 +###???#.?#.?####.??? 7,1,5,2 diff --git a/2023/input/12/test-1 b/2023/input/12/test-1 new file mode 100644 index 0000000..e925935 --- /dev/null +++ b/2023/input/12/test-1 @@ -0,0 +1,6 @@ +???.### 1,1,3 +.??..??...?##. 1,1,3 +?#?#?#?#?#?#?#? 1,3,1,6 +????.#...#... 4,1,1 +????.######..#####. 1,6,5 +?###???????? 3,2,1 diff --git a/2023/src/bin/day12.rs b/2023/src/bin/day12.rs new file mode 100644 index 0000000..944f069 --- /dev/null +++ b/2023/src/bin/day12.rs @@ -0,0 +1,233 @@ +#![feature(test)] +use std::{ + collections::{hash_map::DefaultHasher, HashMap}, + hash::{Hash, Hasher}, +}; + +use anyhow::Result; +use aoc::Solver; + +// -- Runners -- +fn main() -> Result<()> { + Day::solve() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn part1_test1() -> Result<()> { + Day::test(Day::part1, "test-1", 21) + } + + #[test] + fn part1_solution() -> Result<()> { + Day::test(Day::part1, "input", 7674) + } + + #[test] + fn part2_test1() -> Result<()> { + Day::test(Day::part2, "test-1", 525152) + } + + #[test] + fn part2_solution() -> Result<()> { + Day::test(Day::part2, "input", 4443895258186) + } + + // Benchmarks + extern crate test; + #[bench] + #[ignore] + fn part1_bench(b: &mut test::Bencher) { + Day::benchmark(Day::part1, b) + } + #[bench] + #[ignore] + fn part2_bench(b: &mut test::Bencher) { + Day::benchmark(Day::part2, b) + } +} + +#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)] +enum Spring { + Operational, + Damaged, + Unknown, +} + +impl Spring { + fn convert(c: char) -> Self { + match c { + '.' => Self::Operational, + '#' => Self::Damaged, + '?' => Self::Unknown, + _ => unreachable!("Invalid input"), + } + } +} + +impl std::fmt::Display for Spring { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Spring::Operational => write!(f, "."), + Spring::Damaged => write!(f, "#"), + Spring::Unknown => write!(f, "?"), + } + } +} + +// The cache is optional as is slows down part1 by a lot +fn count_valid( + springs: &mut [Spring], + list: &[usize], + damaged_chain: usize, + cache: &mut Option<&mut Cache>, +) -> usize { + let hash = if let Some(cache) = cache { + // Calculate the hash manually, otherwise we end up with weird borrows or we have to clone + // (which is slow) + let mut hash = DefaultHasher::new(); + springs.hash(&mut hash); + list.hash(&mut hash); + damaged_chain.hash(&mut hash); + let hash = hash.finish(); + + if let Some(&value) = cache.get(&hash) { + return value; + } + + Some(hash) + } else { + None + }; + + // We reached the end of the list, no further processing is possible + let count = if list.is_empty() { + if springs + .iter() + .filter(|&spring| spring == &Spring::Damaged) + .count() + > 0 + { + // There are still damaged springs remaining + 0 + } else { + // There are no damaged springs remaining + 1 + } + } else if springs.is_empty() { + // If there is one last entry in the list, check if it maches + if list.len() == 1 && damaged_chain == list[0] { + 1 + } else { + 0 + } + } else { + match springs[0] { + Spring::Operational => { + if damaged_chain == 0 { + // The previous entry was operation, skip over this entry + count_valid(&mut springs[1..], list, 0, cache) + } else if damaged_chain == list[0] { + // We reached the end of a chain and it has the expected length, start working on the next chain + count_valid(&mut springs[1..], &list[1..], 0, cache) + } else { + // We reached the end of a chain and it does not have the expected length + 0 + } + } + Spring::Unknown => { + // Replace unknown with operational + springs[0] = Spring::Operational; + let a = count_valid(springs, list, damaged_chain, cache); + + // Replace unknown with damaged + springs[0] = Spring::Damaged; + let b = count_valid(springs, list, damaged_chain, cache); + + // Reset spring back to unknown + springs[0] = Spring::Unknown; + + // Return the sum of both branches + a + b + } + Spring::Damaged => { + // Add to the damaged chain + count_valid(&mut springs[1..], list, damaged_chain+1, cache) + } + } + }; + + if let Some(cache) = cache { + cache.insert(hash.unwrap(), count); + } + + count +} + +type Cache = HashMap; + +// -- Solution -- +pub struct Day; +impl aoc::Solver for Day { + type Output1 = usize; + type Output2 = usize; + + fn day() -> u8 { + 12 + } + + fn part1(input: &str) -> Self::Output1 { + input + .lines() + .map(|line| line.split_once(' ').unwrap()) + .map(|(springs, list)| { + ( + springs.chars().map(Spring::convert).collect::>(), + list.split(',') + .map(|num| num.parse::().unwrap()) + .collect::>(), + ) + }) + .map(|(mut springs, list)| count_valid(&mut springs, &list, 0, &mut None)) + .sum() + } + + fn part2(input: &str) -> Self::Output2 { + input + .lines() + .map(|line| line.split_once(' ').unwrap()) + .map(|(springs, list)| { + ( + springs.chars().map(Spring::convert).collect::>(), + list.split(',') + .map(|num| num.parse::().unwrap()) + .collect::>(), + ) + }) + .map(|(springs, list)| { + ( + [ + springs.clone(), + vec![Spring::Unknown], + springs.clone(), + vec![Spring::Unknown], + springs.clone(), + vec![Spring::Unknown], + springs.clone(), + vec![Spring::Unknown], + springs, + ] + .concat(), + [list.clone(), list.clone(), list.clone(), list.clone(), list].concat(), + ) + }) + .map(|(mut springs, list)| { + let mut cache = HashMap::new(); + count_valid(&mut springs, &list, 0, &mut Some(&mut cache)) + }) + .sum() + } +}