From 0a4ce052ee781596b99482443005a337fcc1840a Mon Sep 17 00:00:00 2001 From: Dominic Date: Tue, 12 Dec 2023 18:02:07 +0100 Subject: [PATCH] day 12 part 1 --- inputs/day12.txt | 1000 ++++++++++++++++++++++++++++++++++++++++++++++ src/bin/day12.rs | 109 +++++ 2 files changed, 1109 insertions(+) create mode 100644 inputs/day12.txt create mode 100644 src/bin/day12.rs diff --git a/inputs/day12.txt b/inputs/day12.txt new file mode 100644 index 0000000..3f636a6 --- /dev/null +++ b/inputs/day12.txt @@ -0,0 +1,1000 @@ +?#.?..?.##.###? 2,1,2,3 +??????##?.? 2,5,1 +????#??.##????? 1,3,7 +????????#??? 2,3 +?#.?.????.#????#?? 2,3,1,4 +????.??.#?#? 2,1,4 +.#.#?#?????# 1,5,1,1 +.??.??..#?#??#????. 1,1,1,1,6 +#??####????..#??? 7,2,1,1 +?#??#????????.???? 4,2,1,2,2 +..?.???.#?.#? 1,1,2,1 +#???#??#??##? 2,1,2,4 +?#???#??#.??# 1,1,2,3 +?..??????# 1,5,1 +.?.#??#????. 4,1 +????#??##.????? 3,5,2,1 +?###.?#???????#??? 4,2,1,3 +?.???#??...? 1,5,1 +?.#??????##?##???? 2,10 +.###?????#??#?. 4,1,2,2 +.??#????#..?.?# 3,1,1,1,1 +.?#?#.?????#?.#? 4,1,2,2 +.??.#?###?#???.#? 1,9,2 +?????#.??????. 4,1,1,3 +???#????#??.??#?# 3,3,4 +??..?#..?..? 2,1,1 +?.???#.?#??#? 1,1,1,6 +????#????????#?#?? 10,4 +??????#?#??..#?. 1,1,7,2 +.???##??.??#??.? 4,1,3,1 +.???#?##?.??? 6,1 +????#??##??.????#. 2,5,5 +??????.???????? 1,1,1,1,1 +???.?#??#??#? 3,4,2 +.????#?##??.? 8,1 +???#?????####?#???.? 1,9 +?..???#??? 1,4 +?#???#?#?##.. 2,6 +?.???#????##???#??.# 1,1,1,1,9,1 +?.???#?###?.?..???? 8,2 +#???.?##???.???? 2,6,2 +.#.??####?##?.?#? 1,7,3 +##??#???###?#??? 5,1,3,1,1 +??#???##???????..??. 13,1 +???.#.?????? 1,1,4 +??????#???????? 2,5,4 +??????.??#? 2,1 +.?.????.???. 1,1,1,1 +???.??##..?.?????.? 1,3,3 +#?####???? 1,5 +?.??.???.?????? 1,1,2,4,1 +...#???????#??#?? 2,1,7 +.??#??.#?#.????# 3,1,1,1,4 +?#??#???##???#???.?. 1,7,1,1,2,1 +.??..##??#?#?#????? 2,2,2,1,1,1 +.???#???..??.#???? 6,3 +??.###.??. 3,1 +??##???#???.?. 7,2,1 +?.?.?#??#. 1,1 +#??###?.???#????#? 1,5,8 +#?##???#??##??#?? 4,10 +?#??..?#??##?????. 1,11 +???#.???.??##?. 4,3,1,3 +.?#?.?#.??. 2,2,1 +??.??###???.??????. 6,2 +??#??#.??????? 6,5 +..?????.??? 5,2 +?..?#..???. 1,2,2 +???#??#####????.#? 13,2 +..??#???#??.??? 3,3,1 +.?#????#????????#?# 1,1,1,1,1,6 +??????????. 1,3 +.?##???.?.??????? 2,1,1,1,3 +??..#?#???# 2,1,5 +#????#?##???#? 1,10 +??#?#?#?.. 5,2 +??#?#?????...??? 1,1,3,1,1 +??????#????? 1,1,6 +?????.??????..? 2,1,1,1,1 +??#?.#..?#? 2,1,2 +??.?##?.??.#?. 4,2 +.?.??#.??#? 1,2,1 +#???###????##. 1,1,9 +??##.?????###?????.? 2,7 +??.?#??#???##?..?## 1,5,3,3 +.??#??.?#?????#?#??? 2,9 +??#????????? 1,4,2,1 +.?#??????#??? 2,6 +..?????##?.#? 3,3,2 +?????.?#?#??? 1,2,1,3 +??#????##.. 2,1,2 +?????.????#??. 2,5 +##??###???#.# 2,4,2,1 +????#?????????#??.?. 3,10 +#..????.???#?????# 1,4,1,1,2,1 +??..????#?????? 1,2,2,1,2 +..???????????#??#??. 1,3,3,1,2 +???##?????.??#?????. 2,7,1,3,1 +?#?#??.?????# 1,2,6 +???????#????? 1,3 +.???????.???##? 3,5 +.?#???#????#? 1,2,1,1 +?###???#.??????#?? 4,1,1,1,4 +.?#??..?#??.?? 4,1 +?????#?#???#???.??.# 1,6,3,2,1,1 +.?#??????.??. 4,1,1,1 +?????#?????????? 2,2,5 +?????.???. 5,1 +..#????#?##?##?. 1,8 +?????.?..??. 4,1 +????.????.?#??#?? 1,2,5,1 +.??.?.???... 1,1 +?#.??##?#? 1,2,1 +?????#?..??##? 3,4 +.?????##??..??##?? 9,4 +.??#??.??? 3,1 +?.??#?..??.? 1,1,1,1 +#?.#????##?.?. 2,2,4,1 +??#..??.??.??? 1,1 +?.??.???#?????#? 2,2,1,6 +??#.?.??.? 1,2 +?????...?? 3,1 +??###????.?????? 8,3 +?????????????. 4,5 +??.????.#??.#??. 1,2,1,2,2 +??????#??#???#?#?. 1,1,5,5 +?##?#?????.?.#?.## 7,1,1,1,2 +???????#??.#.????.?? 1,7,1,1,1,1 +?????.?#?##?. 1,1,1,3 +??????.??? 1,2,1 +#??????#????? 3,1,2,3 +.??#??##??.??.?? 8,1 +.#???.??.? 2,2 +?#.#??#??##???????? 2,1,7,1,1,1 +?.??#??#??????? 1,1,3,2 +?.??????.? 2,2 +?.#.??.???#?????#??# 1,1,1,12 +?????.?#?????????.?. 1,2,1,4,1,1 +?????####???#???. 3,4,4 +????.?.??? 2,3 +#??????#?#???. 1,8 +?????#???.?## 7,2 +???.?.??#?# 1,1,4 +??????????????#???# 1,1,8,1,3 +??.??.?.??#?#?#??#? 1,1,1,10 +?##??###?#?.?..???? 3,6,1,4 +????.?.????##?? 1,7 +??.???????????.??? 1,1,1,5,1,1 +#??#?#?..#??#?#?#??? 1,1,1,9,1 +???.????.#?.??? 2,2 +???#.??##?? 2,2 +?#?.??????.???#??##? 1,1,2,1,7 +???.#.?#??#??##. 1,1,2,1,3 +????????#??. 2,6 +??#???#??##????.?# 9,1,2 +??????###?#.??.?#??# 1,9,1,1 +?.????.?#?? 4,2 +??????##??? 1,5,1 +#?#?##??##?????#?? 12,4 +##?.??#?#? 2,3 +.??#?##??? 6,1 +?????#??###?#?.??.?# 12,2,1 +.#???????.#?????.??. 8,2,3,1 +??????????.# 1,1,1,1 +?????####?.???#??? 10,1,2 +?.??.????????. 2,4 +?????#..???#?? 5,1,2 +?.??..???#???##?? 1,7 +????..?#???#? 2,1,3 +?#?#?#?.?#. 6,1 +?#.?#..#??##???. 1,2,6 +.?#????#.? 2,1 +.???#?..?.??? 4,1,1 +??#?.?#?#????#? 2,6,1 +#?????#?????####??.? 2,14 +???##?..?#.? 6,2 +??#?????#?#? 2,1,1,1 +?.????.#??#?. 4,1,1 +?#??.?#?#?#????.??? 3,9,1 +??????##?????.?. 11,1 +??.?.???#?. 1,3 +???#?.?#?##? 4,6 +?????#???#.##??# 4,2,5 +?.##???????#???#? 3,6 +??#???.#????? 2,1,1,1 +?#???????.?? 1,1,1,1 +?????.#.#? 2,1,2 +#?#??##????#??#. 1,7,2,1 +#???????.??.?.??.? 8,2,1,1 +???.?#??????#?#??#? 2,7 +????###???##???.. 1,4,3,1 +.??????..?. 1,2,1 +??.??.??????##?#???? 1,10 +????????#????? 3,5 +#????#??????#??? 4,4,1,1 +.?..#?#?...???? 1,1,2,4 +?#???.????.?# 3,2,1 +?..#?##???# 4,3 +##?.#???#?#?#.??? 2,9,2 +???.??????????# 2,4,1,1 +.???.???????? 1,4 +?.???#???#?? 3,4 +.??#??..??? 5,1 +??#?#?#???#? 5,2 +??????.?????#??# 1,3,2,1,1 +.??#??#?.??.???????? 1,5,1,1,1,1 +.???????#?## 1,1,1,5 +.????????? 4,1 +?..#?.?##?.??? 1,4 +??????????##?????#? 1,4,3,2 +?.#?#????????#?????? 1,8,1,4,1 +..?#??.??? 3,2 +##.#??#?#? 2,1,4 +???.#??#???#.#? 2,1,2,1,1 +???????#.?# 1,2,1 +..??????#???? 2,6 +?????#?##??.##?. 1,7,2 +?#??#????#??? 5,6 +??..#?????.?? 1,5 +.??.?.????????#??? 1,1,4,1,2,1 +?.??????.?.??? 2,2 +???#?.#.??? 2,1 +.???#??.??#???.????? 1,1,1,1,2,5 +?#.???????????#???# 1,5,2,6 +#???##.???#???.?#? 1,3,5,2 +#?..#.??#????#??? 2,1,1,3,1 +???..?#..?. 1,2,1 +?##???.???##???#?? 6,9 +??????????#? 1,1,1,1 +?##??##?#..?#?#? 9,5 +#..??????? 1,5 +.?????##???#? 1,7 +##?#????#.#???#?.# 9,1,2,1 +?????#.???. 3,1,2 +?#?????#?##??.#???. 4,2,2,1,1,1 +???#?#??#??????????. 11,2 +?.?.?????##??... 3,3 +.?.#?#?????#? 1,5,1 +?????????#???.?? 1,1,4 +?#??#?.##? 2,1,2 +.????.#??#?. 1,5 +?#?#??..????? 1,1,3,1 +?#?##??#.?.??? 5,1,1 +??##??.?#?????????#? 4,1,2,1,1,1 +?#?#?#???# 6,1 +???.??????????? 1,2,2,1,1 +###???.#?.??? 3,1,2,1 +.??.??.??#??.? 1,1,4,1 +??.??..#?.?. 1,1,2,1 +#?..??.??#??.? 2,2,5 +?#?#???.#?#??. 3,5 +?.#..?#???#????????# 1,7,3,1 +..??.?#???? 2,2,3 +.?..#?#??? 1,6 +##??#?.?#???.? 5,1,2,1 +??.?.?#.???#?#?. 1,1,2,5 +.?..???.?? 1,1 +???###?##???#?##?? 4,4,1,4 +?????#?.????###.? 1,1,1,7,1 +?#.??#?.????##.#.# 1,1,1,6,1,1 +???#?#????.?.?.???#. 5,2,1,1,3 +.????#?###??#? 1,1,4,1 +???#.??#?? 2,2 +?????#?.?#?.. 1,5,3 +?##????????. 3,2,1 +?????..?##??????. 1,5 +?.?#..???#?# 2,3 +????...???.##.#???? 1,2,1,1,2,3 +.????????.?? 1,1,1,2 +???#?#?#?#. 4,3 +?#??.#.???#?#??.? 1,1,1,8,1 +?.??????.#?. 2,1 +.??..?##???? 1,3,2 +.??#???##?## 2,5 +??????.#?. 4,1 +#.????#???#??????#?# 1,1,1,1,1,7 +???##?..???#?#?. 5,4 +..#??.?..??????#??? 1,5 +?#?.???#???? 2,1,1,1 +.?????#?.???? 1,1,1 +?.???????. 1,1,2 +#?????..?? 3,1,1 +#?#?#??#??#?#???#?#? 1,6,10 +..?####?##?????..??# 9,1,1,1 +?#??????????#??????? 4,1,1,3,3,1 +?????.??#? 2,1,3 +??#???##.?#??? 8,4 +?#?.?????. 2,1,1 +??.????##??#? 1,8 +#.????.??????.? 1,2,1,1,1 +?#?#??#.???#?###.? 3,1,6 +????????#??.????? 1,7,1,1 +??????????????? 4,5,1 +?##.?#???#?#?..?. 2,9,1 +????.??????#.???#. 3,5,1,1,1 +?#?.???..?? 2,3,1 +??#..??.??.??#???? 3,1,2,5 +?#?.????.?#? 3,1,1,2 +??????????#??? 1,6 +???????.?#.? 3,1,1 +????????##?. 2,2 +##???#??.. 4,2 +.?#????#?.?...? 4,1,1 +#???.?#?????????#??? 4,2,4,1,1,2 +#??.????#??#?.# 1,3,2,2,1 +?.???????##?#??????? 5,6,1,1 +???.????.##?#???.? 2,5 +??#?#.??.?? 5,1 +??.??????##.#?# 1,1,3,3 +?.??????#.??##?#? 1,4,1,5 +??????#???.??????. 4,2 +????##?.??#??. 5,3 +##???????.??.#? 5,1,1,2 +?..?????.??#??? 1,1,1,5 +??????####???#????? 12,2 +????.???.??? 1,1,1,3 +#?#???????#?##?? 4,9 +???..?.????? 1,1 +#??.??#??????.? 2,1,4,1 +#???#?##?##???????. 1,5,2,1,1,1 +??????#?##?????? 1,8,1,1 +?????.???#.?? 3,2 +???#??##??#?? 1,1,7 +.?#??#???.?. 5,1 +????#?##??#?#???.??? 10,1,1 +?????.#??? 2,3 +#?#?#????## 1,3,3 +??..??#??. 1,3,1 +??#?.??#..?.?? 3,1,1 +??????.?.???. 2,2 +.?????????... 1,1,2 +?.?.???????? 1,1,3 +??????#?.??##.??? 5,2,3 +?##?#???.?????#? 4,1,6 +?#???..??.??#? 3,1,2,2 +??#?????.??? 5,1 +????#?#?????? 5,1 +??????##?.??? 2,2,1 +???#??#??? 5,3 +..?.?????.??#?#???#. 1,4,1,5,1 +?.##???????.?? 6,1 +..???.????#???#???? 2,7 +????#.?#.. 4,1 +?.?.#??##????????? 1,1,5,3,3 +?.??#?#???#...?#?## 1,8,4 +.???#??..#??????? 1,3,3,4 +?#???.#?#???.?#.??# 5,1,2,2,2 +??#??#.?#???#??.? 2,2,1,5 +?.????#?.???? 3,1 +?.#?????#????#??? 1,2,3,1,4 +.????#..?#????.#?# 1,1,1,3,1,1 +#??????.?? 4,1,1 +.?.?#?#??.?.?? 5,1 +.#??#?????#?..??? 1,5,1,1,1 +.??#?.?..? 1,1,1 +#?##.??????##?. 1,2,7 +.#??##???.????? 1,3,2,1,1 +?#.?#..??.? 1,2,1 +?#???...?# 4,1 +####???#?????#???? 6,1,1,6 +???#?#?#?????#.?. 1,3,2,3,1 +??????.??????? 6,1,4 +?????????????? 6,1 +???????#??? 1,2 +.?##???..#?? 5,2 +????.#..???????? 3,1,2,1,1 +?????.??#??.???.?? 2,1,3,2,1 +##???.#???.????? 5,2,1,1 +.#.????????##?????? 1,1,1,4,1,1 +#??###?#??#?# 8,1,1 +??###??.#????.?? 4,1,2,1 +?.?????.?? 1,2 +????##..?#???????.? 5,2,4 +??????#????#??? 7,4,1 +??.#.???????#. 1,1,3 +?.?#????#??#?. 7,3 +?.??###?????##? 1,6,1,3 +????#???#????.?????? 9,3,3 +??#?#???????. 4,1,1 +?.#??????? 5,1 +.??#??????#??.????? 3,8,1,2 +##?##?????.?? 5,2,1,1 +?..#.?#???? 1,5 +????#???.??#?#?????? 2,4,5,1 +????#???????????? 2,3,2 +??.??????.?? 1,3,2 +??.??????? 1,1,2 +???.#?#???.???#?. 1,6,1,1 +?##?????.??.?. 8,1,1 +.#???##??..? 1,5,1 +.????#????? 3,3 +??..??????#?#?#?# 2,1,11 +??###??#???# 6,2 +?????#??#?? 4,2 +#???????????????.??? 6,6,1,1 +???#??##??. 1,7 +?.?#????#??? 1,1,1,3 +?.##?##?.####.? 5,4 +#.?#???.??#? 1,3,3 +?#?#??#?##..??????? 10,1,2,1 +??.???#??? 1,6 +.?###???##?.?#? 8,2 +?.???#??????.??#??# 4,5,6 +????##?.##???#??## 6,2,6 +##??.?.???###?? 2,7 +?..?.??#??#.??????? 1,1,3,1,3,2 +????#.??.? 5,1 +?#??.????#??###? 1,9 +??#?????#?????#? 1,2,1,1,5 +###?.???.?#? 3,1,1 +??????###??????????? 2,13 +??????????#?..? 1,6,1 +??#?#?.???#. 4,4 +??????###???.#??? 2,4,3 +?#?????????#??????? 3,3,4,1 +??.#???#???#.???? 1,3,5,3 +??..#????##? 2,1,1,2 +#..????????????#?. 1,5,3,1 +?#.?#??.??? 2,4,1 +??#????#??###??#?#. 1,1,1,11 +????.#.????.??#?? 1,1,1,1,5 +???.??#???#?????? 2,7 +??##?#?#??.?.#.?.? 1,7,1,1,1,1 +??.##..?.??? 1,2,1,1 +??????#????.###.?.? 1,1,6,3,1,1 +#?????#????#?? 7,1,1,1 +?#?????..??? 1,3,2 +??.#?###.???#????? 5,4 +#?.??..##.?..#?#?#? 1,1,2,1,6 +?.?#..#.???#??.?#?#? 1,1,1,5,4 +.??????#??????.#? 1,5,2,1 +??##.???????.#???#?? 4,1,4,2,1 +????.?????????? 2,1,6,2 +#?????.#??.? 1,1,2,1 +???#?.????##?##??? 3,8 +????.#?????????#?? 2,1,1,2,4,1 +??????????# 1,1,5 +????##?????..?..?? 1,1,5,1,1,1 +?#?#??#?#? 1,7 +??.#????#?????.#.??? 2,2,7,1 +.?.?#????.? 4,1,1 +.?????#??? 1,4 +?#.??.????#?.?? 1,1,4,1 +?????#????#???? 5,4 +.??#?#??.?. 3,3 +??#??##????.?? 8,1 +????#.?.????#?????.# 5,5,1,1,1 +?..?##?##?###.#? 9,1 +???#?#??.???????? 1,6,3,1 +?????#?????#.?#. 2,2,2,1,2 +????#??#.?? 6,1,1 +?.?#????#.????? 1,1,1,2,1 +?????##..???## 1,5,5 +#?????###.#?#.????#? 1,6,1,1,1,4 +????.??.?#.#? 1,2,1,1 +??.#????????.?#??? 2,4,2,2,2 +??..#?????##?#???? 1,2,5,2 +.??...#??? 1,1,1 +.???#?.???.? 1,2,1,1 +???#???????##??#?#? 6,8 +??#.?.????#?# 1,1,1,6 +?????#?#?# 3,3,1 +?#?????.???.?? 5,1,1 +?#?????#?.??#??.?.? 4,2,3 +#??????#??.??..#?? 2,4,1,2,1,1 +????.#??.?. 1,2,1 +?.???#???#???????? 1,4,1,1,2,1 +???.??#?.?? 3,2,2 +.??#??#.?###?? 6,5 +.????..#???.#?#???.? 1,1,3,5 +.?#??.???#??.??#?? 1,2,3 +??.?#?###????### 1,7,3 +.???.##????#???.? 3,2 +#??###??.?##???.. 8,5 +..???#?##.? 1,4,1 +?.?##??.?#?#???###?? 4,12 +?.????#..??#? 1,1,2,3 +.#????#??#??????# 2,1,1,3,1 +?..?#?##?#???????#? 10,2 +??.###.????. 3,2 +???????#???????...?. 9,1,2,1 +?????..?#. 1,2,2 +?????#??#????? 6,3,2 +?.???#??#?. 1,4 +?.?#????#?. 1,3,1 +??.????#??#.#?## 1,8,4 +???...????..?#????.? 4,2 +.##?????#??#?##.?#. 11,2,2 +?..#?#.?#?. 1,3,2 +###???????##?.?. 3,5 +????????#?? 1,1,3 +?.???##???##. 6,3 +???????#???..#??.??? 1,1,5,1,1,1 +??.??##??#???.#???? 2,7,4 +??##??#???.? 7,1,1 +??????????? 6,1 +??#?#??.????#?#.??? 5,4 +.???..#??????#?.??? 2,8,1 +.?#.??#?..?.?.# 2,4,1,1,1 +?.??.?#.???##?.??? 1,2,1,4,3 +???#?.??###????..? 2,6 +????????.##? 1,4,2 +.??.???????##? 1,1,7 +.??????#??#?????# 6,2,1,1 +???#??????#???.???? 4,1,1,1,2 +??.??.???#?#??#?#?#? 1,1,1,7,3 +????.?####.????##?? 3,5,1,1,2,1 +?????#?????????#? 6,3,1,1,1 +????.?.???#?#??? 3,8 +??????#?#?.?. 1,5,1 +.??.#?#???.???? 1,1,2,1,1 +.##???..#????.?.?? 2,2,1,1,1,1 +.#?##?.???? 4,2,1 +?##??##?#? 2,3,2 +??##???.#?#? 4,1,1,2 +???.?????????#.???? 3,2,1,1,3 +????#?..????. 2,1,3 +.???#?#?##??.??#.?. 7,1 +.#??#?.??. 4,2 +???.??????? 1,2,1 +?????????.???.#?? 3,1,3,2 +?#???#?#??#? 5,2,2 +???????.?# 5,2 +#????#??#????.# 1,1,4,2,1 +.??..?.?##???? 2,1,6 +...??.???? 1,1 +#?????#???##?. 1,5,5 +?#?.??#???#?? 1,5,2 +???#?????# 4,3 +.??.????#?? 1,4 +??????#.????# 4,2,4 +????????.#?.???..? 2,2,1,1,3,1 +???.????.? 2,1 +????#???????? 3,1,1,1 +?.#??#???#?????? 1,11 +.?#?#?##.?##.# 7,2,1 +#??????..??? 4,2,1 +?.??#??????###?.?### 1,10,4 +???#??.??##?? 2,2 +?#??#.#?#???? 1,2,5 +????#....#?#?#?#?#.? 4,9 +#?????????????.? 1,2,1,4 +??.?????#?. 1,1,2 +??.????.?? 1,2,2 +????#???#????. 1,7 +???.??.#???##.??.#? 3,1,2,3,1,1 +.#???????#.??. 1,1,4,1 +.?.?.??####????.# 1,1,6,1,1 +.#??#?##??#??#?.# 11,1,1 +??.#?#??.? 1,1,2 +#????#??????.? 11,1 +?#??#?????.?? 1,1,3,1 +??#?##????.#.? 1,5,1 +##.?###???????????.? 2,10,2,1 +????#######????.?... 12,1 +???.??...? 1,2,1 +?#??##?.???? 6,2 +.????????????.# 4,1,1,2,1 +??###????? 3,2 +.??#.?#???? 1,2,2 +?##..#??.? 2,2 +.??#.?.??#???#?.?? 3,1,6 +???###????.?#?? 10,1 +#..???#????#?.???.? 1,9,2 +#.??#.??#???#..? 1,1,1,5 +.?.??????#??.## 1,2,5,2 +????????.??#. 2,3,3 +?#???#??#??#?? 4,2,1,2 +??????.?????????? 6,8 +????.??#?#..????##? 2,3,4 +.?#?#??.??????#??.?? 3,4,3,1 +#???.???#??.?.? 1,2,5,1,1 +?#####?????#?? 6,1,3 +?#????##?? 2,6 +??????##???.????? 8,2 +#?????#### 1,7 +????##??#??? 3,2,2,1 +?.#??.#.##????? 1,2,1,7 +#?#??.??###?#?? 3,7 +????.?#?????#???.# 2,8,1 +?.#????????????? 1,5,2,1,1 +.?????.#???.??????## 1,1,1,1,1,7 +?????#.#.?????#? 3,1,4 +?#?#??#???.??????? 9,1,3 +#?.??????????????##? 2,1,1,2,9 +??.??###.???.?????.# 1,5,1,2,1,1 +.??#?????.#????#?#? 5,9 +?????.??.? 2,1,1 +#???#?#??????#??#. 3,13 +?#???????#??. 6,5 +?.?#?.?????.?.?.. 1,2,5,1 +?#???#???.. 1,2,1 +.?#??#????? 5,2,1 +????.?..?? 3,2 +??###?????#?.#? 7,2,2 +#.???.?????????#? 1,1,8,2 +#??.?????????. 1,1,2,4 +.#????.??? 2,1 +?..?????.?????#?#??? 1,3,1,7 +#..??..??#.?? 1,1,3 +????#.?.#????##..?.? 5,1,2,3,1 +???###????? 6,2 +??..??#????.? 2,6 +????.##??????????#?# 1,1,9,1,1,1 +#.????.#?????#?# 1,1,2,3,4 +#.?????#?????.# 1,8,1,1 +?#?#??.?.#?#.?? 6,3 +.?.#.??.#.?#???##?? 1,2,1,1,6 +.?????????#????? 1,1,5 +??.??#??.??#..???.?? 1,4,3,2,1 +??.?.??.?? 1,1,2 +.?.???????..??. 6,1 +.?##?..????????.? 3,1,1,2,1 +???????????#?. 1,1,1,2 +.?..???#?#?####????# 1,1,1,11 +??#??#??????#. 1,6,2 +?.?????#?##?#? 1,4,5 +????#??.??????? 4,3 +.?.?.#??????##?????. 1,11 +?????????#??#???? 4,2 +??.??????#??#?? 2,4 +?????.????? 2,1,1 +?.??????#??#??#??##. 1,14 +?.??#.???????. 1,4 +.???..???.??? 2,1,1 +??#?##??.???.?. 7,2,1 +??.?#????? 1,2 +#???.#?#??.???????. 1,2,1,2,2,1 +#?#?.##?#??? 3,2,1,1 +??#???????????#..??? 3,2,5,3 +???.##??###?##? 1,2,8 +??#????#?#????? 3,8 +?#?????#??????#??? 7,6,1 +?##??????#??#??. 3,10 +?#?#?????##?. 7,2 +??..??.#?.????? 2,1,1,5 +?????#.?????.??.??. 4,1,2,1,1,1 +?????????.?.??# 1,4,1,1 +#????..#?#. 1,1,3 +???#???.??#???? 4,1,2,1,1 +??.?##.#??#? 2,2,1,1 +.?#??????????? 3,5,1 +?#..????????# 1,2,2 +.?#?.?#??????. 2,3,2 +??????#?#?#?..##??? 11,4 +????#????.?#???#??#. 5,1,1,7,1 +??????.#????#? 2,1,6 +?.??#???.??????##?? 1,2,1,1,1,3 +?#?#.??.????? 4,1,1,1 +????#????#???.? 9,1 +?..????????? 5,2 +????..?##????????? 3,3,6 +?????#.?##????.?.#?. 6,6,1 +?.?.###????????# 1,6,5 +????#?????##????. 4,1,5 +???????##?? 2,1,4 +?????#???#?. 1,8 +.#?#??#?.??? 3,1,1 +????#????###????#.# 2,1,1,6,1,1 +#??????#????.??? 1,1,3,1,1 +?#?#?#???#???.?.#?.? 11,2 +#???????#?#????? 1,1,6,1,1 +?.???##???###??? 1,1,9 +????.?????# 1,1,2 +.???.#?????? 1,1,1,1 +#??????#?#??.? 1,1,6,1 +????.?.?.?. 1,1,1 +?????.???..??????#. 5,3,1,2 +????????#?? 1,5 +..??#??????#??????? 11,2 +??.??????#?. 1,3,1,2 +.#????.??? 3,1 +????..??##. 2,4 +.??#?#????.??#. 9,3 +??#???.???.??#??#?? 5,1,8 +??????????.???????? 1,1,5,1,1,1 +??????##?.#?..??? 2,2,1 +.#??#?..?? 1,1,1 +??#???#?##?????##??# 2,6,6 +????.???.??. 2,1,1 +????????????????? 4,1,1,1,1 +???#??.?.#? 1,2,2 +#?????#?#?#?.?#?## 12,4 +????##?.??.?#?#.?. 4,4 +.??????#?#?###??? 1,10,2 +.???##????? 4,1 +?.#????###.? 8,1 +??.??#???????????? 2,1,5,2,1,1 +??.??#??.?????.. 2,3,3 +#?.#?#???##?? 1,10 +#???.??.?. 1,1,1 +#?#??...??????#? 5,1,2,1 +???.?.?##?.??#??.#? 1,1,4,1,1,1 +??..?.??#????#? 1,1,1,1,4 +?.?#?????.? 2,1,1 +.??#?.#??.?# 4,2,1 +??#?##?#?????# 9,1 +???#?????##?.?????#? 1,1,1,3,1,3 +???????#?????.. 2,1,1,2,1 +?#???#..#.?#? 2,1,1,1 +##???????##?????? 2,1,11 +.??.?.###?#.?????? 1,1,5,1,1,1 +???????.?.?#.?#? 4,1,1,1,3 +???.?????????#??? 1,7,3 +??#??#??#???.??????# 1,1,7,1,4 +??.?????.?.##.? 1,1,3,2 +?.#..###?..?? 1,4 +???..?#?????.??????. 3,1 +?##???????.. 5,4 +.??.??????.##?#? 2,4 +????????#??#? 10,1 +.???##???????#?????? 3,13 +??##????#?#?? 9,1 +##?#?.??????.? 2,2,1,4 +???.?????#?? 1,1 +?#?#.?????????????. 3,5,1,1,1 +#???#?.##?????.?? 1,1,1,7,1 +#?#??.??#.?? 5,1,1,1 +??#?????????##?. 3,1,2,3 +##????#?###??#???.?? 14,1 +?.#.???##?##?#? 1,3,2,2 +??????#.????# 4,2,3 +???#.???.??? 1,1,2,2 +???#????????#. 2,4,3,1 +##??????#??#?.??.??# 10,1,1,2 +?#?##.?????? 1,2,3 +?????????.????.??? 3,1,1,1,1,1 +#.?????#?? 1,1,5 +??#.?.??####??????# 2,10,2 +??#???????.#?? 2,1,2 +???#?.???.#??? 1,2,2,4 +?.?????####?#??#?#? 1,1,2,6,4 +####.??????#.?.#? 4,1,1,3,1 +.?#.?????? 2,1,1 +??.??.#.???#? 1,1,1,5 +?.?.??..#???##?. 1,6 +#??###?#??#?.?#..# 8,1,2,1 +??.??..??..##??#?.? 1,6 +?.#?#?????..?# 1,4,2 +.#???#?.???#????#? 1,2,1,2,4 +?.???#???.??????? 1,2,4,2,1 +??.??#.???? 1,1,3 +??#?.?.#??#??????.?# 3,1,1,1,3,2 +??#?.?.????###?. 4,1,8 +?.?#????#?.. 2,2,2 +?.?##???.??.???? 4,2,3 +?#?.?.#?.??#? 2,2,3 +#????.???#?#.. 2,1,4 +?.?.???#..??.#? 1,2,1,1,1 +????.#?.#??#?##??# 3,2,8,1 +.???.???#?????????? 2,7,4 +?#???#????????#..#?? 13,1,1 +???##??##. 1,2,3 +???????????. 5,1,1 +??..??.???#??# 1,1,5 +???????#??#??#? 2,2,1,5 +???#?????.# 6,1,1 +????###??.?.# 1,5,1,1 +.?.????????#?.#?#.## 1,10,1,1,2 +???.????#??#???#.? 1,8,1,1 +?#???.#????? 3,5 +#????#?##???#??? 4,4,1,1 +???????.???#??. 6,4 +?#??????.?..?.??...? 6,1 +??.??#?..#????? 1,4,1,1,1 +?.?##??#???#.??. 5,1,1 +#?.?#?????? 2,1,4 +.?#??.?#?? 3,2 +????????#???? 3,3,1 +?.#?#?#????? 5,1 +???????##??.??????? 1,1,4,1,2,1 +??#?..?#??? 1,4 +??#???#??#? 3,3,2 +?????.???.#?????.?? 1,1,1,1,6,1 +#????##????#?#??#?? 1,1,13 +??????.??? 1,1,1 +????#?????##?#?. 1,3,2,4 +?#??#?#?##???.#.???? 10,1,1 +???.?.?????? 3,1,5 +????????..?# 1,1,1,1 +.?#???.?#? 4,1 +???#?#??.#?.??. 4,2,2 +.??.???#?? 1,3 +?#..??#??? 1,1 +?.#?.#???##???.?? 1,1,1,6,1 +???????..?? 2,3,1 +.#???##??????? 2,6,2 +?##??..??#?? 2,1,5 +?.???????#?#?#..?# 4,5,1 +???#??.#?.?. 1,2,2 +??...?.???? 1,1,1 +???#?##?##.??#??. 10,3,1 +?..??????#. 2,1 +???..##????????#?? 1,11 +??#?###.## 5,2 +?????????#?#?##?? 3,11 +?#??????.?#.?#. 5,1,2,1 +???????.????##?#??#? 4,2,9 +?#?.??##?? 1,6 +.#??..??#?#??#???? 2,10 +.?.?????##?#??#??.? 2,3,1,3 +?#????#???##??#??? 13,2 +????##??##?##.?#? 6,6,1 +.????#?????.?.???. 8,1,3 +????#???#.?????#?? 7,1,3 +??????.??? 2,1,1 +?#????????.? 1,5,1,1 +?????##?.#.?. 1,5,1,1 +#?#??#????#?????. 1,7,1,4 +?###??????. 3,1,1 +.???##.??#???.?????# 5,1,1,1,3 +#?.#?.???????? 2,1,4 +?.?.??#?#?.??#??#??? 6,6 +?#?????.???#????? 1,2,1,6 +??????#?..?????#.. 2,4 +????.?#?????? 2,7 +?.##?#?.?..#? 1,5,2 +#??.??#?#?..??. 2,6,1 +?#??????.?# 2,3,2 +???????#.?.??? 3,1,1,1 +??##?##??#??.??##? 9,4 +???.?#??????? 1,2,1,3 +?#.??.???????##? 1,1,4,2 +????????????. 2,2,3,1 +????#?#####.????? 2,7,1,1 +#??##????.???.??# 9,2,1,1 +?.???#????##?.#?? 5,3,2 +#????#?????##??? 9,2 +?#?????.?#????..??? 2,2,5,3 +???#??#????.?? 1,7,1 +???#??##??#?. 6,3 +??#????..#??#?.?##? 1,1,1,5,3 +???????#?? 1,2 +?###???##??#.. 5,3,1 +??.?##??????? 1,4,1 +?#????#.?..??#?###?# 1,1,1,1,7,1 +.????.##?? 1,2,1 +##.?.???.??. 2,1,2 +#..?#???#. 1,2,2 +?#?????????????????? 2,1,1,2,7,1 +??#?.????. 2,1,2 +.??????..#?.?#???# 5,1,5 +#?#??.??.?#.?. 5,2,2,1 +???????#.????#?##. 1,1,4,1,3,2 +.???#??.?? 5,1 +#?#?#?????.??. 6,1,2 +????.???????#???##? 1,14 +.?#??#.???#??... 4,5 +#????###.??????#???? 2,3,2,7 +.???#??????#.#???? 4,1,1,1,1 +????#?.???.??# 6,2,3 +??#??#.????.?????? 2,1,1,1,6 +.???#????.??. 6,1,1 +.??#??#..####???..#? 6,6,1 +?.?#??????#???##?? 1,1,1,9,1 +?.??#????? 1,6 +????#?.????? 1,1,5 +??..??#..?##???# 1,1,1,5,1 +#?????.?#?.#?#. 1,1,2,1,1 +????#????.#???????? 4,2,4,1 +????#?.?#?. 1,1,3 +#??#???????????.?? 1,6,1,1,2,1 +???##?????..#.? 10,1,1 +??..?.???#?? 1,1,3 +??..?????.????.??? 1,2,2,1,2,1 +.?#??.???# 3,4 +.?????#???#? 1,1,1,1 +?????#???. 5,2 +?#???#??#.?????? 1,3,1,1,2 +..?#???????..#.? 2,3,1,1 +???#???#?.?.#??.???? 5,2,1,3,1,1 +????.#???##???.?? 3,8,1 +#?????#????.??#. 2,4,1,3 +???..???#??? 1,1,2,1 +????.?.#?????##?.?# 1,1,1,1,6,1 +.###???????#????. 3,2,5 +???#????.#?????#. 4,7 +##?.??#???.? 3,3 +#???#???#.. 3,5 +?????????.#?##? 1,1,2,4 +?.?#?#??#??##?.??? 1,2,9,1 +.???#????#???? 3,6 +????#????#?#???##??? 3,13 +????.??#?#??.# 1,7,1 +???.?????##?? 1,2,3 +????#???????#?.? 1,1,1,4 +??##?#????#??? 7,1,3 +#?##???????..##????? 6,2,2,1 +#???.????????? 2,2,3 +?.??.?###????????.. 1,6,1 +????.??????. 2,1,1,1 +???##???????#???.# 14,1 +??????#?#? 1,1,4 +.#??.???????# 3,1,4,1 +?.???#??????#??.?? 5,6,1 +?????##????.????#? 1,1,2,1,1,6 +???.?????.#?????? 1,1,1,2,4 +?.???.#??. 1,2 +?????.?..# 4,1 +???#?.??#??#?????#? 3,7,1 +????????##?.???? 1,3 +?.?.#??#??#?? 1,1,4,1 +...????##?.?#?.?#?# 7,1,4 +?##?????.?#??## 2,1,5 +???.??#??. 2,1,3 +#??#?##?#????# 1,1,7,1 +.###???#?????#?.?.?? 14,1 +?##..##?##?????#? 3,11 +.#?????.??? 1,2,2 +???#???#???#? 1,10 +?#???????. 3,2 +.?###???## 3,4 +?...#??#?..???## 2,2,2,2 +??#????.#. 4,1,1 +.??.####?#?..???#?. 1,6,5 +??#????#????# 2,2,3 +??#.?????#.?? 1,4,1,1 +?#??#???.????#.?#?? 8,1,1,1,1,1 +??.?..?#?.#???#? 1,2,5 +???###?#?????###? 6,1,7 +??#??.??#.?. 2,2 +???.?.??##??????#? 1,1,4,1,1,1 +???#???.?#??????? 5,1,5 +???.#????????.#. 1,1,5,1,1 +#???#?#??#?#????.?? 1,11,1 +??..?????# 1,1,1 +??#??????.?##?? 4,2,4 +#.#?#??????#?#???? 1,1,1,1,1,7 +????...??##????? 3,7 +.#.??#????.? 1,1,1,1 +???#?...????# 5,5 +?..????#?#??#??#### 1,12 +?##?#?..??? 4,1 +?????##?#??##??? 8,3 +?????##???#???????? 6,1,1,4,1 +?.??.????? 2,2 +??#???#????#??### 1,2,11 +#.????????#??#?. 1,1,10 +?????????#???.???? 2,1,8,1 +????.??#??#?##?? 4,9 +??????????#. 1,3,1,1 +??.?.??#???? 1,1,5 +.??????.??? 5,1 +#??#?????.?.#? 1,6,1,2 +???#?#?#..?????????? 1,3,1,4,3,1 +.?.?.??#?.#.?.???? 1,4,1,1,2 +??##?#????##? 7,2 +?????.??###???#?.? 1,3,9 +???#?.?#..?##??# 1,1,1,3,1 +???????.#?#?????? 2,1,1,6,1 +####?????? 5,2 +??#.???#?.? 2,3 +#??.???????.???#?#?? 1,1,1,2,4,1 +?#??????????????? 1,4,1,1 +##?????.?????????#? 2,3,2,5 +.?###??..?. 4,1 +.#??.??#??? 3,1 +??..???###?.???. 1,1,5,1,1 +???????????#??????? 1,3,4,2,1 +?????#?..????.???#? 5,1,1,1,2 +#?????????.#? 2,3,1 +.#?#??#????????#??.. 9,5 +?.#.???.??.??? 1,3,1,2 +???#??.?#.?. 2,3,2,1 +????..??#?#.# 4,1,3,1 +???###?#???#?????.? 6,2,2 +??????.???? 1,1,2 +???????#??? 1,2,2 +?.??#???????#?#?#??? 3,11 +?.???.??????#.? 1,1,1,3,1 +??#???????????? 5,2,3 +????????????.#??. 7,2,1 +?.??#???#? 2,3 +???#??????. 5,1 +.??#?.???#?????? 2,1,4,1 +?#??#??.???? 4,1 +???#???????????? 3,5 +.?.?#?#?#?..??? 7,1 +...???.??? 1,1,3 +?#?#???.??.. 1,1,1,1 +???##???????#??? 3,1,2 +..#????#????? 3,5 +.?.?#????#??#? 1,4 +???#..?#?#? 4,3 +???????##??#?.?#?#?? 1,9,2,1 +???.???????? 1,2,1,1 +##?#?#??##???.??.## 11,2,2 +??.?????.#?###????? 1,2,1,1,5,1 +???#???.#???#? 1,5,1,2 +?#????..?#??#???? 5,7 +.#??#?#.??.??# 6,3 +###?#?????#????? 6,1,1,1,1 +?????.?#??#?#????.? 3,1,6,1,1,1 +???.?????.?# 1,1,2,1 +?????#.#..#???? 3,2,1,1,1 +?.##?.???.??.? 1,3,2,2 +???#.?#????#?.?..?? 3,1,4,1,2 +.??#????.? 2,1 +??#?#????#??.? 7,1,1,1 +?#??#????.????# 8,1,1 diff --git a/src/bin/day12.rs b/src/bin/day12.rs new file mode 100644 index 0000000..38e8642 --- /dev/null +++ b/src/bin/day12.rs @@ -0,0 +1,109 @@ +#![forbid(elided_lifetimes_in_paths, unsafe_code)] + +use aoc23::read; +use chumsky::{prelude::*, text::int}; + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +enum Cell { + Working, + Broken, + Unknown +} + +impl Cell { + fn parser() -> impl Parser> { + choice(( + just('.').map(|_| Self::Working), + just('#').map(|_| Self::Broken), + just('?').map(|_| Self::Unknown) + )) + } +} + +struct Row { + cells: Vec, + expected: Vec +} + +impl Row { + fn parser() -> impl Parser> { + Cell::parser() + .repeated() + .then_ignore(just(" ")) + .then(int(10).separated_by(just(","))) + .map(|(cells, expected)| Self { + cells, + expected: expected + .into_iter() + .map(|num: String| num.parse().unwrap()) + .collect() + }) + } +} + +fn parser() -> impl Parser, Error = Simple> { + Row::parser() + .then_ignore(just("\n")) + .repeated() + .then_ignore(end()) +} + +fn combinations( + peeked_cell: Option, + cells: &[Cell], + current: u32, + expected: &[u32] +) -> u64 { + let res = match ( + peeked_cell.or_else(|| cells.first().copied()), + expected.first().copied() + ) { + // streak but no more expectations + (_, None) if current != 0 => 0, + // everything empty, everything fine + (None, None) => 1, + // no more cells with expected containing just the current streak + (None, Some(expectation)) if expectation == current && expected.len() == 1 => 1, + // no more cells but expected doesn't match + (None, Some(_)) => 0, + + // working cell with no current streak + (Some(Cell::Working), _) if current == 0 => { + combinations(None, &cells[1 ..], 0, expected) + }, + // working cell with current streak that is expected + (Some(Cell::Working), Some(expectation)) if expectation == current => { + combinations(None, &cells[1 ..], 0, &expected[1 ..]) + }, + // working cell with current streak that doesn't match + (Some(Cell::Working), _) => 0, + + // broken cell + (Some(Cell::Broken), _) => { + combinations(None, &cells[1 ..], current + 1, expected) + }, + + // unknown cell + (Some(Cell::Unknown), _) => { + combinations(Some(Cell::Working), cells, current, expected) + + combinations(Some(Cell::Broken), cells, current, expected) + }, + }; + // eprintln!( + // "combinations({peeked_cell:?}, {cells:?}, {current}, {expected:?}) = {res}" + // ); + res +} + +fn main() -> anyhow::Result<()> { + let grid = read("inputs/day12.txt", parser())?; + + println!( + "{}", + grid.iter() + .map(|row| combinations(None, &row.cells, 0, &row.expected)) + .sum::() + ); + + Ok(()) +}