diff --git a/day-12/input/vanyle.txt b/day-12/input/vanyle.txt new file mode 100644 index 0000000..77f603f --- /dev/null +++ b/day-12/input/vanyle.txt @@ -0,0 +1,1000 @@ +?#?##?#????.?..?? 9,1 +????????#???#? 1,8 +.??????#???#??????? 2,7,1,1 +???.?.?.???#.? 1,1,1,4 +??#???#?##??. 4,5 +??????##??#???????? 1,10,1 +?#?#??.???.???? 6,1,2 +?#?#??..#???#???#? 6,1,4,2 +??????.?.???#?####? 5,1,9 +.#?#??#.????#?#??#? 4,1,1,5,1 +????..????..??? 3,2,2 +.?#??#.??.? 4,2 +???#????#??? 2,4 +#.??#??#??.????#? 1,3,3,1,1 +???.#?????#. 1,1,4,2 +??#?#?.??#??. 3,1,1,3 +?????#???? 2,4,1 +?.??????.?#?#? 5,3 +.?????#???..? 7,1 +.????????.# 1,3,1 +???#.?.?.. 1,1,1 +?.???.??????#??#??? 2,2,6 +??#???.???????#??# 2,10 +?#??#?.????.???? 2,2,1,1,1 +????#?##??. 1,6 +#?#???#???.????? 8,1 +???.?????#???? 1,7 +?????#?????#?...???# 11,1,1 +?.?#?.??.#?#? 2,2,4 +???#.????#??##. 1,1,3,1,2 +??????.????? 2,1 +???#???#?..??.?#??## 1,7,2,6 +?.??#..#???#???.?? 1,1,5,1,1 +?.???###?? 1,5,1 +???.?.#??#?????.?#? 3,2,1,3,1 +???.??.???? 1,1,3 +.?##????????.. 6,1 +????????#???##?#?#. 1,2,2,8,1 +?##?#?????#.????? 4,1,2,4 +?????#??.?#? 4,3 +?##???.#??.? 2,1,1,1 +???.#???#??????# 5,4 +?.?????#.???#..? 4,1,1,1,1 +.?????#??????..#? 8,1,1 +????#??##?? 4,2 +.??##??#?????.. 1,9 +?.?????????? 1,3,1 +?#??..????..??? 1,2 +??????.?.????? 2,2 +?.??##?.?? 1,4,2 +??#?.#?.#. 3,1,1 +??.?##???????#.? 2,5,3 +???.?#?.?#?#?. 1,1,1,4 +??.#???????.# 1,1,3,1 +??###???#? 4,2 +?.?????#??#???? 1,1,1,5 +?..??.?##?????? 1,1,2,1,1 +#??#.#.?.???? 4,1,1,2 +?#?????#???#??#.#?. 6,1,5,1 +?.?###???.????#??? 1,4,1,1,1,4 +???#?.#.##?#?##? 3,1,8 +??#?#?#??????#??#?.? 1,6,7 +##???#?#.???.? 8,1,1 +?..#??.????#?#??.?? 3,5 +?????#?##??. 2,4,1 +??.???###?.?????.? 1,6,1,1,1 +??????????#?#??? 2,4,1,1,2 +?#???#???#???.?#? 2,9,2 +?#??..????? 1,3 +??#?.?.????#.? 3,1,2 +???#??#?#..???? 2,3,4 +?#.##?#?..???#?##.?# 1,2,2,4,2,2 +???.?..#?.???? 1,1,2,3 +????#?#????.? 1,8,1 +?#?????????#?? 1,1,3,5 +???.#??#????? 4,1,1 +.#????.??? 1,1,1 +??.?????#????#?#? 2,1,2,1,4 +.???.????? 3,1,1 +#????#??##???? 1,9 +????#?#?#??.?#?? 4,1,1,2 +??????..?#? 5,3 +??#?#??#????#???#??. 7,5 +??###?.???#??.#. 5,5,1 +?????##??. 3,3,1 +?.??????#????????# 1,1,12 +.????.????? 1,1 +???.??#??..?#?..?#?. 3,4,3,2 +???????.?#??? 3,3,3 +??#???.?????? 2,1 +?#?.?##?#??## 1,6,2 +.????.??#??#?.... 1,6 +.???.#???#? 1,5 +.?#.???#??? 2,2 +#...??.???#? 1,1,1,1 +#.???.?#.??????????# 1,1,1,1,11 +????#??.?? 4,1 +??#???..??? 5,1 +..??????#?? 1,5 +????##?#?.??????.? 6,4,1 +?.?????????????..? 5,3 +??#???????????##???? 5,2,2,6 +.?#??.??#???# 3,4,2 +????#?#????##? 5,3 +?#?.??.???#???#?##? 1,1,12 +??.???#.????????##?? 1,1,2,1,1,8 +.??????#??? 2,3 +?#?????#?#? 2,4 +.?????..????? 2,3 +.?.???#????.???..?. 4,2 +??.??..????????. 2,2 +??##????#???.?#? 1,10,2 +??????#??.?...? 1,3 +??##???#?.????#????? 6,6 +?#?????#?#?????? 2,5,3 +??#???????#???? 5,4,1 +#?.????..?#?. 1,1,1,2 +????????#??#####? 3,12 +????????#??#? 2,1,6 +????##??.?#. 2,3,2 +.?.?##?.????#???. 1,2,8 +?.#.????.#????? 1,4 +??????????.? 1,1,2,1 +??.????#??##?. 1,1,6 +???.?#??..# 3,3,1 +?????#??????.?#.. 10,2 +...??.???????#???#?. 1,11 +??????.#.??.?.? 3,1,1,1,1 +????.#????#?.#?#?? 2,1,2,1,1,1 +???#?#..#???? 4,1,2 +.????..?#?#??.? 2,6 +.??#??###?#?#??#??.. 4,12 +??#???#??# 2,1,1 +????..#???..???? 3,1,2,1,1 +.#??.???#? 1,1,1 +?#??#?.???#. 1,1,1,1 +?....????##?.??..? 1,1,1,3,1,1 +???.#???????#??.#?# 1,11,3 +.?.?#????#? 2,1,1 +?#??#??#.??#?.?????? 7,2,3 +???????????.?. 1,1,5,1 +??#???####?# 3,6 +??#??#.?????????? 1,4,1,1,5 +??####?##??.#.?. 8,1 +?????#??.?#?#?? 3,2,4 +?.???##?#...?? 7,1 +?#?.#?##?#?????# 1,12 +.?????#??#??#???.?#. 1,13,1 +.??##??#?????# 1,6,2 +??.??.?##????.? 1,1,6,1 +??..????#?#. 1,2,3 +?#?.?#..???? 3,1,1,1 +?.##??????? 2,2 +????#?###??.???# 3,6,1,2 +?#??????#???.??????? 11,3 +???..#?##??# 1,1,5,1 +???#?..?????? 4,2,1 +#?#????.??..?# 5,1,2 +?#???.???? 2,2 +???###?###??.#.? 11,1 +????###?#?#???. 11,1 +??#??????#??? 2,2 +#??.#...??#? 3,1,1,1 +.#.?.?##??#???#.?.#? 1,1,8,1,1,2 +?#???????#..#?? 4,1,1,1 +##??#?#.???.?.? 3,3,3,1 +????.??..????????? 1,1,1,3,1,1 +???????#????. 1,1,4 +???????#????# 1,5,1 +..#??????? 2,4 +??#???.???? 2,4 +.???#??.???##?. 5,4 +?.???##.??????..? 2,3 +.#???.?.??#???#??#?? 1,1,1,10 +.??.#???#???? 2,9 +???????##????????.? 1,10,1 +?#.?.#??#?????. 1,1,1,3,1 +???.????#.?.? 5,1 +?.?#???#??????.? 1,1,2,3,1 +??#??..?#.? 5,2 +.??#?.#.#.?? 3,1,1,2 +??#.?#?.???#?? 3,2,3 +??????#???..?.??.?? 8,2 +??..??.?#??? 2,1,3 +??.???#???? 2,2,1 +??????#???.#??# 1,2,2,4 +#??.#?#?...??????## 1,1,4,1,1,2 +???#????#????.?.???? 12,2 +?#?##?.??????? 5,3,1,1 +??????.??????? 1,2,4 +???..??????..??## 2,3,1,1,2 +?.??..????.?? 1,1,2,1 +#?.???.?..??? 1,2,1,2 +????#.#??#??????#?? 1,2,2,10 +?????###??? 7,1 +?#??#?..???.#?? 6,3,1,1 +?#??.?.?##?#??? 3,1,5,1 +??#??#???#???##? 1,2,1,2,5 +?#?#.#?....??????. 2,1,2,1,1,1 +.????##???..?#. 7,1,2 +???..?.??#?#?.?#. 1,4,2 +??.?.????.#.????#?? 1,1,2,1,7 +?#?????#??.? 1,2,1,1 +???#???#?????? 9,1 +??..???.?##..?? 2,2,3,1 +?.#??????????????? 8,1,2 +??#??#?####??.???? 1,7,2 +#.???..#.? 1,1,1 +?????#..????? 4,1,1,1 +??.???##?#???.# 1,5,1,2,1 +????.??.?#?. 3,1 +#??.???????????##?.? 1,1,13,1 +?#.???###?.?.?? 1,1,5,1,2 +??#??????#?????????? 11,2 +???..????. 1,1,3 +.?????????????? 1,4 +?.#????.???#????? 5,5 +???????.#??#?.. 1,1,1,2,2 +?????.????????????? 1,2,2,8 +.???????#?? 3,3 +??.????#??..?.??#. 1,3,1,1,1,1 +?.#??#???.?? 1,1,1,1 +.??????????? 5,2 +.???????#??? 8,1 +.#?..#???#?.#. 1,1,2,1 +.???#?#???.???? 7,2 +??.?????????#????#.. 2,9 +??##???????#????# 5,1,1,1,1 +?#????#??.#??.??? 8,3,1 +?.#??#?.#?. 1,2,1 +#???????#???#? 2,6,3 +??##?#?.?#?? 4,2,3 +???.#????????.?? 1,1,8,1 +##???.??????#???# 4,1,2,2,2 +??###?.?#???? 4,4 +#?#??.?#?.?.?#?##..# 1,1,3,5,1 +.????#?????#?#??. 2,1,7 +.???###??###????.?? 12,1 +??.???####?.??? 1,5,2 +??#????????.?##??## 1,1,1,1,6 +???##????#????????## 1,5,1,5,3 +.??#?#??#?####??.? 5,8,1 +???#??##...#????? 8,3 +.??...##????.? 1,5,1 +.??#????????#? 7,3 +.???.?##.??????.? 3,3,1,2 +????#??##??#?. 3,5 +??##??#???#.? 7,2,1 +#.??#??#??#???.??? 1,2,7,1 +...???.#.??? 2,1 +#???.?##?###??# 1,2,2,6 +????.?#??.? 2,1,1 +???..?#?#??.#???? 1,6,3 +?..?????#?? 1,1,2 +.?##??.?.?#? 5,2 +###???????#?? 3,2,2,1 +????????#?##??.. 1,1,4,3 +??.?.?#????#?..#.#?# 1,5,1,1,1,1 +.#???#?.#???? 1,1,1,5 +?????.?#?.?#?? 2,1,2,3 +?#???????????#?###? 1,1,1,8 +???#???#.#??? 1,3,1,1 +??#?#????????? 3,2,5 +?.???????#???# 2,6 +??##???##??. 4,5 +????#?.??#??#???#. 4,9 +#??.???.?.??## 2,1,1,2 +?#??.????#?.? 3,2,1 +..#?##.?.##??##???? 4,7 +.??.?##???#???#?.?? 8,1 +#.?????#?????? 1,6,1,2 +?#????.#?.??.#?? 5,1,1,1 +?.?.#?#??????.? 1,1,4,1,1 +??.?#????.??#..#?? 5,2,2 +?#??#????. 2,4 +?#????#??#?.#?? 1,1,5,1,1 +#??##??#??#? 2,3,1,2 +??.?.#???#?.??#?#. 2,2,2,3,1 +.##????.?##.?? 3,3 +#?.???.??#?#???.?#? 2,2,2,2,2 +??.????#???????#?? 2,3,1,1,3,2 +??#??#.#??#???#?.? 1,1,1,5,1,1 +??.????###.?. 1,5 +?#???###?.????? 1,5,2 +????#?#???.? 7,1 +.???#???### 3,1,3 +??#..?#??. 3,4 +?????##?.?? 1,4 +?.??#.??????#?#??#? 1,2,1,5,1 +????..??#?? 3,2 +#.????.?#???##??# 1,1,10 +??????????..?.???? 7,2,4 +?#.????????? 2,3,1,2 +.?????.#??#? 2,4 +???#?????#.????.? 1,7,2,1,1 +..???##?????#?? 8,2 +?#????????? 5,1 +????#?#????. 3,2,1 +???..?..#?..# 3,1,2,1 +.????.???????? 1,3,1,1 +.????#?.???#??##?.?? 1,3,7,1 +..??#?#???..#?#???? 3,1,1,4,1 +.??.?????.?#?##??.? 2,1,6 +???#.?#.??#?? 2,1,1,2 +?.??????#?????????. 1,5,1,2,1 +???##?##?.???#?. 1,6,2,2 +.??#....??.? 2,1 +.??????.?#???.??? 1,2,1 +??.??...?##?##????? 2,9 +.#??#?#?????????.??? 11,3,1,1 +???#??#?#????.???? 12,1,1 +???.????#??? 1,1,2,1 +?#.??#???##????. 1,12 +?.????????#?? 1,2 +.??###??????????#?## 5,1,7 +.#?##.???.?.?.???? 4,1,1,1,1,1 +?#??###??##..?##? 1,7,3 +???#.??.?###?#.? 4,1,3,1,1 +???????##?##??#.. 3,1,8 +??#?#.???#?#????? 4,1,4,1 +?##??#??#?##?? 2,1,6 +#?#?.?##?????. 1,1,8 +????????.#? 6,2 +.??#.?#?#??.?. 1,5 +?.?#?.?.????? 2,1,2 +?#????#??????.?????? 2,1,1,3,2,3 +????????#?.##.?.?? 8,2 +?#????#????????#.??? 5,3,2,1,1,2 +#?#????#..???????#? 1,3,1,4,1,1 +.#???#.???????.#???? 5,1,1,3,1,3 +.??????.?#?##???? 5,6 +?.??#.?????#####???? 1,1,9,1 +#???#????#.??.?## 2,2,4,1,3 +#????#????#.?#???#?. 1,1,1,4,5 +?#????.??. 5,1 +????##?????? 7,2 +?#?#??#?#????.?.#?? 9,1,2 +??##.?##?#??.??..?? 4,4,2 +..??.??????? 2,7 +?#??#.#?##????? 4,1,6 +??.?#?.?#?.?????? 3,1,6 +.#??????.?? 4,1,1 +##??.##??.?##?#???? 4,4,6,1 +??????#?????#?? 10,2 +?##??????? 3,5 +.??????????.#?#.? 9,1,1 +..???#????##??#? 2,1,8 +??????#??#???????# 1,1,1,8,1 +?..???.???#?##?#. 2,6 +?#????##.???#?# 2,3,6 +?#????#??? 4,3 +#?.??????????#???. 1,1,2,3,3 +????????????..?.? 1,4 +##?#??#.?#??.#??# 7,1,1,4 +??.?????????#..???. 1,1,8,2 +????#?????.?#? 2,1,3,2 +.?#??..#??? 3,1,1 +?#?#?????#????? 1,1,9 +#???#?#?#?.? 1,7,1 +#??????##??..?#?#??? 2,6,6 +.??###??????#???. 3,3,3 +?????????????##.?? 1,1,8,1 +????????#.??#???# 9,2,1 +???#????????? 1,6,2 +.?????.???.??.. 5,1,2 +?#?.??????.??# 1,6,1 +???#???.????? 2,1,3 +.#.????#..?##?.????? 1,1,2,3,2 +?#?.?#???#?.?. 2,6 +.##?#.#??#???????### 2,1,1,1,1,4 +????#???.????.#.? 7,1,1,1 +#???.????? 1,4 +##??#???#??????????? 5,10,1 +?#??????..??? 5,1 +.???#??#?##? 1,7 +??..#?#??????#. 2,4,3 +?.??????#??.???.?.?? 3,5,1,1,1 +??????#?.??. 5,1 +#??.??#?.?#?##??#? 3,1,1,5,1 +##?#?.?.#? 5,1 +????#???.? 4,1,1 +.??#?#????..?????? 1,1,3,1,1,1 +??#????#?##???????? 1,1,11,2 +#??.?#?#???.# 1,6,1 +??.??????.? 3,2 +???#?.?????#?##?#.# 4,1,7,1 +????##???#?.??.# 2,5,1,2,1 +?.?###????#?#??#???? 11,1,1 +???#.????.?.?#?#??#. 4,3,1,5,1 +?##?###?????.??? 9,1,2 +??#???.????????#???? 4,1,8,1 +#?#????.???.? 6,1 +?????..??.????.??? 1,4 +.??.???.??.?#??.?.? 1,2 +.?.??#?.??#??#??#? 3,7 +?#?????..????? 4,1,2,1 +????????????#?? 4,5 +??.?#???#??.??? 1,3,2,2 +##??#?.????#??? 6,7 +#?????.?###?##? 1,1,7 +?.??#?#??# 2,4 +?#???????# 1,2,3 +????.????..##? 2,4,2 +???????#?#? 1,6 +???#.??#??.? 1,4 +??###?###??..?????? 11,2,1 +?????.?.??.#?.? 1,1,1,1,1 +?#?????#.?#??. 2,5,4 +??.????#?????#???#. 1,1,2,7 +??###????????.? 4,2,1 +?????.?.???.? 1,1,3,1 +.?#??????#??.??##?#. 4,2,3,6 +?##???#???#?? 2,3,3 +????#????##??????? 1,13,1 +???.??????##.... 2,3 +.#??#???.???.?#?? 1,4,3,3 +#??#?????#?#???##?? 2,10,3 +?????##.??#?#??. 7,1,5 +???#????#??? 5,2 +????#???.?#??#???? 1,1,1,9 +#???##???. 2,4 +.#???..#????#??? 2,2,5 +?????????#?? 7,1,1 +?#??#????.???? 7,1,1,1 +??.?#???#????????? 2,3,6,1 +.?..??#?###. 1,7 +???#????.?#?????? 4,1,2,2,1 +.????#.???. 4,2 +.???????.? 4,1 +.?????????.??#? 1,1,2,4 +.??##?##?????.?# 2,2,1,1,2 +??????.#.?#? 2,1,2 +?#???.???.??#????. 4,3,1,1,2 +??#.???.??? 2,3,2 +.????#????#??????? 10,4 +.#.??#..?. 1,1 +????????..?#???# 2,2,2,4,1 +##??????.???.?#.?? 3,1,1,3,1,1 +###???.?#.?#?#????# 3,2,1,4,2,1 +#?.###??#.??? 2,3,1,1 +???.??#..??.??? 1,1,1,2,1 +??#?..?.?..?##???. 3,4 +?..???#?#?? 1,7 +????#?#????##??????? 10,1 +.?????????.??.??##?? 4,1,1,1,6 +?#???..?????. 2,1,1,1 +?#.??#????? 1,3,1 +.???##?#???#?. 1,4,2 +..?????##??????.? 8,1,1 +?????#?..??. 3,1,1 +????#??#?.?#??. 6,3 +????.?.##?????###? 1,1,2,2,4 +?????.?#???? 2,1 +#???#?#??.#.?. 1,6,1,1 +????#.?.#??#??#??## 1,1,11 +??##?#???#?.?.????? 1,8,1,1,2 +.##??#.?#?? 5,1,1 +.?#???.??????..??? 5,1,3,2 +.???.??????.##???? 3,1,5 +???#?#??#??????.???? 13,1 +??.?#??.?# 1,2,1 +??#????????.??.?.#? 1,9,2,1,1 +??#??#..??#.? 4,1,3,1 +#?.#??#???#???.??? 1,9,1,2 +??#?????????? 1,1,3,1 +????..?.?#?.???? 1,1,1,3,4 +?#??.?#???? 1,5 +?##??.??#.??..????? 2,3,3 +.??.?????? 1,1 +?##?#?##????????.?? 3,1,4,3,1,1 +.???#?#?#?????#?? 4,7,3 +?#??#???..? 4,1,1 +...?###????#?#??#??# 3,8,2 +???#????.??????#???? 2,1,7 +#???????##?####.?? 1,1,1,2,4,1 +??#.????#?????. 1,1,6 +#??????#?.#? 1,1,1,1 +#??#????????.?? 1,1,3,1,1 +?#?#??#??? 3,2 +..????.?#?. 1,2 +??????##????. 5,3 +????????.??#??. 6,1 +.#?##????.?#?#.??? 8,2,1,3 +??#?.????#????? 3,5 +????#???????? 1,8 +??.??#???#?? 1,1,4 +???...???..? 1,3 +..??##??#?#.?##### 9,5 +..?#?.???. 2,1 +#?#???#.#???#???? 1,2,2,2,5 +??#???.??.?? 4,1,1 +..???.?????... 2,1 +?..?#???#?..??#????? 7,7 +?.?...???#. 1,4 +?..?#???#????? 6,2 +??#???????#?????#?.. 2,9 +?#??#???###????#. 1,7,1,1 +???#..?#????.?##??# 4,5,3,1 +.??#..#??.?? 3,1 +????.#?.??..??#? 4,2,1,4 +#????????#. 1,5,1 +????#??.#.??? 4,1,1 +.#?#?#??????? 1,1,8 +???#?????.# 4,1,1 +?????#??#.???.?. 7,1 +??????????? 3,1,1 +##??#?#???????# 5,1,4,1 +?#???##?.??#??#????? 3,3,1,9 +#????#.????#.?? 3,1,1,1,1 +.??#.?#.??#?? 1,1,2,3 +?.??##?##????.??.#.? 1,7,1,1,1 +##???????.? 2,2 +??#??.?#????. 2,1,3 +?....#?#??. 1,1 +??##??.?.??#? 4,1,1,2 +??..?.?????# 1,1,1,1 +.??.?????? 1,1 +????#??..?#?#??#. 4,7 +?##????#.??# 3,3,3 +?#?#????.##?#?? 5,1,2,1,1 +.#?#???.##? 1,4,2 +.??????..?#??? 1,3,3,1 +?##??#??.????? 6,1,1 +.???.??... 1,1 +.##???###???#?#?? 14,1 +#?#?????###?.?????. 3,5,3 +???.?#?#??#?????.?? 1,1,7,1,2,1 +???#?.??##?? 1,4 +#?#.???#???. 3,4 +???.?.???.#???#? 1,1,2,1,2 +..#??????#???? 4,4 +.#???????????#??.. 1,3,6,1 +.????###???#? 1,1,5,1 +?.??????#???...?? 2,5 +?????#??????.??#???? 7,1,3,1 +??#?#..#??.#??? 2,1,2,1,1 +.?#?.?#??#? 1,5 +#???##??????????? 1,10,1 +????#?###?#?.??.?.# 3,8,1,1,1 +??.##????##. 3,1,2 +.??##.?.??? 2,2 +?#?#???????????##??? 11,4 +?.?????#?.????#?? 1,1,1,1,4 +?#?##?????##??????? 2,12,1 +?????????#????.??? 10,1 +???.#???.? 2,4 +?#????.?#.?#?..#?## 2,1,2,2,1,2 +???.#?#?#.?????? 5,2 +.##??#?#??#?? 7,3 +#.????#?#?#????.?? 1,3,7,1 +??##???#???#??.?#?? 10,3 +????#?????#. 4,1 +?????.???? 4,1 +?##??????#?##.? 2,7 +.?##?????#?#?? 6,1,1,1 +???????.???##?? 1,2,5 +.?.??#????#??#??###. 1,1,12 +??#??#???#.????. 5,3,2 +?##??#??.???#??? 8,6 +?##??.???????? 5,1,2,1 +?.???.?.????#???# 1,3,1,2,5 +??#?#????#???#??#. 3,2,9 +?#.??????.??????? 2,1,1,1,4 +?????#?????. 2,1,2,1 +???.??#?#..???# 2,1,1,1,1 +?#????????. 2,1,1 +???#??..??.??#??. 3,3 +????????..?? 2,1,1,1 +.??..??#...?#.???# 1,3,2,3 +?????###??.?? 4,1 +????#?????? 6,1,1 +.???????#??## 3,6 +.?.???#???????#? 1,10,1 +?#.???#??#?#???? 1,4,8 +.??????##??? 1,4 +#??##.?????#???##??? 1,3,1,8,1 +????#????#?###????# 3,1,7,2,1 +??.????###?????? 1,1,7 +?#?#?.???.##? 4,1,2 +????.?..???#?#? 4,1,1,5 +?#???.?#??. 1,2 +#??#????????????. 1,7,1,1,1 +.?#..#?.##?#.??? 2,1,4,2 +??.???.??#????#??#? 1,1,1,6,1,2 +?..#??#.##?.#. 4,3,1 +???###??##????# 1,7,2,1 +###?????###?#??#..?? 13,1,1 +.#?????#??? 1,6 +?#??#??.??.?.? 6,1,1,1 +.#??.?#..?#??? 3,1,4 +??#??.?##??? 1,1,4,1 +.#????#?#.?#?#?##??? 8,7,1 +?#??#?#.???????. 7,3 +#?.??#??##??????. 2,6,2 +.#??#?#??.? 1,5 +.????#??????#??? 2,7,3 +.???#?#????.? 1,4,1,1 +?#..???.#? 1,2,2 +.#??????###????? 6,7 +?.????.???#?? 1,1,1,2 +??..??????.##?##???. 2,6 +.#?#..?#????.?? 3,5 +.#?#?????????? 5,1,1,1 +.?.???#?#??.? 1,3 +???#.?#?..????#?###? 2,2,8 +.?#???.?.???##?.?.? 2,1,5,1,1 +???????..#?##? 2,1,1,2 +.?#?????.??#. 3,1,1,1 +???#????#??.?.#?? 1,8,1,1,1 +?????.????#??#?#? 3,11 +#..?.#????#??#?..? 1,9,1 +#.?.?#??.??? 1,1,3,2 +????.????.?##???? 1,1,2,3,1 +..??.?..???.?.?? 1,1 +.???.##??#??#???? 1,1,6,1,1 +#.#?????????# 1,1,3,2 +#??#?#???.?????.? 1,5,1,1,1 +??.###???..? 5,1 +?#?#??##??#??.??. 4,7 +??#?????????? 5,3 +?#???#???. 2,2 +??#??#?#??#?? 6,1,1 +?.???#.?#?# 1,3,3 +???#??????#???#?. 1,10,1 +?.?#?##?.?? 1,4,1 +#??##??.????#??. 1,3,6 +#.???????#? 1,2,2 +?#?#??.?.?#?#.?#? 3,1,1,3,2 +??#???.?#?????? 2,1,6 +.??#???##???# 1,2,7 +??#??#???#?#?.?.?. 1,1,8,1 +##???.?..??#?? 2,1,1,2 +?#..????.????????#?. 2,2,10 +??##?..?##????###.?? 4,10 +?#?..??.?? 1,1,1 +??????#??..??????.#? 8,1,1,1,1 +???????.#?????..??.? 2,1,5,2,1 +#?#????????##??? 4,1,1,6 +.???#?..?????? 1,2,1,4 +.#..???.??##??. 1,3,3,1 +????#??????#???????? 1,1,5,2,1,1 +?.?###?#?#?#?#?#?.?? 14,1 +?.?.?#??????? 1,3,2,1 +?##????????#?#??.# 5,1,3,1,1,1 +???.???#????? 1,6 +?????####?????#?#? 1,11,3 +?#?.???#??? 1,2,1 +..#??##??? 6,1 +??????.??.. 2,3,1 +.????#?.#???.?? 1,2,1,1,1 +.??##?##??..??###??? 7,5 +#???#??.??.?#.#.?. 1,2,2,1,1,1 +??????#?#??.?? 5,1,2 +#?#??#??????.????.?? 9,1,1,1,1 +#?#..????#?????###? 1,1,1,4,7 +.?.?????#.?# 1,1,2,1 +?.???#?##?????#????? 5,2 +#?????.??? 2,1,2 +?????#??#?#????#?? 13,1 +?.??#????#..?? 5,2,1 +????#??##?.?.? 1,3,3,1 +?.????.?##???#? 2,7 +#?#?????#??.??##?? 6,1,1,1,2 +???#?#??????#???.?.? 4,4,1,1,1 +???#???#?#?.#? 4,5,1 +??.?#???????????. 1,5,4 +.?#.?????#.? 2,2,1,1 +????.?#?###???#?.#.? 2,11,1 +??#??????##?#?? 2,9 +???????#?#?##??????? 3,1,7,1,1 +???##?....??????? 6,6 +?#.?#?.##?#?#. 1,1,2,3 +??????????#? 4,2 +#.?###?#???#?##?#?.? 1,13,1,1 +??#?#?.?.???.??##?? 6,3,4 +???.#?????##?.# 1,1,8,1 +??????#?#?? 8,1 +?#??????#??#?. 6,1,1 +.#?#??#.#?#?#?.? 6,5,1 +?????????#??.??#?#? 7,2,3 +.????#??#????.??#? 8,1,3 +??.?#???##?#??##??? 2,12,1 +?#???###?.???.?? 7,3,2 +#????.#???.???#..# 1,1,1,1,4,1 +????##?.#? 6,2 +??????####?.# 7,1 +????#??.#. 1,4,1 +.????#?????????##?? 15,1 +???.????#?# 1,4 +???????###. 1,5 +#?.?????#??#?? 2,6 +?????##????.#??#.?? 8,2,1 +??####????##???.# 13,1 +?..??#??#.?#?????? 1,3,1,1,1,1 +.#???#???????#??#?? 6,1,8 +??#?#..???? 4,2 +.?#?.?.???? 2,1 +.???????????? 2,1 +????????#?.??? 1,1 +??#???#???. 2,4,1 +#??.????#.?. 3,3,1,1 +?????#.?.?.????. 5,2 +???#???.???? 1,5,1,1 +#.?.?????#????? 1,6,1,1 +?#?..#?#.??.??#?. 2,3,3 +#????..???. 5,1,1 +?#??#?????#???#. 1,3,1,1,3 +???#?????????????.?? 4,2,1,5,2 +????...?..??.????? 2,1 +??.?..?####?#?#????# 1,14 +???###?##??#?# 9,1,1 +??.#??.???##? 1,3,5 +??#??#???????? 1,2,1,2 +?.###??##??.?#.. 9,1 +?????#???? 1,1 +#??????#?#???.?##?. 1,8,3 +.?.??###?# 1,7 +?????????##???.???# 1,2,1,4,2 +?.?#???#???#.???? 2,1,2,2,1 +#????#??????.?? 4,3,1,1,1 +??????????.? 3,3,1 +?????.??#?## 2,4 +?###?#??.????..? 8,2,1 +?????.##???.?? 3,4,1 +#??????.??# 1,3,2 +?#?????????#?.?? 7,3 +????#??#?.??????. 5,1,5 +.?#?#??#?.???### 8,1,3 +??.?#???.???????.? 2,4,1,5,1 +??.??#????.#?#???? 1,1,2,1,1,3 +????????.???# 1,1,1,2 +???#??#?#??.????#. 5,2,5 +??.??.?#?.#?#? 2,2,1,4 +.#????.#???????.?? 1,1,1,5 +???###??????????.?? 15,1 +???????##.??.??# 6,2,1,1,1 +???????.??? 6,2 +????????.?#?#.??#??. 3,3,3,4 +????#?..?.. 3,1 +?#??#?###???##?#?? 2,13 +????###??? 2,4,1 +??.?#??####?.??##??? 9,6 +?#???..???.????? 4,2,1,2 +??#??##???? 3,2 +?#??#?##?????# 1,2,6,1 +..????..???? 4,1,2 +?#????.???..#???? 2,2,2,2,2 +?#????????#??#??? 1,13 +#???..#???????# 1,1,1,7 +#?#.#????.?? 3,1,1,1 +?.???????..?.?? 1,4 +?.#??.????? 1,1,1 +??#?.?????#. 3,3,2 +.?.#??##?##???#? 1,12 +??#????#??.#? 8,1 +??#???..####?#??#? 5,7,2 +???.#?#?????#?????? 1,6,2,2 +??.???????#??##?#.. 1,2,4,4 +#.??????????#???? 1,1,11 +???#?#???#???. 1,4,2,2 +?????.????? 1,1,4 +??????#??##??. 9,1 +??#???#?.??? 6,1 +????.???##?.??.#??? 2,5,1,2,1 +??.#?.?..?#????.?? 1,3 +?#?#.??#.? 3,1 +##??#?.#?????#?????? 3,1,3,1,1,4 +????.?#???#??#?? 1,1,5,2,1 +?????..?????? 4,5 +??#..?#.?.????????#? 1,2,6,1 +?#??#?##???#???#???. 2,8,1,1 +????#????#.????.#? 1,5,1,1,1,1 +?????????# 1,1,2 +??#???##??. 3,4 +?#?????#???#?? 1,1,6 +??#??.#?#???#?????? 2,1,5,3 +??????????#???#. 2,6,1 +?????#?#??????#????? 11,1,1,1 +?????#.?.?...??.?# 1,3,1,1,1,1 +??#.#???#???????? 1,1,10,1 +???#?.????.??#??# 1,3,1,1,6 +#??????#.??#?.? 2,1,1,1,2 +?.???????.??? 5,1 +???#...?#?? 1,1,2 +????.?????????.? 1,8 +?##?#?##?#???###??? 3,14 +??????#???#?#?#???#? 1,16 +?.?????????????? 1,2,1,4,1 +?..?.?#??##?..?????? 1,1,6,2,1 +.?###?#?.??# 7,2 +???#.#????.???? 1,2,3,1,3 +?#.????#????? 2,1,5,1 +#.##?????.#..??#???? 1,2,2,1,5 +??#?##????.#???.?.?? 3,2,1,4,1,1 +?.??#.?????#?#.. 3,6 +????##??#??? 1,1,7 +??.#?##??.? 1,6,1 +??.???#?.??##????? 1,1,6,1 +?#??.????###??.? 2,9 +?????#??#???#.??. 1,7,1,1 +?????????#? 2,3,1 +#?????????.???? 8,4 +??.#?.#?.?? 2,1,1 +.????##?????#?#? 6,4 +#??????.?#????? 1,2,6 +?#???????. 3,4 +???.???##???.??#? 1,8,2 +.#???#??#????#??? 1,13 +?.?????#????? 1,2,1,4 +??.??????? 1,3 +.????#??#?????# 8,1,1 +.??#???#????????? 3,4,3 +#?????#???#?#?.????? 7,4,1,1 +???#.?.#??.??????? 4,1,1,1,4 +???????#?? 3,3 +??#???#???? 3,6 +?????#????.?? 5,1,1 +.???#?#..##.? 2,3,2,1 +?#?.?????#?#?? 2,1,5 +#.????.?????? 1,4,2,1 +???#???..?#??#???. 6,6 +#???.#?#?????#?? 4,10 +#????????? 2,1,3 +?#??#?#.?#?#???# 1,1,1,4,2 +???????##?#?? 2,7 +..??#?????.?#??? 5,3 +..????????.???.? 1,1,2,1 +?.??#????#?? 4,1 +???.??.????.??. 1,2 +.?????????###.?#?? 5,1,3,1 +???.?#????#????? 1,8,1 +??.??.???.??? 2,1,3,1 +?.??###???????.. 4,3 +????????????.#??? 3,3,1,2 +???#?.#?###??#??? 1,3,5,1,2 +?#??#???..??#?.. 7,4 +#.??##?????. 1,1,4,1 +?.??.#????#?#??#? 1,1,12 +????#??#?.? 7,1 +????#??.?? 2,3 +?..??#?.????# 3,1,2 +?.#?#???#???.#? 1,5,3,1 +##??#?#???###?? 2,11 +???#####??????? 2,10 +??#?#?#?.?. 6,1 +????..????..#?#. 1,1,3,1,1 +.#?????#???##?#??? 14,1 +#.??.?.??#.?.?? 1,2,3,1,1 +?#??????.????.???.? 3,1,1,2,3,1 +?.?.???#?? 1,1,2 +??#?##????? 4,1 +?.?#??.??. 2,1 +??.???#.?? 1,1 +##.?.?#?????.#? 2,5,1 +?##?#.???????. 5,1,4 +..?##???#.???? 6,2 +.???.??????#?#?. 1,7 +?????#.??#? 2,1,2 +.#?.#?????????? 1,1,1,5,1 +???.?????##??..? 2,1,1,4,1 +?????##..? 5,1 +#?????????#???? 1,3,1,3,1 +?#????..???????##? 1,1,10 +???#????#.??.????#? 1,2,1,1,2,6 +??##.?.???.??..#? 3,3,1,2 +?.?#?#?.???#?#??? 4,4 +?##???.??#?.? 2,1,1 +#?.??##??.?.#?????? 1,6,1,1,1 +???#??#???.?##?? 7,3 +?##??.?.?#????????#? 3,2,1,1 +?..?#?.##?#?.? 2,5 +?..??????? 1,2,2 +??#?????.#???#??. 4,7 +????.?????.. 2,4 +.??#?.??.??..??????# 3,1,1,4,1 +#???#?###??##?.? 1,11 +??#??.???????#??#? 5,10 +?.??#?..##?. 1,3,3 +??.???.?.? 2,2 +#??????##?##.?? 4,6,1 +???????.?#????.?? 2,1,2,3,1 +.??#???#???#?##.#.?? 13,1 +??.??#?#?? 1,5,1 +?#?#?#.?????.?? 2,3,2,2,1 +????.???#????#? 1,1,2,4 +.?????.????#. 2,1,1,1 +.???.????.?? 1,1,1,1 +?.????.?#.??#. 4,2,2 +??????.?.???#?? 1,1,5 +????????.?#???#?? 5,5 +????####??##?? 7,5 +.??##??????.???.? 10,1 +#??#???#??#??? 1,3,4,1 +.#???.????? 2,3 +..??#??#??#??#?? 2,8 +??????##??.???? 2,1,4,1 +??????##??????????? 1,5,5,1,1 +??#?.??????.?????? 3,1,1,1,1,2 +???#.?#??? 2,2 +##.??????#????# 2,2,8 +?#????????? 5,3 +?#?..????.?# 2,1,2 +#??.?.#???#????# 1,1,1,3,1 +?..??.??????? 1,1,1,2 +?#?.?######?#???? 2,7,1,1 +??##???.?###? 5,3 +??#.??##..???????? 2,4,4 +??????.#.??##?. 2,1,5 +????#?.??? 1,2,1 +.???????.?.? 2,2,1 +?????#???????? 2,3,2,1 +?.??.#?#?# 1,5 +??.???.?????.?? 1,2,1,1,1 +???.?..??? 1,1,2 +????.?.??.? 1,2 +?.????#??? 2,3 +?????#???????.?? 7,2,1,1 +???????.?## 1,4,3 +?.?#?????? 4,1 +??????#????#..?????? 11,3,1 +#?##????##???##.? 4,1,7,1 +?#???##??????##?#? 2,3,1,4,1 +??..#?????#??.?? 1,9 +?###.????.???#???? 3,2,1,6 +???#????.????##??. 3,1,4 +????#???.?##?. 1,1,2 +.???#??##?#?# 1,6 +#??.?????.?.? 3,4 +?.??#?#?#????? 8,1 +?????.????? 1,1,2 +?.#???#????????#.#? 1,8,4,2 +???#???#??#??????#.? 6,1,2,2,2 +????.???.??????#? 2,1,7 +??#.?????.?. 1,2,1,1 +?#?##???.?#???????# 1,5,1,2,1,1 +??????#?#.??? 3,3 +??##??????..#??. 7,2 +????.?.??.? 1,1 +?????#??#? 2,1,2 +???#?.???????# 4,1,3 +??##????#?#?? 5,1,1,1 +??##?.#?.#????????. 1,2,1,1,1,4 +?.??.???.#. 2,1,1 +???#??#?????###???.. 9,6 +???????.???#.?# 1,2,3,2 +???#?.####??????. 1,3,6,1,1 +#?#??#?????###?#. 1,8,3,1 +???#?????? 1,3,2 +#?#??????#??#?.?? 13,2 +.?????#.??#? 1,1,1,2 +.###..?.???#??.?? 3,1,6,1 +#??#???#?..?????###? 1,6,3,3 +.??????#???. 1,3,1,2 +#????#??.??????#?? 1,1,1,1,1,5 +?????.??#??#???#?? 4,11 +????#???#??????? 6,1 +.??##?.?..?.#??#. 4,1,1,1,1 +???#?????#??? 2,5 +#?????.?????.?#? 3,1,5,3 +??.#??#?#.? 2,1,1 +?#.?????????.?. 1,7,1 +###???#?????#????#.. 13,1,1 +..???????.?.#.?? 1,4,1,1,1 +??.#?#????????? 3,1 +.????????.??#?#??? 5,7 +?#.????????#???.? 1,2,1,4,1 +?#.??##????#??#####? 1,6,8 +???.?#?#???#?#. 2,5,3 +##..?#????.# 2,6,1 +#??#.#???##.. 1,1,1,4 +.?.?##?????.?? 3,1 +.#..#.??#??#?##?##.. 1,1,11 +.?.?????##???#?. 1,7,3 +?#???#????#???# 2,3,2,1 +?##?#????.?# 7,1 +?..??#?????? 1,1,1,4 +..#?.?#?.???#???#? 1,2,4,3 +????????.????? 3,2,4 +???.???#?.?...# 1,1,2,1 +#??###???#??? 6,2 +?.?.?.?.#.?? 1,1,1,1 +.?##?#??.??#???##?. 5,7 +??.?????#?????? 2,9,1 +.?#..?##??..#??# 2,4,4 +????.??????#?????? 1,9,2 +.????.##???? 1,2,4 +.???.??.#?? 2,1,2 +..???#???? 1,3 +.??#???..?? 2,2,1 +?#?#?????????.???? 13,2 +???.??#??... 2,3 +???.?#????#??. 1,6 +?.??##??##????? 8,1 +?.??#?###??#.?#?? 9,1 +??###.?????#????##? 1,3,8,2 +?????#??#.#.???###? 1,5,1,7 +?...?#????. 2,2 +????.??#?.???? 2,3,2 +??.?????#.. 2,3 +#??#??????.. 2,2,2,1 \ No newline at end of file diff --git a/day-12/part-1/vanyle.nim b/day-12/part-1/vanyle.nim new file mode 100644 index 0000000..e52344e --- /dev/null +++ b/day-12/part-1/vanyle.nim @@ -0,0 +1,116 @@ +from times import cpuTime +from os import paramStr + +import tables, strutils, sequtils, sugar, hashes + +func parseInput(s: string): seq[(string, seq[uint8])] = + let lines = s.strip.splitLines + for i in lines: + var s = i.split(" ",2) + + result.add(( + s[0], + s[1].split(",").map(x => x.parseInt().uint8) + )) + + +type LinkedString = object + c: char + h: Hash + n: int32 # index to next element. + +var memory: seq[LinkedString] + +proc addAtEnd(ll: int32, c: char): int32 = + var lh = hashes.hash(0) + if ll != -1: + lh = memory[ll].h + + var ls = LinkedString( + c: c, + n: ll, + h: lh !& hash(c) + ) + memory.add(ls) + return memory.len.int32 - 1 + +proc toLinkedString(s: string): int32 = + var current = -1.int32 + for i in s: + current = current.addAtEnd(i) + return current + +proc hash(ll: int): Hash = + if ll == -1: return hash(0) + return memory[ll].h + +var hints: seq[uint8] +var memoTable: Table[(int32, uint8, uint8), int] +proc possibilities(pattern: int32, hintSlice: uint8, counterSeq: uint8): int = + # Recursion, my boy!! + if (pattern, hintSlice, counterSeq) in memoTable: + return memoTable[(pattern, hintSlice, counterSeq)] + + if pattern == -1: + if hintSlice > 1: + return 0 + if hintSlice == 0 and counterSeq == 0: + return 1 + if hintSlice == 1 and counterSeq == hints[0]: + return 1 + return 0 + + var brokenCounter = counterSeq + var pp = pattern + + while pp != -1: + var el = memory[pp] + if el.c == '#': + inc brokenCounter + elif el.c == '.': + if brokenCounter == 0: + pp = el.n + continue + if hintSlice == 0: + return 0 + if hints[hintSlice-1] == brokenCounter: # ok! + var r = possibilities(el.n, hintSlice - 1, 0) + memoTable[(pattern, hintSlice, counterSeq)] = r + return r + else: + return 0 # impossible! + elif el.c == '?': + var p1 = el.n.addAtEnd('.') + var c1 = possibilities(p1, hintSlice, brokenCounter) + + var p2 = el.n.addAtEnd('#') + var c2 = possibilities(p2, hintSlice, brokenCounter) + + memoTable[(pattern, hintSlice, counterSeq)] = c1 + c2 + return c1 + c2 + pp = el.n + + # make sure the counter and the hint match here. + return possibilities(-1, hintSlice, brokenCounter) + +proc run(s: string): string = + var r = parseInput(s) + var res = 0 + memory = newSeqOfCap[LinkedString](3000) + + for i in r: + hints = i[1] + memoTable.clear() + memory.setLen(0) + var p = possibilities(i[0].toLinkedString(), i[1].len.uint8, 0) + res += p + return $res + + +var input: string = paramStr(1) + +var t0 = cpuTime() +var output = run(input) + +echo "_duration:", (cpuTime() - t0) * 1000 +echo output diff --git a/day-12/part-2/vanyle.nim b/day-12/part-2/vanyle.nim new file mode 100644 index 0000000..cca538d --- /dev/null +++ b/day-12/part-2/vanyle.nim @@ -0,0 +1,91 @@ +from times import cpuTime +from os import paramStr + +import tables, strutils, sequtils, sugar, hashes + +func parseInput(s: string): seq[(string, seq[uint8])] = + let lines = s.strip.splitLines + for i in lines: + var s = i.split(" ",2) + + result.add(( + s[0], + s[1].split(",").map(x => x.parseInt().uint8) + )) + + +var hints: seq[uint8] +var memoTable: Table[(string, int16, uint8, uint8), int] +proc possibilities(pattern: string, pslice: int16, hintSlice: uint8, counterSeq: uint8): int = + # Recursion, my boy!! + if (pattern, pslice, hintSlice, counterSeq) in memoTable: + return memoTable[(pattern, pslice, hintSlice, counterSeq)] + + if pslice == -1: + if hintSlice > 1: + return 0 + if hintSlice == 0 and counterSeq == 0: + return 1 + if hintSlice == 1 and counterSeq == hints[0]: + return 1 + return 0 + + var brokenCounter = counterSeq + + for j in countdown(pslice, 0): + if pattern[j] == '#': + inc brokenCounter + elif pattern[j] == '.': + if brokenCounter == 0: continue + if hintSlice == 0: return 0 + if hints[hintSlice-1] == brokenCounter: # ok! + var r = possibilities(pattern, j-1, hintSlice - 1, 0) + memoTable[(pattern, pslice, hintSlice, counterSeq)] = r + return r + else: + return 0 # impossible! + elif pattern[j] == '?': + var p1 = pattern[0.. x.split("\n")) + +proc isHorizontalSym(pattern: seq[string], l: int): int = + var errCount = 0 + for i in (l+1).. pattern.len : OK + # match: 0 --> l: OK (and they are disjointed!) + + for j in 0..= 2: + return errCount + return errCount + +proc isVerticalSym(pattern: seq[string], l: int): int = + var errCount = 0 + for i in (l+1)..= 2: + return errCount + return errCount + +proc findSymetry(pattern: seq[string]): (bool, int) = + for l in 0..<(pattern.len-1): + if pattern.isHorizontalSym(l) == 0: + return (false, l) + + for l in 0..<(pattern[0].len-1): + if pattern.isVerticalSym(l) == 0: + return (true, l) + + return (false, -1) + +proc run(s: string): string = + var r = parseInput(s) + var res = 0 + + for pattern in r: + var (symDir, symPos) = findSymetry(pattern) + if symDir: # vertical + res += (symPos+1) + else: + res += 100 * (symPos+1) + + return $res + + +var input: string = paramStr(1) + +var t0 = cpuTime() +var output = run(input) + +echo "_duration:", (cpuTime() - t0) * 1000 +echo output diff --git a/day-13/part-2/vanyle.nim b/day-13/part-2/vanyle.nim new file mode 100644 index 0000000..f4e398b --- /dev/null +++ b/day-13/part-2/vanyle.nim @@ -0,0 +1,93 @@ +from times import cpuTime +from os import paramStr + +import strutils, sugar, sequtils + +proc parseInput(s: string): seq[seq[string]] = + return s.strip.split("\n\n").map(x => x.split("\n")) + +proc isHorizontalSym(pattern: seq[string], l: int): int = + var errCount = 0 + for i in (l+1).. pattern.len : OK + # match: 0 --> l: OK (and they are disjointed!) + + for j in 0..= 2: + return errCount + return errCount + +proc isVerticalSym(pattern: seq[string], l: int): int = + var errCount = 0 + for i in (l+1)..= 2: + return errCount + return errCount + +proc toggle(c: char): char = + if c == '.': + return '#' + else: + return '.' + +proc run(s: string): string = + var r = parseInput(s) + + var res = 0 + + for idx in 0..= 0 and s[pi-1][j] == '.': + s[pi-1][j] = 'O' + s[pi][j] = '.' + dec pi + +proc run(s: string): string = + var r = parseInput(s) + r.tiltNorth() + + var res = 0 + for i in 0..= 0 and s[pi-1][j] == '.': + s[pi-1][j] = 'O' + s[pi][j] = '.' + dec pi + +proc tiltWest(s: var seq[string]) = + for i in 0..= 0 and s[i][pj-1] == '.': + s[i][pj-1] = 'O' + s[i][pj] = '.' + dec pj + +proc tiltSouth(s: var seq[string]) = + for i in countdown(s.len-2, 0): + for j in 0..= lstate.len: return false + if x < 0 or x >= lstate[y].len: return false + + if d in lstate[y][x]: return false + lstate[y][x].incl d + return true + +var lstate: array[110,array[110, set[Dir]]] +proc simulateLight(level: seq[string], entryi = 0, entryj = 0, entryd: Dir = Right): array[110,array[110, set[Dir]]] = + # Zero out lstate: + for i in 0.. 0: + var (i, j) = toProcess.pop() + let rays = lstate[i][j] + for r in rays: + for lbit in processLightBit((i,j), level, r): + var (y,x,newd) = lbit + if lstate.updateState(y,x,newd): + toProcess.add((y, x)) + + return lstate + +proc energized(lstate: array[110, array[110,set[Dir]]]): int = + for i in 0.. 0: + inc result + +proc run(s: string): string = + var r = parseInput(s) + var lstate = simulateLight(r) + + return $energized(lstate) + +var input: string = paramStr(1) + +var t0 = cpuTime() +var output = run(input) + +echo "_duration:", (cpuTime() - t0) * 1000 +echo output diff --git a/day-16/part-2/vanyle.nim b/day-16/part-2/vanyle.nim new file mode 100644 index 0000000..34dcfbc --- /dev/null +++ b/day-16/part-2/vanyle.nim @@ -0,0 +1,130 @@ +from times import cpuTime +from os import paramStr + +import strutils + +proc parseInput(s: string): seq[string] = + return s.strip.split("\n") + +type Dir = enum + LEFT = 0, + DOWN = 1, + RIGHT = 2, + UP = 3 + +proc dirTuple(d: Dir): (int, int) = + case d: + of LEFT: return (0, -1) + of RIGHT: return (0, 1) + of UP: return (-1, 0) + of DOWN: return (1, 0) + +iterator processLightBit(lpos: (int, int), level: seq[string], d: Dir): (int, int, Dir) = + # Returns the position of light to change, if needed. + let c = level[lpos[0]][lpos[1]] + var lightPos = lpos + var ldir = dirTuple(d) + if c == '.': + lightPos[0] += ldir[0] + lightPos[1] += ldir[1] + yield (lightPos[0], lightPos[1], d) + elif c == '/' or c == '\\': + var newDir = d + if c == '/': + if d == LEFT: newDir = DOWN + elif d == DOWN: newDir = LEFT + elif d == UP: newDir = RIGHT + elif d == RIGHT: newDir = UP + elif c == '\\': + if d == LEFT: newDir = UP + elif d == UP: newDir = LEFT + elif d == DOWN: newDir = RIGHT + elif d == RIGHT: newDir = DOWN + + ldir = dirTuple(newDir) + lightPos[0] += ldir[0] + lightPos[1] += ldir[1] + yield (lightPos[0], lightPos[1], newDir) + + elif c == '-': + if d == LEFT or d == RIGHT: + lightPos[0] += ldir[0] + lightPos[1] += ldir[1] + yield (lightPos[0], lightPos[1], d) + else: + yield (lightPos[0], lightPos[1]-1, LEFT) + yield (lightPos[0], lightPos[1]+1, RIGHT) + elif c == '|': + if d == UP or d == DOWN: + lightPos[0] += ldir[0] + lightPos[1] += ldir[1] + yield (lightPos[0], lightPos[1], d) + else: + yield (lightPos[0]+1, lightPos[1], DOWN) + yield (lightPos[0]-1, lightPos[1], UP) + +proc updateState(lstate: var array[110,array[110,set[Dir]]], y: int, x: int, d: Dir): bool = + # Check for out of bounds. + if y < 0 or y >= lstate.len: return false + if x < 0 or x >= lstate[y].len: return false + + if d in lstate[y][x]: return false + lstate[y][x].incl d + return true + +var lstate: array[110,array[110, set[Dir]]] +proc simulateLight(level: seq[string], entryi = 0, entryj = 0, entryd: Dir = Right): array[110,array[110, set[Dir]]] = + # Zero out lstate: + for i in 0.. 0: + var (i, j) = toProcess.pop() + let rays = lstate[i][j] + for r in rays: + for lbit in processLightBit((i,j), level, r): + var (y,x,newd) = lbit + if lstate.updateState(y,x,newd): + toProcess.add((y, x)) + + return lstate + +proc energized(lstate: array[110, array[110,set[Dir]]]): int = + for i in 0.. 0: + inc result + +proc run(s: string): string = + var r = parseInput(s) + + var menergy = 0 + + for i in 0.. 0: + let current = frontier.pop + if current.node == goal: + for node in backtrack(cameFrom, start, goal): + yield node + break + + for next in graph.neighbors(current.node): + let cost = current.cost + D( graph.cost(current.node, next) ) + if not cameFrom.hasKey(next) or cost < `[]`(cameFrom, next).cost: + `[]=`(cameFrom, next, (node: current.node, cost: cost)) + let priority: D = cost + calcHeuristic[G, N, D]( + graph, next, start, goal, current, cameFrom ) + frontier.push( (next, priority, cost) ) + +## ======================================================================= + +proc parseInput(s: string): seq[seq[int8]] = + var lines = s.strip.split("\n") + result = newSeq[seq[int8]](lines.len) + for i in 0..= 0 and node[1] >= 0 and node[0] < grid.len and node[1] < grid[node[0]].len + if isOk: + yield node + +iterator neighbors*(grid: MyG, node: MyN): MyN = + var (y, x, d) = node + + if y == grid.len - 1 and x == grid[0].len - 1: + for i in Dir: + yield (y, x, i) + elif y == 0 and x == 0: + for i in Dir: + yield (y, x, i) + + if d == Up or d == Down: + for i in 1..3: + validatePos(grid, (y, (x-i).int16, Left)) + validatePos(grid, (y, (x+i).int16, Right)) + + elif d == Left or d == Right: + for i in 1..3: + validatePos(grid, ((y-i).int16, x, Up)) + validatePos(grid, ((y+i).int16, x, Down)) + +proc cost*(grid: MyG, a: MyN, b: MyN): int = + if a[0] == b[0] and a[1] == b[1]: + return 0 + + for i in min(a[0],b[0])..max(a[0],b[0]): + for j in min(a[1],b[1])..max(b[1],a[1]): + if i != a[0] or j != a[1]: + result += grid[i][j] + +proc heuristic*(grid: MyG, a: MyN, b: MyN): int = + return max(a[0] - b[0], a[1] - b[1]) + +proc run(s: string): string = + var r = parseInput(s) + + var start = (0.int16, 0.int16, Down) + var dest = ((r.len - 1).int16, (r[0].len - 1).int16, Right) + var pcost = 0 + + var currentPos = start + for pt in path[MyG, MyN, int](r, start, dest): + if currentPos != pt: + pcost += r.cost(currentPos, pt) + currentPos = pt + + return $pcost + + +var input: string = paramStr(1) + +var t0 = cpuTime() +var output = run(input) + +echo "_duration:", (cpuTime() - t0) * 1000 +echo output diff --git a/day-17/part-2/vanyle.nim b/day-17/part-2/vanyle.nim new file mode 100644 index 0000000..0bc858f --- /dev/null +++ b/day-17/part-2/vanyle.nim @@ -0,0 +1,161 @@ +from times import cpuTime +from os import paramStr + +import heapqueue, tables, hashes, options, strutils + +# A Star implementation, from the astar package. + +type + Distance* = int|float + Node* = concept n + `==`(n, n) is bool + `hash`(n) is Hash + + Graph* = concept g + var node: Node + for neighbor in g.neighbors(node): + type(neighbor) is Node + cost(g, node, node) is Distance + + Point* = concept p + p.x is Distance + p.y is Distance + + +type + FrontierElem[N, D] = tuple[node: N, priority: D, cost: D] + CameFrom[N, D] = tuple[node: N, cost: D] + +proc `<`(a, b: FrontierElem): bool = a.priority < b.priority + +iterator backtrack[N, D]( + cameFrom: Table[N, CameFrom[N, D]], start, goal: N +): N = + yield start + var current: N = goal + var path: seq[N] = @[] + while current != start: + path.add(current) + current = `[]`(cameFrom, current).node + + for i in countdown(path.len - 1, 0): + yield path[i] + +proc calcHeuristic[G: Graph, N: Node, D: Distance] ( + graph: G, + next, start, goal: N, + current: FrontierElem[N, D], + cameFrom: Table[N, CameFrom[N, D]], +): D {.inline.} = + when compiles(graph.heuristic(next, start, goal, current.node)): + return D(graph.heuristic(next, start, goal, current.node)) + + elif compiles(graph.heuristic(next, start, goal, current.node, none(N))): + var grandparent: Option[N] + if cameFrom.hasKey(current.node): + grandparent = some[N]( `[]`(cameFrom, current.node).node ) + else: + grandparent = none(N) + return D(graph.heuristic(next, start, goal, current.node, grandparent)) + + else: + return D(graph.heuristic(next, goal)) + +iterator path*[G: Graph, N: Node, D: Distance](graph: G, start, goal: N): N = + var frontier = initHeapQueue[FrontierElem[N, D]]() + frontier.push( (node: start, priority: D(0), cost: D(0)) ) + var cameFrom = initTable[N, CameFrom[N, D]]() + + while frontier.len > 0: + let current = frontier.pop + if current.node == goal: + for node in backtrack(cameFrom, start, goal): + yield node + break + + for next in graph.neighbors(current.node): + let cost = current.cost + D( graph.cost(current.node, next) ) + if not cameFrom.hasKey(next) or cost < `[]`(cameFrom, next).cost: + `[]=`(cameFrom, next, (node: current.node, cost: cost)) + let priority: D = cost + calcHeuristic[G, N, D]( + graph, next, start, goal, current, cameFrom ) + frontier.push( (next, priority, cost) ) + +## ======================================================================= + +proc parseInput(s: string): seq[seq[int8]] = + var lines = s.strip.split("\n") + result = newSeq[seq[int8]](lines.len) + for i in 0..= 0 and node[1] >= 0 and node[0] < grid.len and node[1] < grid[node[0]].len + if isOk: + yield node + +proc cost*(grid: MyG, a: MyN, b: MyN): int = + if a[0] == b[0] and a[1] == b[1]: + return 0 + + for i in min(a[0],b[0])..max(a[0],b[0]): + for j in min(a[1],b[1])..max(b[1],a[1]): + if i != a[0] or j != a[1]: + result += grid[i][j] + +proc heuristic*(grid: MyG, a: MyN, b: MyN): int = + return max(abs(a[0] - b[0]),abs(a[1] - b[1])) + +iterator neighbors*(grid: MyG, node: MyN): MyN = + var (y, x, d) = node + + if y == grid.len - 1 and x == grid[0].len - 1: + for i in Dir: + yield (y, x, i) + elif y == 0 and x == 0: + for i in Dir: + yield (y, x, i) + + if d == Up or d == Down: + for i in 4..10: + validatePos(grid, (y, (x-i).int16, Left)) + validatePos(grid, (y, (x+i).int16, Right)) + + elif d == Left or d == Right: + for i in 4..10: + validatePos(grid, ((y-i).int16, x, Up)) + validatePos(grid, ((y+i).int16, x, Down)) + +proc run(s: string): string = + var r = parseInput(s) + + var start: MyN = (0, 0, Down) + var dest: MyN = ((r.len - 1).int16, (r[0].len - 1).int16, Right) + var pcost = 0 + + var currentPos = start + for pt in path[MyG, MyN, int](r, start, dest): + if currentPos != pt: + pcost += r.cost(currentPos, pt) + currentPos = pt + + return $pcost + + +var input: string = paramStr(1) + +var t0 = cpuTime() +var output = run(input) + +echo "_duration:", (cpuTime() - t0) * 1000 +echo output