From ecfe1aad353ec0ec1aee6800edd295c26dbd3036 Mon Sep 17 00:00:00 2001 From: Daniel Heras Quesada Date: Sun, 14 Dec 2025 23:39:10 +0100 Subject: [PATCH] chore: day_10 A done but file read to slow WIP --- README.md | 2 +- src/exercises/assets/day_10_input.txt | 177 ++++++++++++++++++++++++++ src/exercises/day_10.ts | 133 +++++++++---------- 3 files changed, 237 insertions(+), 75 deletions(-) create mode 100644 src/exercises/assets/day_10_input.txt diff --git a/README.md b/README.md index 54abf69..d8ee502 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,4 @@ | 7 | Laboratories | ⭐ | 🌓 | | 8 | Playground | ⭐ | ⭐ | | 9 | Movie Theater | ⭐ | 🌓 | -| 10 | Factory | | | +| 10 | Factory | 🌓 | | diff --git a/src/exercises/assets/day_10_input.txt b/src/exercises/assets/day_10_input.txt new file mode 100644 index 0000000..a366e83 --- /dev/null +++ b/src/exercises/assets/day_10_input.txt @@ -0,0 +1,177 @@ +[...#...] (0,2,3,6) (0,1,4,6) (1,3,4,5) (1,2,4,6) (0,2,3,4,5) (2,3,6) (1,2) (2,3,4,5,6) {37,24,84,71,44,32,71} +[...##.] (0,3,4) (0,1,2,5) (0,1,3,4,5) (3,4) {53,34,17,42,42,34} +[###.] (1,3) (0,1,2) {4,13,4,9} +[.#.....] (0,1,6) (0,2,4) (1,3,4,6) (0,1,3,5) (4,5) {219,37,194,30,211,23,19} +[...##] (1,2) (0,2,3) (0,3) (1,3) (2,3,4) {10,20,23,37,14} +[#.##] (1,3) (2) (0,1,2) (2,3) {16,26,38,24} +[#...] (1,3) (0,1) (0,3) (1) (2,3) {2,13,11,15} +[.###.#.] (0,3,6) (0,1,2,5,6) (1,2,3,4,5) (0,1,2,3,4,5) (0,1,4,5) (0,4,6) {76,41,23,27,48,41,50} +[#...#..###] (2,3,5,6,7,8,9) (0,4,6,7,8,9) (1,7,8) (0,1,2,8) (0,1,2,3,4,5,6,9) (0,2,3,4,5,7) (1,6,8) (1,6,9) {56,71,48,29,37,29,50,54,76,31} +[####...] (0,1,2,3,4,6) (1,2,4) (1,3,5) (0,2,5) (4,6) (0,1,4,5,6) (3,5,6) (3) (0,1,2,5) {32,56,31,49,53,50,48} +[#...#.##] (0,4,6,7) (0,3,5,6) (0,1,3,4) (0,1,2,5,6,7) (0,1,2,5,7) (0,2,3,4,5,6) {202,164,169,27,19,189,185,175} +[##....#.#] (2,3,8) (3,4,7) (1) (1,2,3,5,6,8) (5,8) (0,1,5,6,8) (4,6,7,8) (0,3,4,5,7,8) {15,17,16,20,15,21,27,15,45} +[##.#] (0,1,2) (0,1) (1,3) (2,3) (0,2) {176,12,167,3} +[....#....#] (0,3,6) (1,3,4) (3,4,5,9) (0,1,3,5,6,7,8,9) (1,2,3,4,6,8,9) (1,2,3,4,6,7,8,9) (2,5) (4,5,6,7) {19,29,5,35,36,44,41,38,19,23} +[####.##] (2,4) (0,1,6) (0,1,2,3,6) (1,2,4) (0,2,4,5,6) {36,207,217,13,204,13,36} +[#.#..##.] (0,1,2,3,4,5) (0,1,6,7) (5,7) (2,3,5,7) (2) (0,1,4) (2,3,4) (4,5) (0,2,3,4,5,7) {62,44,46,37,54,48,19,45} +[#.#.#.] (0,2,4) (1,3,4,5) (2) (1,2,3,4,5) {2,21,31,21,23,21} +[#...##..#] (0,3,4,7,8) (0,1,2,3,4,5,7) (2,3,4,6,7,8) (4,6,7) (6,7) (0,1,2,3,4,5,8) (2,4,5,6,7) (1,2,4,5,6) {46,38,60,60,78,46,48,75,41} +[..##.##] (2,4) (3,4) (2,4,5) (2,3,5,6) (0,1,2,3,6) (0,1,6) {32,32,57,38,49,24,37} +[####.####.] (0,1,2,3,5,6,7,8) (0,1,3,4,6,8) (1,3) (0,1,3,4,5,6,7) (0,2,3,4,5,8) (0,3,4,5) (2,7) (1,3,4,7,8,9) (0,1,2,4,6,9) (0,1,2,4,5,6,7,8,9) {48,51,33,56,55,42,32,53,36,25} +[#.....] (0,1,2,4,5) (0,1,3,4) (1,2,3) (3,4,5) (0,3,4) (0,2,4,5) {56,38,35,48,73,47} +[#.###] (0,1,2) (0,1,3) (0,2,3) (0,2,3,4) (2,3,4) {24,14,24,24,16} +[#.##.#..##] (1,2,6,7,8) (0,1,2,4,5,6,8,9) (0,1,2,3,5,6,7,8,9) (0,1,2,3,6,7,8,9) (0,2,4,8) (0,1,2,3,4,5,6,7,9) (2,3,4,7,8) (0,3,4,5,7,8) {94,71,110,75,83,57,71,84,112,62} +[###..####] (2,3) (3,4,5,7,8) (3,4) (1,4) (2,3,4,5,6,7,8) (2,3,4,6,7,8) (0,1,3,5,7) (0,3,5,6,7) (1,3,5,6,7,8) (0,1,2,4,5,7,8) (1,2,5,8) {44,61,49,85,75,93,48,89,72} +[.#..#.] (0,2) (5) (0,2,3,5) (2,4,5) (1,4,5) (1,4) (0,2,3) (1,2,5) {25,167,41,18,161,196} +[#.##...] (0,4,5,6) (0,1,2,3,4,5) (3,5) (0,2,3,5,6) (0,3,4,5) (0,1) (2,3,4,5,6) (3,4,6) (0,4,6) {68,22,57,101,79,92,63} +[.###....#] (2) (0,3,7,8) (0,7,8) (1,8) (2,6,8) (0,3,5,6) (0,1,2,4,7) {151,19,28,36,14,20,34,131,136} +[######.] (1,3,5) (2,3,4,6) (2,4,5,6) (1,5,6) (0,1,3,5,6) (3,4) (0,1,5) (3,4,5) (0,1,2,3,5) {29,58,119,29,119,169,131} +[#.###.###] (1,3,5) (0,2,3,4,6,8) (0,2,3,4,5,6) (1,3,4,6,7,8) (1,2,4,5,6,7) (0,1,4,6,7) (0,3,4,5,7,8) (2,5) (1,2,3,4,6,7,8) (0,2,3,4,6,7,8) (3,5) {53,44,74,90,86,78,69,59,52} +[..#.#.#] (0,1,3,4,5,6) (1,2,4) (0,3,4) (1,6) (1,3,4,6) {31,59,13,44,57,18,46} +[...#..] (2,3,4,5) (1,2,4) (0,4) (1,2,3,4,5) (1,4) (2) (1,3,5) (0,4,5) {35,28,33,17,76,33} +[...##...##] (0,1,2,3,4,6,7,8,9) (2,3,4,5) (0,1,2,4,5,6,7,8) (0,3,5,6,7,8,9) (3,8,9) (0,2,3,4,9) (1,3,4,5,6,7,8,9) (0,1,5,6,7,8,9) (0,2,3,5,6,7) (5,8) (4,7) (0,1,7,8) {241,49,53,252,65,240,238,246,264,251} +[.##..#] (0,2,3,5) (0) (0,1,3) (1,2,4) (1,3) (0,1,2,4) {32,23,12,15,10,2} +[#####....#] (0,1,4,5,6,7,9) (1,2,3,9) (0,2,3,4,5,6,7,9) (2,4,5,6,8,9) (1,3,5,8) (0,2,3,4,6,7,8,9) (2,3,4,6,8,9) (2,3,8,9) (0,1,2,4,6,7,8,9) (3,5,8,9) (1,2,3,4,5,7,8,9) {39,52,92,86,82,78,73,48,110,114} +[######.##.] (2,3,4,5,6,7,8,9) (2,3,4,6,8) (7,8) (7) (3,7,9) (0,1,2,3,5,7,8) (6,7) (0,1,3,5,7,9) (2,4,5,6,9) (7,9) (0,1,2,4,6) (0,2,3,4,7,8) {32,13,71,65,69,47,69,88,54,62} +[.###......] (1,2,3) (1,2,5,7,9) (1,4,8,9) (2,3,4,5) (0,2,4,5,8) (2,4,8) (0,1,4,6,7,8) (0,6,9) {19,33,37,14,44,8,16,3,41,36} +[.#..#] (1,3) (0) (1,2,3,4) (3,4) (1,2,3) {11,26,22,42,33} +[.##..#] (2,3) (0,1,3,4) (1,3,4) (1,2,5) {20,33,9,24,24,9} +[##..##.] (1,5,6) (0,1,2,3) (0,5,6) (0,1,2,4) (2,3,4,5,6) (0,2,4,5) {19,19,20,19,12,33,32} +[.####] (1,3) (0,1,3) (1,4) (1,3,4) (1,2,3,4) (0,3,4) (0,2,4) {22,50,20,39,49} +[.#.#####] (1,5,6,7) (0,1,2,3,4,5) (1,2,5) (2,3) (2,3,4,5,6) (0,1,2,3,5,7) (0,2,3,4,5,7) (0,1,3,4,5) {58,68,63,82,57,92,34,44} +[..###.####] (0,1,3,7,9) (1,2,4,7,8) (0,1,2,5,7) (1,3,4,5,7,8,9) (0,1,5,6,7,8,9) (0,1,3,4,6,8,9) (1,8) (3,4,9) (0,1,4,5,6) (2,4,7) (2,3,5,6,7,8,9) (0,1,2,4,5,6,9) {27,44,21,21,34,36,30,28,30,32} +[.#.##.#..] (1,5,7,8) (0,2) (0,3,7,8) (0,1,2,4,5,6,7,8) (0,1,3,4,5,6,7) (4,5,8) (0,5,7) {46,33,31,9,33,55,17,48,58} +[##.######.] (0,1,3,4,5,6,7,8) (1,3,5,6,7) (0,3,4,5,6,7,9) (0,2,3,5,7,9) (0,1,7,8) (0,2,8,9) (2,7,8) (0,1,2,3,5,8,9) (4,5) {177,34,28,176,152,179,160,180,35,158} +[###..] (1,3,4) (0,4) (4) (0,2,3,4) (1,2) (2) (0,1,3) {32,22,20,19,31} +[.#.##] (0,1,4) (3,4) (1,2,3) (1,3,4) {173,191,7,25,191} +[#...###] (0,3,4,5,6) (0,1,3,4,5) (0,1,2,3,5) (1,3) (0,1) (0,2,3,4,6) (1,2,3) (3,4,6) (4) {34,42,16,67,64,23,31} +[.#.#..#..#] (0,2,3,4,5,7,8,9) (0,2,3,4,6,7,8,9) (1,3,6,9) (0,5,6,8,9) (1,2,3,4,9) (1,4,5,6,7,9) (0,1,2,3,5,7) (0,1,2,9) (0,1,2,3,4,6,7,8) (3,7) (0,1,2,4,5,7,8,9) {91,77,78,80,84,69,81,89,80,108} +[#....#.] (0,1,2) (1,4,5,6) (1,3,4,5) (2,3,5) (0,3,4,5,6) (0,2,6) (2,3,4,5,6) (1,2,3,4,5,6) {28,30,73,56,43,63,57} +[...###..#] (1,2,4,7,8) (0,1,4,8) (0,2,3,4,5,6,7,8) (2,3,5,6,7) (1,7) (0,4,5,7) (6,8) (0,4) (0,6) {198,54,44,24,210,25,32,64,54} +[....####] (1,3,4,5) (1,3,6) (1,4,5,7) (4,5,6,7) (0,1,3,4,5,6,7) (0,1,4,5,6,7) (0,1,2,3,5,6) {35,74,11,41,73,84,61,58} +[...#.###.] (0,2,3,4,7,8) (2,3,5,6) (0,1,3,4,6,7,8) (0,3,4,5,7) (0,3,4,5,7,8) (0,5) (0,1,2,5,6,7) (0,1,5,6,7,8) (0,2,3,5,6,7,8) {82,41,12,50,41,62,50,70,68} +[#....###.#] (1,2,4,5,6,7,8,9) (1,2,3,4,7) (4) (6,8,9) (0,2,3,4,6,7,9) (0,1,3,5,6) (0,3,4,5,6,8,9) (0,3,5,6,7,8,9) (2,4,7) (2,4,5,6) (4,8) (1,2,4,6,7,8,9) (2,5) {52,40,64,69,92,62,88,52,67,65} +[#.#..#.#] (0,2) (0,2,3,4,5,7) (0,4,5,6,7) (3,4,5) (0,1,3,4,5) (0,1,2,4,6,7) (1,4) (1,2,5,7) (3,4,7) (1,3) {63,63,42,53,91,59,25,46} +[##.###.###] (3,4,7,9) (0,2,3,4,6,7,9) (4,5,7,8,9) (0,4,5,6,7) (0,1,2,3,4,6) (0,1,3,4,5,7,8,9) (0,1,2) (3,4,5,6,7) (0,3,6,7,8,9) (0,2,3,4,5,7,9) (1,7) (0,1,2,3,4,5,7,8) (7,8) {84,63,53,88,96,67,55,104,39,48} +[.##..##..] (0,1,2,3,4,5,7) (0,5,8) (0,1,2,5,8) (0,1,3,4,7,8) (0,1,2,4,5,6,7) (0,1) (0,1,4,5,6,7,8) (2,3,5,6,7,8) (1,2,4,5,7,8) {171,173,65,59,167,180,138,187,170} +[.###.#..] (3,5,6,7) (3,5,7) (1,2,3,4,5,7) (0,1,3,4,5,7) (0,1,2) (0,1,3,4,6,7) (0,2,4) (0,3,4,6) {238,28,28,220,226,10,211,26} +[..##.] (0,1,2,3) (2,3) (1,4) {11,20,21,21,9} +[.###.#####] (0,4,5,6,7,8,9) (2,3,4,5,8,9) (1,2,4,5) (0,1,2,3,4,6,8,9) (1,2,3,5,6,7,8,9) (0,1,4,5,8,9) (0,2,3,4,5,6,7,9) (3,4,5,9) (1,2,3,4,5,6,7,8) {192,65,72,67,229,220,196,179,213,215} +[###..#.#] (2,3,5) (1,4) (1,2,5) (0,1,2,4,5,6) (0,4,6) (3,4) (0,1,2,5) (0,2,3,4,6,7) (2,4,6,7) (0,1,2,3,5,7) {73,48,232,50,216,55,206,190} +[.###..##] (0,1,3,4,5,6,7) (1,2,3,4,6,7) (0,3,4,5) (0,1,4,5,6) (0,2,3,4,6,7) (0,4,6,7) (2,3,6) (0,1,2,3,4,5) (0,7) (4,6) {49,29,39,54,62,33,53,27} +[####] (1,2) (2,3) (0,1,3) (3) (2) (0,1) {18,20,22,31} +[.......#] (0,1,3,4,5,7) (5) (0,2,3,4,5,6) (6) (2,3,4,5,7) (0,1,2,3,7) (0,2,4,6,7) (1,6) (0,1,2,4,5,6) {63,39,164,166,165,151,42,170} +[#.#.] (1,3) (1) (1,2) (0,1,2) (0,3) (3) {25,47,27,25} +[.###] (0,3) (2,3) (1,2,3) (1,3) {132,23,26,165} +[..#...] (0,3,4) (2) (1,2,3,5) (0,1,3,4,5) {19,9,17,25,19,9} +[##.#] (1,2,3) (0,1,3) (0,1,2) {123,138,15,138} +[..##...#.#] (0,1,3,4,6,8,9) (0,8,9) (0,2,4,5,7,8,9) (0,2,3,7) (2,3,5,8,9) (0,1,2,3,4,6,9) (0,3,4,6,8,9) (1,3,6,7,9) (1,2,3,8) (0,6,7,9) {57,57,53,74,43,19,50,39,53,77} +[.#.#..#.#] (1,3,4,5,6,7) (1,7) (2,8) (1,3,4,5,7,8) (0,1,2,4,5,6,7) (0,8) (3,5,8) (1,3,5,6) {8,23,4,17,3,19,6,19,21} +[...######.] (0,2,3,4,6,8,9) (1,3,9) (0,1,2,3,4,5,9) (0,2,4,6,7,9) (3,5) (0,4,5,8) (0,3,5,6,8) (1,2,3,5,6,7,8) {34,3,20,37,24,30,29,8,27,20} +[.#...] (0,2) (1,3) (2,3) (0,4) (2,4) (3) {19,5,152,10,155} +[##.##.#...] (2,4,6,7,8,9) (1,3,9) (2,4) (1,3,5,6) (0,2) (0,1,2,4,6,7,9) (1,6,8) (0,1,3,4,5,6,9) (0,2,3,4,5,6,8,9) (0,1,2,7,8) (2) {40,62,63,38,42,26,60,29,42,44} +[##.###.] (0,3,5,6) (0,1,3,4,5) (0,1,5) (0,3,4,6) (0,1,3,4,6) (0,2,3,5) (4,5) (1,2,5,6) (1,2,4) {50,28,22,34,27,47,21} +[.#.##..##] (3,5,7) (0,1,3) (1,2,5,6) (0,3,6,7,8) (4,6) (5,8) (3,8) (0,3,4,5) (1,2,3) (0,2,3,4,6,7,8) (8) {26,33,25,65,16,34,6,7,35} +[.#...#..] (0,3,7) (1,2,6) (0,1,4,5,6,7) (2,5,6) (0,7) (0,2,5) (1,3,4,5,7) {34,52,23,18,33,37,41,45} +[##..#..#..] (0,1,2,4,5,7,8,9) (3,4,6,9) (0,1,3,5,6,7,8) (0,2,3,4,6,7,8) (1,2,4) (1,3,4,5,6,7,8) (0,1,2,4,5,6) (0,1,5,8,9) (1,3,4,5,6,7,8,9) (0,4,7,9) (0,1,6,7,9) {71,59,35,53,80,48,57,75,63,62} +[###.#....#] (0,2,7,9) (0,5,6,8) (1,2,4,5,7,8,9) (3,7) (0,7,9) (4,6,8) (2,4,8) (3,5,7) (0,1,2,3,4,5,7) (0,1,3,4,5,8) (1,3,5,6,8,9) (2,8) {59,45,56,52,66,51,25,62,73,34} +[.###] (2,3) (0,3) (1,2,3) {107,18,36,143} +[....##] (3,4) (0,5) (0,1,3,5) (2,4) (3,4,5) (4,5) {143,8,16,32,59,173} +[.##.....] (1,4,5,6,7) (0,4,5,6,7) (1,2,4) (2,5,6) (1,2) (0,1,2,3,6,7) (1,2,3,6,7) (1,3,4,5,6,7) {23,167,69,33,139,144,165,148} +[...#..#.#.] (1,3,4) (3,6) (0,1,2,3,4,6,7,8,9) (0,1,3,5,6,7,8,9) (1,2,3,4,7) (2) (0,1,4,6,8,9) (0,1,2,3,4,9) (0,1,3,4,5,7,8,9) (0,3,8,9) (0,1,2,3,6,8,9) (1,2,3,4,6,7,8,9) {89,246,209,234,219,28,69,193,88,107} +[##...#] (1,2,4,5) (1,2,3,4) (0,2,4) (2,4) {15,20,204,17,204,3} +[##...##...] (0,5,9) (0,1) (6) (4,8) (0,1,5,8) (2,3,5,7,8) (0,1,2,4,5,7,9) (0,2,3,4,7,9) (2,3,4,5,6,7,8,9) (0,2,4,7) (0,1,3,4,5,6) (0,3,4,6,8,9) {74,35,52,41,64,60,22,52,38,60} +[.#.###] (2,5) (2,3,4) (1,2,3,4) (0,3,5) (1) {9,9,28,34,25,12} +[.##.#.#] (1,2,3,4) (1,2,4,5) (1,2,6) (0,1,4,6) (2,3,5) (1,2) (1,5,6) {12,48,50,29,36,26,20} +[..####..#] (0,1,2,4,5,7,8) (0,2,3,4,6,7) (0,1,2,3,4) (0,1,2,4,6,7,8) (0,2,3,5,6,8) (2,6,7,8) (1,4,8) (1,3,4,5,7,8) (0,6,8) (1,2,4,5,8) (0,7) {189,54,61,39,72,17,46,152,56} +[###.######] (1,2,4,5,7,8) (0,1,2,3,4,6,8,9) (0,1,2,3,4,5,6,9) (1,5,7,9) (2,3,4) (0,1,2,4,5,6,7,8,9) (3,5,6,7) (0,1,2,4,5,7,9) (0,1,3,4,5,8,9) {52,85,78,55,85,91,46,71,44,69} +[.###..###] (1,2,3,6,7) (2) (1,4,6) (1,2,5,6,8) (0,1,3,5,6,7,8) (1,3,5) (0,3,4,5,7) (0,5) {42,59,23,58,31,51,50,49,17} +[..#.] (0,1,2) (1,2,3) (0,3) (0) (1,2) (0,2,3) {30,27,34,20} +[##.#.#] (0,1,2,5) (0,1,4,5) (2,3) (1,3,4,5) {16,140,8,130,138,140} +[.##.####.#] (2,3,5,7) (0,1,2,6,8) (6) (1,2,4,5,7) (0,2,3,5,6,7,8,9) (1,2,4,5,6,7,9) (0,1,2,5,7,8) (0,3,4,5,6,9) (1,3) (0,1,4,5,7,8) {42,56,53,33,27,63,33,62,41,27} +[.#..#] (0,1,3,4) (1,2,3) (0,3) {23,29,14,37,15} +[#####.#.] (1,2,4,6) (0,1,4,5,6) (0,1,2,3,5,6) (0,1,2,6,7) (1,3,6,7) (0,2,4) (0,3,4,5,6) (6) (2,3,4,5,7) {48,56,30,46,58,43,91,24} +[.#....#] (0,1,5) (1,3,4,5,6) (0,4,6) (1,2,3,4,5) (0,1,2,3,4,6) {32,210,20,208,220,192,218} +[#.#...##] (0,1,2,3,5,6) (0,2,3,4,5,7) (0,2,4) (0,4,6,7) (1,2,7) (1,4,5) (0,2,6,7) {57,40,52,26,42,37,43,47} +[.#....###] (3,6,7,8) (1,2,3,4,5,6) (0,5,7) (2,4,5,6) (1,2,3,6) (2,3,4,5,6,7,8) (1,2,4,5,6,8) {17,38,59,40,40,57,60,26,16} +[#####] (0,1,2,4) (1,3) (2,3) (1,4) (2,3,4) (0,4) {27,33,24,25,32} +[.###] (0,2,3) (1,2,3) {3,3,6,6} +[##...#] (0,1,2,4,5) (0,5) (1,4) (0,2,3,5) (5) (0,1,4) (0,1,2) (2,3) {42,40,40,5,25,27} +[.###] (1,2,3) (0,1,2,3) {15,19,19,19} +[####.#.] (1,4,5,6) (0,1,2,3,5) (0,1,2,3,5,6) (2) (2,3) {35,44,68,51,9,44,26} +[#.####.#.] (1,4,5,6,8) (1,2,6,7) (0,2,3,6,7) (0,3,5,6,7,8) (1,4,7,8) (0,1,2,3,4,5,6,8) (1,4,8) {187,46,195,187,36,27,205,183,38} +[.#.##] (0,2,3,4) (2,3) (1,3,4) (0,1,3) {169,2,183,185,169} +[#.#.###] (0,2,5) (0,5,6) (1,2,3,4,5) (5) (1,4,6) (0,1,3,5,6) {29,31,12,19,19,56,36} +[####..#.##] (2,3,4,5,7,8) (0,1,2,3,5,6,7,8,9) (0,1,2,6) (0,4,5,6,9) (0,1,4,6,7,9) (2,7) (0,2,3,4,5,6,8) (0,1,4,6,8,9) {48,44,45,19,44,20,48,34,31,25} +[.#####.] (1,2,3,5,6) (3,6) (0,1,3,5,6) (1,5) (0,1) (0,2,5) (0,3,4) {43,37,29,55,9,52,46} +[#...#] (2,4) (0,1,2,3) (1,3,4) (0,4) {16,9,21,9,37} +[#.###.] (0,5) (0,3,4,5) (0,2) (0,1,2,3,4) (1,2) {65,34,53,36,36,27} +[.#..#.] (1,3,5) (1,2,3,4) (0,2,3,4,5) (0,1,3,4) (0,1,3) (3,4,5) (0,1,2,5) {45,50,21,45,32,15} +[..###] (2,3,4) (1,2,4) (0,3,4) (3,4) (0,1,3) {12,25,17,19,22} +[.###..##] (0,2,5,6) (1,4,5,6) (1,2,3,5,6) (0,4,5,6,7) (1,3,4,6) (1,3,7) (0,4,7) {38,34,22,21,42,37,45,29} +[####] (1,3) (0,1,2,3) {187,203,187,203} +[..#..##.] (0,1,2,4,5,6,7) (0,1,2,3,4,5) (4,6) (0,1,6,7) (1,3,5,7) (0,2,3,4,5,7) {37,38,30,38,42,48,29,52} +[..##] (0,3) (0,2) (1,3) {9,180,8,181} +[#.###.] (1,4,5) (2,3,4,5) (0,1,2,4) (0,1,2,5) (3,5) (1,3,4) (0,1,3) {46,59,45,48,40,44} +[#.#...] (0,1,3,4) (0,2) (0,2,3,4) (3,4,5) (1,2,4,5) (1,2,3) (2) {34,28,48,235,217,190} +[#...###.#] (1,2,4,5,6) (1,2,3,4,5,7,8) (2,3) (0,2,4,6) (0,5,7,8) (0,2,3,6,8) (1,2,4,5) {39,43,81,54,43,62,39,35,55} +[.###.#.##] (0,1,4,6,7,8) (0,4,6,7,8) (0,1,6,7) (0,3,4,5,8) (1,2,4,6,7,8) (0,1,3,4,5,6,7,8) (0,3,4,5) (1,2,3,5,7,8) (1,3,4,7) (4,7) (1,3,7,8) {40,34,17,42,57,32,27,51,54} +[#.#...##] (2,3,4,6) (1,2,4,5,6,7) (3,5,7) (0,6) (0,1,2,4,6) (1,3,4,6) (4,5,7) (1,4,5,6) (0,1,4,5,6,7) (0,1,2,3,6,7) {62,70,56,37,84,48,103,48} +[##..] (0,3) (1,2,3) (1,2) (0,2,3) (2) {20,12,48,32} +[.#.###] (1,2,4,5) (0,1,3) (0,2,3,4,5) (0,5) (0,3) (1,2,5) (0,1,5) (2,4) {50,45,29,27,18,48} +[.####] (1,3,4) (0,1,2,4) (0,2,3,4) (2,4) (0,1,2) {49,48,53,35,57} +[####..###] (0,1,3,4,7,8) (0,4,6,8) (1,7,8) (0,2,3,6) (0,1,3,4,8) (4,5) (2,7) (1,3,4,7,8) (1,5,6,8) (1,2) {39,76,24,56,72,25,13,51,66} +[##.#.#..] (2,3) (2,3,4) (0,3,5) (0,1,2,5) (0,4,6) (1,2,5,7) {55,30,39,25,20,46,20,11} +[#..#.#.#.] (0,3,5,6) (1,3,4,6,7,8) (1,2,6,8) (4,5) (0,1,3,4,8) (2,3,5,6,7,8) (0,2,5,6) (0,2,3,4,5,6,7) (0,3,4,5,7) (0,1,2,3,5,7,8) {258,55,58,283,84,265,273,70,68} +[#....##] (0,4) (0,1,3,5,6) (1,2,3) (0,1,2,3,6) (4,5,6) (0,1,3,4,5) (0,2,3,6) {43,37,21,45,47,42,32} +[..#...] (1,3,4,5) (0,1,2,3,5) (1,2,3,4) (0,4) {36,29,25,29,29,22} +[...##..] (0,1,4,5,6) (0,1,3,4,5,6) (0,1,2,3,5) (0,3,4,5) (3,5) (0,1,2,3) (1,3,4,6) {160,58,21,183,155,163,37} +[##..##..] (2,3,6) (0,1,4,7) (2,4,6,7) (2,4,6) (0,3,6) (1,4,6,7) (0,1,3,4,6,7) (3,4,5,6) (0,3,4,6) {21,24,33,36,48,5,62,38} +[#.....##] (1,2) (1,4,7) (2,3,4) (0,2,4,5) (1,3) (0,6,7) {7,27,35,19,28,5,2,10} +[##.....#.] (0,2,3,6,8) (1,3,4,5,7) (0,4,5,6) (1,2,3,4,6,7,8) (0,1,4,5,6,7,8) (1,2,5,8) (0,2,3,4,7) {33,65,38,41,62,57,41,56,50} +[#...###..] (2,3,4,5,7) (0,1,2,4,7,8) (0,1,2,3,5,6,7) (6,7,8) (4,5,8) (1,3,4,8) (5,8) (0,2) (0,2,3,5,6,7,8) {37,36,48,59,44,79,50,63,80} +[.##..] (1,3) (3) (0,1,2) (0,4) (0,1,3,4) (1,2) {9,28,12,22,5} +[###..#.#.#] (1,2,4,6,7,8) (4,6) (0,2,5,6,7,9) (0,1,2,3,5,6,8,9) (0,1,6,8) (0,2) (1,2,6,7) (0,3,5) (1,2,6,7,9) (3,7,9) (0,1,6,7,8) (1,2,3,4,7,8,9) (0,2,3,4,5,7,9) {182,75,172,36,36,140,203,188,59,167} +[....#..] (0,1,3) (0,4,6) (1,2) (0,2,4) (3,5,6) (1,4,5,6) (0,3) (0,1,3,4) {73,25,18,47,42,12,29} +[....#....#] (0,1,2,5,6,7,8) (0,1,2,3,4,6,7,8,9) (0,2) (0,1,4,5,6,8,9) (2,3,8,9) (4,9) (1,2,3,5,7,8,9) (2,6,7,8) (5,7,8) (0,1,2,3,4,6,7,9) (1,3,5,7,8,9) {37,49,63,30,20,49,52,67,75,41} +[..#.##..] (0,2,5,6) (0,4,7) (0,1,2,3,5,7) (6,7) (1,2,4,5) (0,1,2,4,5,7) (0,1,2,4,7) {197,178,198,155,23,185,40,197} +[###.#] (3,4) (0,2,3,4) (0,2,3) (1,3,4) (1,2,3) (0,1,2) {39,44,54,47,17} +[....#.#.] (3,6) (1,2,3,4) (2,3,6,7) (2,5,6,7) (0,1,2,3,5,7) (2,3,4) (2,3,5) (0,3,4,5,6,7) (3,4) (1,2,3,6) {17,13,48,86,56,34,44,26} +[..#.] (0,3) (1,2) (2,3) (1,2,3) {13,17,20,32} +[..#..] (0,1,2,4) (0,2,3) (2) {4,0,16,4,0} +[...##.] (3,4) (0,2,5) (1,3) (0,1,4) (0,3,5) (1,4) (1,2) {26,47,16,31,29,17} +[#.#.#..##] (2,3) (0,2,5,7,8) (0,6) (2,3,4,5,6,8) (1,3,4,5,6,8) (2,4,6,7) (1,8) (0,2) {42,22,58,39,39,43,54,28,45} +[##.#] (0,1,3) (0,2,3) {10,9,1,10} +[##....] (2,3) (2,3,4,5) (0,5) (1,2,3) (2,3,4) (0,2,3,5) {22,16,56,56,12,33} +[.#...#..] (0,2,3,6,7) (0,1,2,3,5,7) (6,7) (0,1,2,3,6,7) (0,1,2,3,5,6) (0,3,4,7) (4,5) (1,4,5,7) (0,1,2,3,5,6,7) {50,36,49,50,14,35,49,57} +[#.#..#] (2,4) (0,2,5) (2,3,4,5) (1,2,4) (0,2,3,4,5) (1,3,4,5) (2,3) {18,26,65,61,72,56} +[..##] (1,2) (0,2) (0,3) {22,1,11,12} +[.###.###..] (0,1,2,3,6,8,9) (0,5,9) (1,2,3,4,5,6,8,9) (0,1,2,4,5,7,8,9) (0,1,2,3,7,8,9) (2,4,7) (1,2,5,6,8) (3,4,5,8,9) (4,7,8,9) {218,225,238,230,43,42,202,36,239,243} +[.#...#.#.] (4,8) (0,2,3,7,8) (0,1,2,8) (0,2,3,4,5,6,8) (1,2,6) (2,6,7,8) (3,6,8) (0,2,3,4,5,7,8) {25,23,51,35,26,9,47,27,75} +[..#...###.] (0,1,4,5,6,9) (3,4,6,9) (1,2,3,6,8) (0,2,3,4,5,7,8,9) (1,3,8) (0,2,5,7,8,9) (1,2,3,5) (0,3,4,6,8) (3,5) (3,5,6) (2,7) (9) {37,30,35,65,44,39,60,26,38,40} +[..##...##.] (0,1,4,8,9) (2,3,7) (2,3,4,5,7) (4,6,7,8) (5,6) (1,5,9) (0,2,3,4,5,6,8,9) (2,5,6,9) (0,6) (1,8) (1,5,8,9) (2,9) (1,3,4,7) {17,38,39,24,32,49,18,24,35,55} +[###.#] (0,2) (4) (0,2,3) (3,4) (0,1,2,4) (0,1,2) {45,28,45,18,38} +[.###] (0,2) (1,2,3) {19,195,214,195} +[##.#] (3) (1,2) (2) (0,2,3) (0) {114,14,120,114} +[.##...] (1,2,5) (1,3,4) (0,2,4,5) (2) (0,3,5) {11,31,39,21,20,27} +[.##......] (0,2,4,5,6) (2,3,4,6,8) (0,1,2,3,5,6,7) (0,5,6,7,8) (2,3,4,5,8) (1,4,7) (8) (0,1,3,4,6,7,8) (3) (0,1,2,7) {46,32,56,51,44,47,34,43,52} +[.###] (0,2) (0,3) (1) (2,3) {12,3,15,15} +[#.#..##..#] (1,5,7) (0,1,2,3,4,6,7,8,9) (2,9) (0,5,6) (1,4,9) (1,2,5,7,9) (0,2,8,9) (4,9) {23,28,40,3,28,29,18,17,8,65} +[#..#.###.] (1,2,3) (0,2,3,4,7) (1,3,4,5,6,7,8) (0,2,4,5,6,8) (1,2,3,5,8) (0,2,4,5,6,7,8) (0,2,5,8) (0,1,2,3,4,5,7) (2,3,8) (1,3,6,7) {196,226,235,250,204,219,51,222,70} +[...#.] (2,3) (0,2,4) (0,2,3) (1,4) (1,2,4) {37,26,61,26,43} +[..#.#.##.#] (0,3,4,5,6,7,8,9) (0,1,2,5,6,7,8) (0,2,3,4,5,6,7,8,9) (1,2,4,7) (0,8) (5,6) (0,1,2,3,5,6,7,8) (0,1,2,3,4,5,6,7) (0,2,3,4,5,6,8,9) (1,3,6,8) (0,2,3,6,7,9) (1,2) (0,4,5,7,9) {91,200,210,76,78,74,83,76,72,48} +[..#.] (0) (0,2) (1,2,3) (2) (1) (2,3) {32,11,50,15} +[#.##.###..] (0,4,5,6,7,8,9) (2,3,4,5,6,7,9) (4,6,8) (0,1,3,4,6,7,8,9) (0,1,2,3,4,7) (1,2,4,8) (1,4) (0,1,2,3,4,5,6,8,9) (1,2,4,7,8) (0,2,3,5,8) (1,4,5,6,7) (1,4,9) {73,109,75,65,139,66,78,83,82,68} +[.####.#...] (0,3,4,6,7,8) (2,9) (0,1,2,3,4,5,6,8) (1,2,3,4,5,6,8,9) (0,1,2,3,7) (0,2,3,5,8) (0,1,2,3,4,5,6,7,9) (0,1,3,4,6) (0,1,4,6,9) (0,3,4,5,6,7,8,9) {60,44,35,48,45,24,45,33,27,29} +[.###..#] (0,1,2,3,6) (1,4) (3,6) (0,1,4,5) (1,2,4,5,6) (0,1,6) (1,2,5) (0,1,3,5) {47,80,22,28,41,41,43} +[.##..] (2,3) (0,1,2,3) (0,3,4) (0,1,2) (2,3,4) (3,4) (4) {50,37,65,71,59} +[.#..###.] (1,3,4) (0,1,4,5,6) (4,5) (0,1,7) (6) (1,2,3,4) (2,3,5,6) (0,3,4,5,6) {31,28,158,177,46,184,174,10} +[#..#.#....] (0,3,4) (1,4,5,6,7,8) (1,3,4,5,7,8) (0,5,7,8) (0,1,2,3,5,8,9) (0,3,4,5,6,7,8) (0,2,4,8,9) (0,6) (2,3,5,6,7,8,9) (0,2,3,4,5,7,9) (1,2,4,5,6,7,8,9) {84,45,59,70,73,75,52,57,78,59} +[#.#..] (1,3,4) (2,4) (0,2) (0,1,4) (2,3) (1,3) (0,4) {17,29,14,28,25} +[#.#.#.##] (1,4,7) (0,2,5,6) (4,7) (2,3,4,6,7) (1,3,5,6) (0,2,4,6,7) {19,200,38,24,237,17,43,237} +[..##.##...] (0,1,3,5,6,7,8,9) (0,2,4,5,6,8) (1,3,6,9) (0,1,2,3,4,5,7,8,9) (3,4,5) (2,3,4,5,9) (1,2,4,5,8) (0,2,3,7,9) (1,2,6,7,8,9) (1,2,5,9) (1,3) (1,7) {56,86,93,96,79,106,45,49,60,87} +[.#.###] (0,5) (0,4,5) (2,3,4,5) (0,1) (0,2) {247,198,18,4,22,39} +[##.#.] (0,2,3,4) (0,2) (0,1,2,3) (0,1,4) {53,29,33,14,25} +[#####] (1,3,4) (0,2,3,4) (0,2) {36,15,36,31,31} +[..###] (0,2,4) (1,2,4) (0,3) {13,5,9,9,9} +[.#..] (0,2) (1,2,3) (0,3) (1,2) (0,1,3) {29,14,18,21} diff --git a/src/exercises/day_10.ts b/src/exercises/day_10.ts index 6d62bda..416f2a5 100644 --- a/src/exercises/day_10.ts +++ b/src/exercises/day_10.ts @@ -13,94 +13,52 @@ interface MachineManual { } export default async function Factory() { + console.log("== Factory =="); + const manual_list = await read_machine_manuals( + "src/exercises/assets/day_10_input.txt", + ); + const min_presses = count_min_button_presses(manual_list); + console.log( + ">> Min button presses to start: ", + min_presses, + ); } export function count_min_button_presses(manuals: MachineManual[]): number { let total_sum = 0; - manuals.forEach((manual, i) => { + manuals.forEach((manual, m_i) => { + console.log(`== Manual ${m_i} out of ${manuals.length}`); const wiring_list = manual.button_wirings; let min_presses = Infinity; - wiring_list.forEach((wiring, wiring_i) => { - let pairing_indicator = manual.indicators.map((_) => Indicator.OFF); - // Apply the current wiring - pairing_indicator = apply_wiring_to_indicators( - wiring, - pairing_indicator, + for (let size = 1; size < wiring_list.length; size++) { + const button_combinations = make_all_combinations_of_size( + wiring_list, + size, ); - - if (pairing_indicator.join("") === manual.indicators.join("")) { - min_presses = 1; - return; - } - - for ( - let inner_i = wiring_i + 1; - inner_i < wiring_list.length; - inner_i++ - ) { - pairing_indicator = manual.indicators.map((_) => Indicator.OFF); - // Apply the current wiring - pairing_indicator = apply_wiring_to_indicators( - wiring, - pairing_indicator, - ); - // Apply the next wiring - pairing_indicator = apply_wiring_to_indicators( - wiring_list[inner_i], - pairing_indicator, - ); - - if (pairing_indicator.join("") === manual.indicators.join("")) { - min_presses = 2; - break; - } - } - }); - - // If - not a simple press/pairing found - // then - check all combinations - // - // For size, starts at 1 - // for index spacing? - // OR binary - if (min_presses === Infinity) { - let cumulative_presses = 0; - // DOES NOT MAKE ALL COMBINATIONS, only secuentials - wiring_list.forEach((wiring, wiring_i) => { - let cumulative_indicator = manual.indicators.map((_) => Indicator.OFF); - - // Apply the current wiring - cumulative_indicator = apply_wiring_to_indicators( - wiring, - cumulative_indicator, - ); - cumulative_presses += 1; - - for ( - let inner_i = wiring_i + 1; - inner_i < wiring_list.length; - inner_i++ - ) { - cumulative_presses += 1; - // Apply the next wiring - cumulative_indicator = apply_wiring_to_indicators( - wiring_list[inner_i], - cumulative_indicator, + button_combinations.forEach((combination) => { + // Apply combination + let pairing_indicator = manual.indicators.map((_) => Indicator.OFF); + combination.forEach((b) => { + pairing_indicator = apply_wiring_to_indicators( + b, + pairing_indicator, ); - if (cumulative_indicator.join("") === manual.indicators.join("")) { - break; - } - } + }); - if (cumulative_presses < min_presses) { - min_presses = cumulative_presses; + // Check if valid + if (pairing_indicator.join("") === manual.indicators.join("")) { + min_presses = combination.length; + return; } }); + + if (min_presses < Infinity) { + break; + } } - console.log(">> Total and min", { total_sum, min_presses }); total_sum += min_presses; }); @@ -116,6 +74,32 @@ function apply_wiring_to_indicators( ); } +function make_all_combinations_of_size( + list: T, + size: number, +): T[] { + const binary_cap = Math.pow(2, list.length); + + const result_list: T[] = []; + + for (let i = 0; i < binary_cap; i++) { + const combination = i.toString(2).padStart(list.length, "0").split(""); + + if ( + combination.reduce((sum, n) => sum + (n === "1" ? 1 : 0), 0) !== size + ) { + continue; + } + + const next_l = list.map((l, i) => combination[i] === "1" ? l : null).filter( + (l) => l !== null, + ); + result_list.push(next_l as T); + } + + return result_list; +} + export async function read_machine_manuals( path: string, ): Promise { @@ -123,7 +107,8 @@ export async function read_machine_manuals( const input_txt = await Deno.readTextFile(path); const lines = input_txt.split("\n"); - const manual_list: MachineManual[] = lines.map((line) => { + const manual_list: MachineManual[] = lines.map((line, line_i) => { + console.log(`== Reading file ${line_i} out of ${lines.length}`); const matched_line = line.matchAll(line_regex)?.toArray()?.[0]; if (matched_line && matched_line.length > 3) { const indicators = matched_line[1].toString().split("").map((ch) =>