From b1c43e46fc840aea17592ad0771fdebfa17e8ba6 Mon Sep 17 00:00:00 2001 From: Timo Schneider Date: Wed, 10 Dec 2025 23:51:01 +0100 Subject: [PATCH] day10a --- README.md | 30 ++++---- puzzles/input10.txt | 172 +++++++++++++++++++++++++++++++++++++++++++ src/day10/mod.rs | 22 ++++++ src/day10/part10a.rs | 72 ++++++++++++++++++ src/day10/part10b.rs | 4 + src/main.rs | 3 + 6 files changed, 289 insertions(+), 14 deletions(-) create mode 100644 puzzles/input10.txt create mode 100644 src/day10/mod.rs create mode 100644 src/day10/part10a.rs create mode 100644 src/day10/part10b.rs diff --git a/README.md b/README.md index 3931188..5d61538 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,25 @@ # Advent of Code 2025 ```bash -day01:A => 1150 ( 49us) -day01:B => 1150 ( 47us) -day02:A => 31839939622 ( 7731us) -day02:B => 41662374059 ( 64732us) -day03:A => 16812 ( 84us) -day03:B => 166345822896410 ( 286us) -day04:A => 1518 ( 202us) -day04:B => 8665 ( 3737us) +day01:A => 1150 ( 51us) +day01:B => 1150 ( 49us) +day02:A => 31839939622 ( 7737us) +day02:B => 41662374059 ( 64501us) +day03:A => 16812 ( 106us) +day03:B => 166345822896410 ( 282us) +day04:A => 1518 ( 193us) +day04:B => 8665 ( 3713us) day05:A => 701 ( 140us) day05:B => 352340558684863 ( 19us) -day06:A => 6503327062445 ( 207us) -day06:B => 9640641878593 ( 133us) -day07:A => 1678 ( 49us) -day07:B => 357525737893560 ( 55us) +day06:A => 6503327062445 ( 188us) +day06:B => 9640641878593 ( 137us) +day07:A => 1678 ( 43us) +day07:B => 357525737893560 ( 50us) day08:A => 0 ( 0us) day08:B => 0 ( 0us) -day09:A => 4725826296 ( 164us) +day09:A => 4725826296 ( 159us) day09:B => 0 ( 0us) +day10:A => 452 ( 395us) +day10:B => 0 ( 0us) ---------- - 81857us + 78306us ``` \ No newline at end of file diff --git a/puzzles/input10.txt b/puzzles/input10.txt new file mode 100644 index 0000000..2e295ac --- /dev/null +++ b/puzzles/input10.txt @@ -0,0 +1,172 @@ +[.###.#..] (0,2,3,4,6,7) (1,2,4,5,6) (1,3,4,5,7) (0,2,4) (4,7) (0,1,4,6) (1,2,3,4,5,7) (2,4,7) {29,44,42,26,66,27,30,36} +[###.#...] (3,4,6) (1,2,3,4,5,7) (0,1,2,4) (0,1,3,5,7) (0,1,4,5,6,7) (0,2,7) (4,6) (7) (0,6) (1,4,5,6,7) {214,221,33,36,226,204,203,217} +[##.#.###] (0,1,7) (2,3,4,5,6,7) (0,3,4,5,6,7) (0,1,3,5,6,7) (2,7) (0,1,2,3,4,6,7) (0,1,3,4,6,7) {68,52,32,65,52,36,65,88} +[.#.#...#..] (0,1,4,5,9) (0,2,6,7,8,9) (0,5,6,9) (2,5,6) (1,5,9) (0,1,3,4,6,7,8,9) (2) (0,1,2,3,4,6,8) (0,7,8,9) (0,1,3,5,6,7,9) (3,5,9) {68,64,220,49,46,43,59,35,36,57} +[##.#..#] (0,2,3,4) (2,3,5) (0,1,3,6) (0,1,3,4,5) (0,1,5,6) (5) {26,16,194,197,13,205,13} +[.##.....##] (0,1,4,7,8,9) (1,3,4,5,6,9) (2,4,9) (3,6,8) (0,2,3,4,6,7,8) (0,1,2,3,4,5,6,8) (1,2,3,4,6,7,8,9) (2,4,6,9) (0,1,5,8,9) (2,7) (4,6,8,9) (1,3,4,5,7,8,9) (1,3,4,6,7,8,9) {12,56,55,72,88,16,88,57,85,79} +[#...#] (0,2,3,4) (2,3) (0,1,2,3) (0,1,2) {27,21,43,41,6} +[#.###] (0,1,3) (1,2,3,4) (1,2,4) {4,29,25,14,25} +[#....##.#.] (5,6,8) (0,2,5,6,7,9) (1,3,5,6,7,9) (1,2,7,9) (1,2,4,5,6,7,8,9) (2,8) (0,2,3,5,6,7,8,9) (0,4,5,9) (4,5,8) (4,5) (0,2,3,4,5,7,8,9) (0) (1,2,3,4,5,6,7,8) {49,233,86,233,57,297,253,271,72,271} +[.#.##.] (0,2,4) (1) (3,4) (0,1,3,4,5) (0,1,2,5) (1,2) {42,46,35,25,35,32} +[..#.#] (0,3) (1,2,4) (1,2) (1,2,3,4) (0,2) (1,4) (2,3,4) {15,32,19,17,21} +[..##...] (0,1,2,5,6) (1,2,4,6) (0,1,3,5,6) (0,5) (1,3,5,6) (0,1,2,3,4,6) (5,6) (4,5) {34,37,14,35,29,64,55} +[##..#] (0,1,2,4) (1,2,3,4) (0,2,3) {141,151,155,18,151} +[#.#.##] (0,3) (5) (0,1,3) (0,1,2,5) (0,1,2,4,5) (1,3,5) (0,1,2,4) (1,3,4,5) {53,66,23,56,32,52} +[###.] (0,2) (0,2,3) (2,3) (0,1) (3) {40,15,38,38} +[.#..#] (0,2,3,4) (0,1,3) (1,4) {30,21,12,30,15} +[####.] (0,1,4) (1,2,3) (2,3,4) (1,3) (0,3) {24,12,4,30,9} +[..#.#.#] (4,6) (2,5) (0,2) (0,1,2,3,6) (1,2,4,5,6) (0,2,3,4,6) (0,4) {45,16,57,23,49,23,43} +[...###] (1,2) (4,5) (0,3,4) (0,2,3,5) (0,1,2,5) {36,11,27,29,27,37} +[##.##..###] (3,5,6,7,8,9) (0,1,2,3,5,7,9) (0,5,8) (2,4,5,8) (2,3,6,7) (0,1,2,3,6,7,8) (0,1,2,4,5,6,8) (5,6,7) {55,54,73,53,39,97,75,73,75,37} +[..##.#] (0,1,3,5) (0) (1,2,5) (3,4) (0,1,3,4) (1,2,3,5) (3,5) (0,1,5) {67,69,19,60,37,51} +[.#...##.##] (0,1,2,5,7,8) (1,5,6,8,9) (0,1,2,6,8) (0,8,9) (0,7) (1,9) (1,3,8) (1,5,7) (0,1,2,3,4,7,8) {39,69,24,40,20,11,6,28,62,36} +[...###.#] (0,2,3,6) (0,1,3,4,5,6,7) (0,2,4,6) (0,1,2,3,6) (3,4,5,7) (1,3,4,6,7) {56,33,48,55,29,11,63,18} +[.#..#] (1,2,4) (2,3) (0) (1,4) (3) (3,4) (0,1,2) {23,28,26,33,26} +[###.#.#] (0,2,3,4,6) (0,4,5,6) (3,4,5,6) (0,2) (1,4,5,6) {39,14,23,178,208,197,208} +[#.###.#] (1,2,4,5) (0,2,3,4) (1,2,3,5,6) (0,2) (0,1,3,6) (0,1,2,6) {151,134,151,33,11,11,134} +[......##] (0,1,2,4,6,7) (0,1,2,4,5) (0,2,3,4,5,7) (0,1,4,5,7) (0,1,2,3,6,7) (0,1,2) (6,7) (0,1,3,6) {91,80,63,32,60,42,50,65} +[..##.#.##] (0,2,5,7) (1,2,3,6,8) (0,1,4,6,7) (5,7,8) (0,1,3,4,6,7,8) (0,5) (3,5,7) (1,3,4,5,6) (2,3,4,8) (0,1,4,5,7) (0,1,3,5,6,8) {67,79,51,89,68,93,75,87,72} +[##..] (2) (0,3) (0,1,3) (0,1) {19,7,12,12} +[.#.#.] (0,1,4) (1,3) (0,2,3) (2,3,4) {29,25,205,214,208} +[###.#.##.] (0,1,2,5,6,7,8) (2,4,5,6) (1,3,4,5,6) (1,4,5,7,8) (0,2,3,5,6,7,8) (0,2,3,4,6) (0,3,4,8) (7) (0,2,5) {71,35,55,65,65,78,52,52,57} +[.....##...] (0,1,2,3,4,5,6,7) (9) (1,4,5,6,7,8,9) (0,1,3,4,8,9) (0,2,3,6,8) (0,2) (5,6,9) (1,3,4,6,8,9) (1,3,4,5,6,8,9) (0,1,2,3,5,6,8,9) (1,2,4,5,6,7,8,9) (0,5,8) (3,5,6,8) {48,77,30,85,62,82,99,11,99,107} +[.###..##.#] (1,2,3,4,5,6,8,9) (8,9) (0,1,2,3,5,8,9) (1,2,3,4,9) (0,1,3,4,5,7,8,9) (3,5,6,9) (1,2,3,5,6,7,9) (0,2,3,4,6,7,8,9) (0,2,3,6) (0,1,2,5,6) (1,3,4,5,7,8) (0,1,3,6,8,9) {46,82,72,101,68,70,60,45,62,95} +[##.#...] (3,4,5) (0,3,4,5) (0,1,2,5,6) (0,2) (2,3,4,6) (0,1,4,5) (1,2,5,6) (0,1,3) (0,3,4,5,6) {74,33,19,53,45,43,16} +[.....##.##] (7,9) (0,2,3,4,5,6,7,8) (1,3,4,5,6,7,8,9) (0,1,4,8) (2,6) (0,3,4,5,8) (3,4,5,7,8) (1,2,3,5,6,7,8) (0,3,4,6,7,8) (0,8) (1,2,3,4,6) {31,52,39,48,64,34,53,33,55,15} +[.##..####.] (0,3,4,6,9) (0,1,2,3,5,6,7,8,9) (3,4) (0,3,7,8,9) (0,1,2,5,6,7,9) (1,3,4,5,6,8,9) (4,7) (1,3,6,8,9) (0,1,2,3,4,5,8) (6,7) {61,32,27,62,56,32,35,41,36,52} +[#.........] (1,3,4,7) (1,4,5,7,8) (0,1,2,3,5,7,9) (4,5) (2,3,9) (0,1,2,3,6,7,8,9) (3,6,9) (0,1,4,6,7,8) (0,4,9) (1,2,3,6) (5,7,8,9) (6) {36,70,32,60,49,33,64,58,35,45} +[#..##.] (0,1,4) (1,2,4) (0,1,2,3) (1,5) {13,42,20,0,33,9} +[###...] (0,1,2) (1,2,4,5) (2,3,5) (1,3,5) (1) (1,2,3) {199,238,232,27,12,38} +[.#..#...#.] (1,8,9) (2,3) (1,2,4,6,7) (0,1,2,3,4,7,8) (1,2,3,5,6,7,8,9) (1,2,7) (1,2,7,9) (2,3,4,5,7,8,9) (1,3,5,6,7,9) (0,2,3,5,7,8,9) (0,2,3,4,6,8) {24,64,85,71,35,52,39,83,58,76} +[..#..#....] (5,7) (1,3,4,5,6,8) (0,2,3,4,5,6,7,9) (0,3,8) (1,2,3,4,6,8) (1,6,9) (1,2,3,4,7,8,9) (4,7) {18,42,20,51,52,30,24,53,50,29} +[#.####] (1,2) (0,1,4) (3,5) (1,4,5) {14,38,19,16,19,21} +[..#..#.#.#] (4,6) (1,2,3,5,6,8,9) (0) (0,1,3,4,5,6,8,9) (0,1,3,4,6,7,8) (0,1,5,7,8) (0,1,4,5,8) (3,4,7,8) (1,9) (0,1,2,3,5,8,9) (5,6,9) (4,6,8,9) (0,4,6,7) {48,63,17,57,51,161,167,30,61,173} +[.#..] (0,1) (0,2) (0,1,2) (1,3) {134,125,19,10} +[#..#...##] (0,1,2,4,5,6,7) (3,4,5,6,8) (0,3,4,5,6) (0,1,2,3,4,5,6,8) (1,4,5,8) (1,2,6,8) (2,8) (0,4,7,8) (0,2,5,6,7) (0,1,3,4,7) {239,250,225,234,253,237,241,31,232} +[..###] (1,2,3,4) (0,1,2) (0,4) (0,1,4) (2,3,4) {35,21,29,19,44} +[#####] (1,2) (0,1,3,4) (0,3,4) (2) (0,1,4) (3,4) {29,27,12,34,41} +[#.#.##.] (1,3,5,6) (0,2,3) (3,4,6) (0,2,4,5,6) (0,4) (2) (0,1,4,5,6) (2,3,4,5) (1,2,4,5,6) {43,21,73,41,62,61,42} +[##.###.] (0,1,2,5,6) (0,1,3,4,5) (0,1,3,4,6) (0,1,3,4,5,6) (0,2,3,4,5) (2,3,4) (3,4,5) (0,1,2) {187,167,59,174,174,180,143} +[..###] (0,2,3) (0,1,2,3,4) (1,2,3) (1,2) {178,17,195,184,0} +[#.#.####] (0,1,3,4,5) (1,2,4,5,6,7) (7) (0,2,4,5,6,7) (0,2,3,5,6,7) (2,4,5,6,7) (2,3) (1,2,3,5,6,7) {38,33,50,47,31,59,45,52} +[..#..#..#] (6,8) (1,2,5,6) (0,1,2,3,8) (2,4) (0,1,2,3,5,7,8) (0,2,3,6,7) (1,2,3,4,5,6,8) (0,1,2,3,4,5,6) (0,2,4) (0,1,2,4,6,7,8) (2,7) {67,69,126,63,55,49,64,35,34} +[.####.] (2,4,5) (1,2,3,4) (3) (0,2,3,5) (0,2,5) (0,3) (1,5) (0,3,4,5) {36,33,32,53,30,52} +[.#...##..] (1,2,3,4,7,8) (5,7) (0,1,3,4,8) (0,1,4) (1,2,3,5,6,8) (0,3,4,6,7,8) (0,2,4,5,7,8) (1,3,4,5,6,7,8) {47,39,35,53,61,58,43,67,70} +[##.#..#...] (0,1,2,4,9) (0,1,4,5,7) (0,1,2,4,5,6,7,8) (1,4,5,6,7,8,9) (0,1,3,6,8) (0,5,7) (2,5,9) (6,9) (0,3,4,6,8,9) (3,5,6,8,9) (2,3,9) {79,68,128,135,61,61,67,48,54,165} +[#...] (0,2) (1,3) (0,1) (1,2,3) (1) {17,26,20,18} +[.#.####.] (2,6) (0,2,5,6,7) (0,2,3,4,7) (1,3,6) (2,3,4,5) (1,2,3,4,5,7) (3,4,5,6,7) {21,32,60,55,38,55,63,48} +[#..###..#] (2,3,5,6) (0,3,6,7) (0,1,4) (0,3,4,5,6) (0,2,4,5,6,7,8) (0,1,4,6,7,8) (2,3,6,7) {58,32,44,52,42,29,80,60,28} +[..#.##..##] (0,4) (1,2,3,4,5,8,9) (0,9) (0,5,7) (1,5,7,8) (0,2,4,5,6,8,9) (5,6,8) (0,3,7) (1,2,6) (0,1,4,6,7,8,9) {45,24,17,12,35,31,38,31,46,36} +[#..#.#.] (2,4,6) (0,1,3,4) (1,3,5) (0,1,2,4,6) (0,3,4,5) (0,1,3,5,6) (0,1,3,6) (0,2,4) (2,3,4,6) {51,44,43,50,44,33,49} +[#..#] (1) (1,2,3) (1,3) (3) (2) (0,3) {16,13,7,48} +[##..#..] (0,4) (0,3,5,6) (1,2,5,6) (0,2,3,4,5,6) (0,3,4) {33,12,16,26,31,18,18} +[##..#.##] (1,4) (0,1,2,3,4,5) (1,6) (0,2,6) (0,6) (0,2,3,4,5,7) (0,2,4,6,7) (1,2,3,4,6,7) (3,4) {64,26,55,37,65,25,46,38} +[#..#.] (0,1,4) (0,2,3) (2) {16,7,16,9,7} +[..##.#] (1,3,4) (1) (0,5) (2,3,4,5) (2,3,5) {18,30,11,29,25,29} +[#....#] (1,3,4,5) (0,3) (3) (1,3,4) (0,1,2,4) (2,5) (1,2,3,4,5) {17,49,36,54,49,34} +[#....#.] (4,5) (1,3,4,5,6) (0,1,2,4,5,6) (3) (0,1,2,3,5) (1,4) (3,5) (0,1,3,6) {20,43,7,48,37,30,34} +[...##] (0,1,2) (0,1,4) (0,1,2,4) (0,1,2,3) {159,159,147,130,18} +[..##] (0,1,2) (0,2,3) (2,3) {19,12,20,8} +[..#.#] (0,1,2,3,4) (1,2,3) (0,2,3) (1,2) {25,33,49,41,9} +[.##.] (1,2,3) (0,1,3) (0,2,3) {14,7,19,20} +[#..#] (1,2,3) (2) (0) (0,1,2) {30,21,154,4} +[#.##.] (1,2,3) (0,2,3) (2) (2,4) (1,3,4) (0,1) (1,3) {20,44,45,64,18} +[#.#.#.] (0,5) (0,2,4) (1) (3,5) (0,1,2,3,5) {38,36,29,21,10,30} +[#..#.....] (0,3) (0,1,2,4) (3,4,5,6) (0,1,3,5,7,8) (1,4,7,8) (0,1,2,4,5,6) (2,4,6) (1,2,3,4,5,6) {34,55,52,36,75,39,47,17,17} +[.#.#] (1,3) (0,2) {4,1,4,1} +[#.#.#####] (0,1,2,3) (2,4,8) (2,6,7,8) (1,4,5,7) (5,8) (4,5,6,7,8) (8) (3,8) (2,4,6,7) (1,4,5) {20,27,40,20,25,38,27,32,64} +[###.##.#] (0,1,3,4,6) (0,5,6) (1,2,3,5,6,7) (3,4,5,7) (1,2,3,4,5,6,7) (1,2,3,4,6) (1,2,3,4,6,7) (0,1,3,5,6) (0,3,4,5,7) (3,4,7) {24,234,225,267,251,51,239,64} +[....###] (2,3,4,6) (1,2,3,4,5) (1,3,4,5) (0,1,4,6) (1,2,4,6) (0,1,2,4) (0,1,2,5,6) {25,48,46,31,43,36,39} +[##..##...] (0,2,3,4,5,6,7,8) (1,4) (0,2,7) (3,5,6) (0,1,3,5,6,7,8) (2,5,7) (1,8) (1,2,5,6,7,8) (1,2,3,4,5,6,7) (3) (7) {16,55,47,46,28,61,42,72,33} +[#..##.] (1,2,3,4,5) (0,1,2,5) (1,2,4,5) (2,3,4) (1) {9,50,42,14,33,33} +[..#.#.##..] (1,3,5,9) (6,7,8) (0,1,2,3,4,5,6) (3,7,8,9) (6,7) (3,4,6,7,9) (1,2,3,4,5) (3) (4,5,7,9) (1,3,8) (0,2,3,6,8,9) (1,2,5,7) {4,30,18,62,32,42,40,78,40,57} +[.##.###] (0,1,2,4,5,6) (3,4,5) (0,3,6) (2,3,4,5,6) (0,3,5,6) (1,4,5) {26,18,21,51,49,62,41} +[.#.#] (1,3) (0,1,3) (1,2) {9,22,6,16} +[......#] (0,2,4,5,6) (1,2,4,5,6) (2,3,4,5,6) (3,4) (0,2,3,4) (0,2,3,5) (1,3,4,6) {33,21,51,57,63,37,41} +[###.] (0,1,2) (1,3) {19,36,19,17} +[...##] (3,4) (1) (0,2,3,4) (1,2) {0,10,7,15,15} +[##...####] (0,1,3,4,5,7) (0,2,4,8) (6,7) (0,3,4,5,6,7,8) (0,2,3,4,6,7) (1,2,3,4,5,8) (0,1,2,3,6,7,8) {152,133,154,157,38,16,166,167,142} +[####] (0,1,2,3) (0,2) {25,7,25,7} +[..#..#.##.] (0,1,2,3,5,7,8,9) (0,1,2,4,5,6,7,8,9) (0,1,2,3,5,7,9) (3,4,6,7) (1,2,5,7,9) (1,2,5,6,7,8,9) (0,2,4,5,7,8) (1,2,4,5,6) {37,66,77,24,30,77,31,60,33,49} +[.#.#..] (0) (2,4) (1,3,4) (0,3,4,5) (1,4) (2,3,4) (0,1,2,5) {153,36,23,23,53,6} +[.####.#.#] (0,1,2,4,6,7) (0,4,5,6,7,8) (0,1,4,5,6,7,8) (0,6,8) (0,4,6,7) (1,2,3,4,8) (3,4,5,8) (0,1,3,4,7,8) (1,7,8) (1,8) {71,72,31,37,82,30,57,79,89} +[##.#.#...#] (1,2,5,9) (0,1,2,4,5,6,7,8) (0,2,3,4,5,7,8) (1,2,3) (0,2,3,4,6,8) (7,8) (0,2,5,6) (0,1,2,3,4,5,6,7) {48,27,65,47,37,40,29,195,200,0} +[#.##..##.] (0,1,2,5,6,8) (1,2,3,5,6,8) (0,1,3,4,5,7,8) (3,6,8) (1,4,5,6,8) (1,3,5,8) (1,6) (0,1,2,4,5,6,7,8) (1,2,5,6,7,8) {26,76,44,42,22,56,90,23,76} +[.#.##..#] (0,1,2,3,4,5,6) (1,2,3,4,6,7) (0,1,2,3,4,5) (0,2,5) (1,2,7) (0,1,3,4,5,6) {43,69,51,49,49,43,41,26} +[##...#.] (3,4) (0,1,2,6) (0,1,5) (1,2,3,5,6) (2,3,4,5,6) {170,184,27,29,15,181,27} +[#.##] (0,1) (0,1,3) (1,2) (2,3) {37,43,19,30} +[#.#.#.#.#.] (0,1,2,3,5,6,8,9) (1,4,6) (2,3,5,6,8) (5,7,9) (0,1,2,4,6,8,9) (6) (2,4,6,9) (0,1,2,3,4,7,9) (0,3,4,8) (4,7) (0,1,2,3,4,6,8,9) (0,4) (0,1,2,4,5,8,9) {95,75,106,66,112,74,104,28,92,101} +[.###.] (0) (0,2,3) (1,4) (1,3,4) (1,2,3,4) (0,3,4) {38,28,39,55,42} +[####..] (1,2,3) (0,3,5) (0,1,4) (0,3,4,5) (2,3) {30,23,40,67,22,27} +[.#..#.....] (0,2) (0,1,2,4,5,6,9) (0,2,3,6) (3,6,7) (0,1,2,3,4,5,6,8,9) (0,2,3,5,6,8,9) (1,9) (0,1,2,3,4,5,8,9) (1,3,4,5,6,8,9) (4,6) {77,42,77,59,47,38,87,16,23,48} +[#####] (0,1,3) (0,1,2,3) (0,1,2) (0,2,4) (1,2,3) {49,153,161,138,19} +[...#.] (1,2) (2,3,4) (0,2,3,4) (0,1,3,4) (1,2,4) (0,3,4) {30,35,44,46,62} +[.###.##.#] (3,5) (6,7) (0,6) (2,3,5,6,7) (0,2,3,4,5,6,7,8) (4,5,6,7) (2,7,8) (1,3,6,8) (2,4,5,6,7,8) {25,3,56,48,34,61,76,76,44} +[#..###] (2,4,5) (1,4,5) (0,3,5) (1,3) (0,2,3) (0,4,5) (0,1,2,3) {40,21,25,43,16,33} +[.#..#.] (1,4,5) (0,1,4) (2) (1,4) (1,3) (0,2,4,5) {13,35,11,11,32,23} +[...#] (0,2) (1,3) (0,2,3) {16,6,16,18} +[####.##.#] (0,1,3,6,7,8) (1,2,3,5,7) (0,4,6) (0,1,2,3,4,6) (3,5,7,8) (0,1,2,4,6,8) (6,8) (5,7) (1,3,5,7,8) (0,2,3,4,5,6,7) (0,2,3,4,5,7) {71,44,49,48,58,48,71,61,41} +[#.##..] (1,2,3,5) (0,1,4,5) (0,5) (0,3,5) (0,2,3) (3,4) {31,21,10,12,21,25} +[...#.#..] (4,7) (4,6,7) (3,5) (0,4,5,6,7) (1,2,4,5,7) (0,3,4,6) (0,2,5) (0,3,5,6) (1,4,5) (0,1,4,5,7) {50,39,28,43,64,89,35,40} +[..####.#] (1,2,3) (0,1,2,5) (0,1,5,6,7) (0,1,2,7) (4,7) (0,1,3,4,7) {57,57,23,20,30,18,14,63} +[.#.###.] (1,3,4,5) (0,1,2,4,6) (0,3,5) (2,3,4,6) (0,2,4) {207,19,200,30,219,28,2} +[#.###] (1,4) (0,2,3,4) (0,3) (0,1,2) (1,3,4) (1,2) (1,3) {39,51,35,43,41} +[#.##] (2) (1,3) (0,3) {11,11,1,22} +[..##] (0,2,3) (1,2) (1,3) (2,3) {4,21,20,39} +[#.#.#.] (1,2,4) (0,1,3,5) (0,1) (1,3,5) (0,4,5) (0,2,5) {46,67,19,32,20,41} +[#..#.#.#.] (5,7) (2,4,5,7) (1,2,3) (0,5,6) (2,4,7,8) (1,3,4,8) (0,1,3) (0,1,2,4,5,6,7) (0,2,4,6,8) (0,6,8) {72,60,71,47,78,69,58,67,63} +[..#.#..#] (2,7) (4) (1,4) (0,2,3) (3,4,6) (6) (5) (3,4,5,6,7) (0,4,6) (2,4,7) {15,4,8,28,53,29,54,21} +[...#] (2) (2,3) (1,3) (0,2) (0) (0,1) {22,25,31,26} +[#.#..##..] (0,1,3,4,5,6,8) (0,1,3,4,5,6,7,8) (1,2,6,8) (2,3,5,6,7) (0,1,3,4,7,8) (0,2,6) (2,3,4,5,7) (0,2,3,4,5,6,7,8) (0,2,5,6) {68,43,42,68,62,58,66,54,57} +[#.###] (1,2,4) (0,2,3) (2,4) (0,3) (2,3,4) {22,15,35,29,29} +[..###...] (1,7) (0,2) (0,1,2,3,6) (0,1,2,3,4,5,7) (1,2,4,5,6,7) (5,7) {38,22,39,18,12,16,8,19} +[..#...#] (0,3,4,5,6) (0,1,3,4,5) (0,2,3,5) (1,2) (0,1,2,3,6) (2,4) {30,18,24,30,18,16,25} +[#.##] (1,3) (0,1) (0,2) (2,3) (0,3) (0) {44,11,20,27} +[..##.##] (1,4,5,6) (2,3,4,6) (0,1,3,4,5) (0,4,5,6) (0,1,2,3,4) (0,3,4,6) (0,1,2,5,6) (0,2,4,5,6) {47,33,24,39,63,37,59} +[#####....] (5) (2,4,5,6) (0,1,2,8) (0,1,8) (1,6,7) (0,2,5,6,7,8) (0,1,2,3,4) (1,2,3,4,5,7) (0,5,7) (1,3,6,7) (0,1,3,4,5,6,7) {89,223,59,176,52,70,170,201,42} +[.##.#] (0,2,3) (0,1,3,4) (0,1,2,3) {40,32,27,40,13} +[..###.] (1,2) (0,1,5) (0,2,3,4) (0,3,4,5) {22,12,13,15,15,14} +[#####.] (1,3,5) (2,3,4) (1,2,3) (1,3,4,5) (0,1,3) (0,3,4) (0,4) {205,56,39,94,228,20} +[.##...##..] (0,1,3,5,7,9) (1,6,8,9) (0,1,2,3,4,5,6,7,8) (0,4) (0,2,8,9) (0,6) (1,2,3,7) (0,1,4,5,6,7,8,9) (1,2,5,6,7,8,9) (2,3,4,5,7) {101,86,80,62,74,80,76,91,81,75} +[###.#.#.] (0,1,2,4,5,6,7) (1,2,5,7) (0,1,2,6) (0,1,2,4,5,7) (2,4,5) (0,4,5,7) (0,1,3,4,5,6,7) {204,212,214,6,37,51,189,43} +[####.##] (1,2,4,6) (1,2,3,5) (0,2,3,4) (0,1,5,6) (2,3) {19,33,29,16,19,20,26} +[##.#####..] (0,1,2,3,4,5,6,8) (1,3,6) (0,1,2,3,5,6,7,8,9) (3,5,6,8) (0,1,3,5,6,8,9) (0,2,3,6,7,8,9) (0,1,2,3,4,5,7,8,9) (2,4,6,7,8) {21,157,35,172,31,36,189,27,56,13} +[####..#] (0,2,3) (0,2,5) (3,4) (0,1,2,3,5) (1,3,5,6) (2,4,5,6) (1,3,4,5,6) {14,30,15,49,28,33,20} +[..##.#..] (0,1,2,5,7) (0,1,3,6) (2,5) (2,3,5) (2,4,7) (0,7) (1,6) {14,156,40,4,18,22,155,31} +[#.....] (1,4,5) (1,4) (2,3,4,5) (4) (0,1) (0) (0,2,3,4) {32,47,15,15,58,19} +[#....#.##.] (0,1,2,3,4,5,7,9) (1,2,3,4,5,6,8,9) (0,1,3,4,5,6,8,9) (0,6) (0,2,3,4,5,6,7,8) (1,2,3,4,5,7,8) (1,7,9) (1,7) (0,1,6) (4,5,7) (4,7) (5) {31,64,39,56,83,86,40,74,55,39} +[...##.##] (1,2,4,5,6,7) (2,3,4,7) (1,4,5,6,7) (0,3,5,7) (1,3,4,6) (2,4) (1,7) (3,5,6) (1,3,4,5,7) {5,77,54,62,108,64,57,82} +[#####..#.#] (0,2,3,4,5,6,7,8,9) (1,2,3,5,9) (1,9) (6,9) (1,2,3,4,5,7,8,9) (0,1,6,9) (0,1,3,4,5,6,7) (0,1,2,3,5,6,9) (2,5,8,9) (4,5) (0,2,4,5,6,7,8,9) (7) {27,54,38,43,25,52,42,39,15,65} +[#...###] (1,2,3,6) (4,5) (0,4,5,6) (0,1,6) (1,3,5,6) (0,1,2,3) (0,6) (0,1,2,3,5) (0,2,3,5,6) {100,79,75,79,22,64,89} +[#.#.....] (0,1,4,5,6,7) (2,3,4,5,6,7) (4,5,6) (1,2,3,6) (0,1,5,6,7) (1,3,4,5,6) (0,3,5,6,7) (2,3,5,6,7) (0,2,3,7) (0,2,3,4,7) {44,37,41,44,53,78,83,69} +[#.##..#.#] (0,1,3) (5,8) (1,2,4,5) (0,6,7) (1,5,7) (0,1,7,8) (7,8) (0,2,5,6) (1,7) (1,2,4,5,7) (0,1,2,3,5,6,7) {60,59,41,21,14,46,32,65,31} +[#..##] (0) (1,3,4) (0,3) (2,4) (0,2) {26,15,24,20,27} +[.##.#.#.] (0,2,4,7) (1,2,3,4,5,7) (0,1,3,4,5,6) (3,5,6) (0,1,2,3,7) (0,1,3,5,7) (1,2,3,6) (1,7) {38,139,139,143,129,121,34,128} +[#.#.##..#.] (0,2,3,5) (4,8,9) (1,3,4,5,6,7,8,9) (1,2,3,5) (0,2,5,6,7) (4,8) (3,4,5,6,7,8) (0,3,9) (1,2,3,5,6,7) {29,20,42,53,45,61,35,35,45,16} +[#.####.#.#] (0,1,2,4,7) (0,1,2,4,6,7,8) (0,3,5) (0,1,2,3,7) (0,1,2,3,5,6,7,9) (2,4) (2,8) (1,2,7,8) (0,3,7) (1,5,7) (1,3,6,7,8,9) {60,64,75,44,45,25,39,67,34,23} +[###..#..#] (0,1,2,5,8) (0,1,4,5,6,7,8) (0,1,2,3,6,7,8) (0,1,3,4,5,7,8) (5,7,8) (1,2,4,8) (4,6) (0,6,7) {61,58,28,30,58,46,65,75,73} +[#.....] (0,2,5) (1,3) (2,3,4,5) (1,2) (0,1,5) (0,1,2,4) (0) (1,2,4,5) {195,178,197,20,171,62} +[##..] (0,1,3) (0,3) (1,2,3) (0,2) (2) (1,3) {27,27,35,41} +[#####.] (0,4) (1,2,4) (0,1,5) (3,4) {26,33,15,17,40,18} +[.##..#.#.] (4,6,7,8) (2,3,7) (0,4) (1,5,8) (1,4,5) (0,2,3,4,5,6,7,8) (0,2,3,4,6,7,8) (1,3,4,5,6,7,8) {34,41,25,44,90,60,63,63,67} +[#...] (0,2,3) (0,3) (1,2) (0,1,2) (0,2) {43,32,51,11} +[.#.#.#..#] (0,1,5,8) (2,4,6) (0,2,4,5,7,8) (1,2,7) (4,6,8) (0,1,5,6,7) (0,3,6,7,8) {61,48,177,18,169,43,186,58,59} +[..###] (0,1,2) (0,1,4) (1,2,3) (0,3,4) (2,3,4) (0,2,3) {29,204,216,217,9} +[.#.#.#..#.] (2,3,4,5,8,9) (0,1,3,5,7) (1,2,4,6,7,8) (1,2,3,4,5,6,8) (0,1,2,3,4,6,8,9) (1,3,5,6,7,8,9) (1,3,6,7) (0,1,5,6,7,9) (1,2,3,4,5,6,7,8) {22,190,45,193,45,65,185,170,64,50} +[#.##.] (0,1,3,4) (0,1,2) (1,2,3) (0,2,3) (3) (1,3) (2) {41,42,32,38,15} +[..#.##] (2,3,5) (0,1,5) (0,3,4,5) (1,2,4,5) (0,1,4,5) (5) (1,3,4) (1,4) {39,69,22,17,54,61} +[##..#.##] (1,2,3,5,6,7) (3,5,6,7) (0,1,2,3,4,6,7) (1,6,7) (0,2,4,7) (3,4) (1,3,4) (1,3,5,7) (0,1,2,3,4,6) {25,64,42,83,45,42,61,60} +[.##....#] (0,2,5,7) (0,1,2,3,5) (0,2,3,4,5) (0,1,4,5,6) (0,2,4,5,6) (3,6,7) (1,4,5,6,7) (0,2,3,4,5,7) {64,14,53,29,46,65,41,44} +[#......] (0,1,3,4,5,6) (1,4,6) (0,1,6) (0,1) (1,2,3,5) (1,3,4,5) (0,1,2,3,6) (0,1,3,4,5) {174,188,6,150,153,144,159} +[.##.##] (0,1,2,3,5) (0,5) (1,4,5) (0,2,5) (0,2,3,4) (1,3,5) {42,32,35,22,16,55} +[#.#....#] (0,2,7) (3,6,7) (2,4,6,7) (0,1,4,5,6) (1,2,4,5,7) (0,1,2,3,4) (1,5,7) {24,27,52,30,44,17,41,63} +[.##.##.#.] (0,1,2,3,4,7,8) (0,3,5,8) (1,2,4) (0,2,3,5,7,8) (0,1,2,4,5,6,7,8) (0,2,3) (1,3,4,5,6,7) {86,52,81,72,52,52,18,51,69} +[#.#.###.] (4,6) (1,2,3,4,5) (0,1,2,3,4,5,6) (0) (0,1,4,6) (3) (1,6) (1,5) (0,4,7) (0,2,3) {52,30,14,29,35,28,16,18} +[#.##] (1,3) (0,2,3) {8,9,8,17} +[#...##..#.] (0,1,2,4,6,8,9) (2,5,6,8,9) (1,3,8) (0,1,2,3,4,6,8,9) (0,4,5,8,9) (0,8) (0,1) (1,2,3,4,5,6,8,9) (4,5,7,9) {51,67,69,48,71,52,69,8,99,86} +[.####.##] (1,2,4,6) (1,2,3,7) (0,1,3,4,5,6,7) (0,2,3,4,6,7) (1,4,5,7) (0,2,3,4,5,7) (0,1,2,3,5) (0,2,3,5,6) (0,4) {70,55,72,63,71,45,60,45} +[...#] (1) (2) (0,1) (0,1,3) (1,3) {34,45,6,27} +[.#.####] (3,4,5) (0,1,4,5) (0,1,2,4,6) (2,5) (1,2,3,4,6) (0,1,3,6) {37,38,16,32,35,23,31} +[...#.#] (1,5) (0,1) (4) (0,1,4) (0,3,4) (0,1,2) (0,2,3,4) {44,43,25,20,25,19} +[#####.] (0,2,3,4) (0,1,3) (1,2,3,4,5) (0,1,2) (0,1,2,4,5) {159,24,154,146,144,7} +[.#..#] (1,2,3,4) (0,2,3,4) (1,2) (3,4) (0,4) (0,1) {27,23,36,29,31} \ No newline at end of file diff --git a/src/day10/mod.rs b/src/day10/mod.rs new file mode 100644 index 0000000..711d482 --- /dev/null +++ b/src/day10/mod.rs @@ -0,0 +1,22 @@ +pub mod part10a; +pub mod part10b; + +#[cfg(test)] +mod tests { + use crate::day10::{part10a, part10b}; + + const PUZZLE: &str = "[.##.] (3) (1,3) (2) (2,3) (0,2) (0,1) {3,5,4,7} +[...#.] (0,2,3,4) (2,3) (0,4) (0,1,2) (1,2,3,4) {7,5,12,7,2} +[.###.#] (0,1,2,3,4) (0,3,4) (0,1,2,4,5) (1,2) {10,11,11,5,10,5}"; + + #[test] + fn part10a() { + assert_eq!(part10a::solve(PUZZLE.to_string()), 7); + } + + #[test] + #[ignore] + fn part10b() { + assert_eq!(part10b::solve(PUZZLE.to_string()), 0); + } +} \ No newline at end of file diff --git a/src/day10/part10a.rs b/src/day10/part10a.rs new file mode 100644 index 0000000..2ec13c5 --- /dev/null +++ b/src/day10/part10a.rs @@ -0,0 +1,72 @@ +use std::fmt::Debug; +use std::ops::{Add, BitXor}; + +fn min_preferring_some(a: Option, b: Option) -> Option { + let r = match (a, b) { + (Some(v), None) => Some(v), + (None, Some(v)) => Some(v), + (Some(v1), Some(v2)) => Some(v1.min(v2)), + (None, None) => None, + }; + r +} + +fn find_least_combinations + Eq + Default + Copy>(pre_press: T, buttons: &[T], mut max_depth: usize) -> Option { + if max_depth == 0 {return None} + + let button = buttons.first()?; + let post_press = pre_press ^ *button; + if post_press == T::default() { + return Some(1); + } + + let max_pressed = match find_least_combinations(post_press, &buttons[1..], max_depth-1) { + Some(v) => { + max_depth = v; + Some(v+1) + }, + None => None, + }; + if let Some(max) = max_pressed {max_depth = max} + + let max_unpressed = find_least_combinations(pre_press, &buttons[1..], max_depth); + min_preferring_some(max_pressed, max_unpressed) +} + +pub fn solve(puzzle: String) -> u64 { + puzzle + .lines() + .map(|line| { + let mut chunks = line.split_whitespace(); + let button_cnt = chunks.clone().count() - 2; + ( + chunks + .next() + .unwrap() + .chars() + .filter(|c| c != &'[' && c != &']') + .map(|c| match c { + '#' => 1, + _ => 0 + }) + .rev() + .reduce(|a, b| a << 1 | b) + .unwrap(), + chunks + .take(button_cnt) + .map(|button| + button + .chars() + .filter(|c| c != &'(' && c != &')' && c != &',') + .map(|c| c as u8) + .map(|c| 1 << (c - b'0')) + .map(|c| c as u16) + .reduce(|a, b| a | b) + .unwrap() + ) + .collect::>(), + ) + }) + .map(|tup| find_least_combinations(tup.0, &tup.1, usize::MAX).unwrap()) + .sum::() as u64 +} diff --git a/src/day10/part10b.rs b/src/day10/part10b.rs new file mode 100644 index 0000000..986c86a --- /dev/null +++ b/src/day10/part10b.rs @@ -0,0 +1,4 @@ + +pub fn solve(puzzle: String) -> u64 { + 0 // TODO +} diff --git a/src/main.rs b/src/main.rs index 1cdd0c7..b4ea594 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ mod day06; mod day07; mod day08; mod day09; +mod day10; use std::time::Instant; @@ -43,6 +44,8 @@ fn main() { ("day08:B", day08::part08b::solve, "puzzles/input08.txt"), ("day09:A", day09::part09a::solve, "puzzles/input09.txt"), ("day09:B", day09::part09b::solve, "puzzles/input09.txt"), + ("day10:A", day10::part10a::solve, "puzzles/input10.txt"), + ("day10:B", day10::part10b::solve, "puzzles/input10.txt"), ]; let start: Instant = Instant::now();