diff --git a/data/day14/example01.txt b/data/day14/example01.txt new file mode 100644 index 0000000..1926028 --- /dev/null +++ b/data/day14/example01.txt @@ -0,0 +1,2 @@ +498,4 -> 498,6 -> 496,6 +503,4 -> 502,4 -> 502,9 -> 494,9 \ No newline at end of file diff --git a/data/day14/input.txt b/data/day14/input.txt new file mode 100644 index 0000000..880a895 --- /dev/null +++ b/data/day14/input.txt @@ -0,0 +1,179 @@ +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +568,139 -> 573,139 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +517,81 -> 517,84 -> 509,84 -> 509,92 -> 524,92 -> 524,84 -> 522,84 -> 522,81 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +531,98 -> 531,102 -> 526,102 -> 526,109 -> 540,109 -> 540,102 -> 535,102 -> 535,98 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +534,78 -> 539,78 +513,78 -> 518,78 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +531,98 -> 531,102 -> 526,102 -> 526,109 -> 540,109 -> 540,102 -> 535,102 -> 535,98 +553,133 -> 558,133 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +511,53 -> 515,53 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +543,144 -> 543,145 -> 560,145 -> 560,144 +522,69 -> 527,69 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +560,133 -> 565,133 +561,139 -> 566,139 +518,94 -> 518,95 -> 532,95 -> 532,94 +497,13 -> 497,17 -> 489,17 -> 489,22 -> 502,22 -> 502,17 -> 501,17 -> 501,13 +531,98 -> 531,102 -> 526,102 -> 526,109 -> 540,109 -> 540,102 -> 535,102 -> 535,98 +553,118 -> 553,120 -> 549,120 -> 549,124 -> 561,124 -> 561,120 -> 557,120 -> 557,118 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +517,53 -> 521,53 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +518,94 -> 518,95 -> 532,95 -> 532,94 +520,78 -> 525,78 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +546,114 -> 546,115 -> 554,115 -> 554,114 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +522,63 -> 527,63 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +564,136 -> 569,136 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +534,111 -> 534,112 -> 549,112 -> 549,111 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +497,13 -> 497,17 -> 489,17 -> 489,22 -> 502,22 -> 502,17 -> 501,17 -> 501,13 +553,118 -> 553,120 -> 549,120 -> 549,124 -> 561,124 -> 561,120 -> 557,120 -> 557,118 +526,72 -> 531,72 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +533,66 -> 538,66 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +527,78 -> 532,78 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +517,81 -> 517,84 -> 509,84 -> 509,92 -> 524,92 -> 524,84 -> 522,84 -> 522,81 +517,81 -> 517,84 -> 509,84 -> 509,92 -> 524,92 -> 524,84 -> 522,84 -> 522,81 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +553,118 -> 553,120 -> 549,120 -> 549,124 -> 561,124 -> 561,120 -> 557,120 -> 557,118 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +497,13 -> 497,17 -> 489,17 -> 489,22 -> 502,22 -> 502,17 -> 501,17 -> 501,13 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +550,136 -> 555,136 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +556,130 -> 561,130 +517,81 -> 517,84 -> 509,84 -> 509,92 -> 524,92 -> 524,84 -> 522,84 -> 522,81 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +547,139 -> 552,139 +505,57 -> 509,57 +497,13 -> 497,17 -> 489,17 -> 489,22 -> 502,22 -> 502,17 -> 501,17 -> 501,13 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +567,133 -> 572,133 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +520,55 -> 524,55 +517,81 -> 517,84 -> 509,84 -> 509,92 -> 524,92 -> 524,84 -> 522,84 -> 522,81 +543,144 -> 543,145 -> 560,145 -> 560,144 +553,118 -> 553,120 -> 549,120 -> 549,124 -> 561,124 -> 561,120 -> 557,120 -> 557,118 +497,13 -> 497,17 -> 489,17 -> 489,22 -> 502,22 -> 502,17 -> 501,17 -> 501,13 +575,139 -> 580,139 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +511,57 -> 515,57 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +497,13 -> 497,17 -> 489,17 -> 489,22 -> 502,22 -> 502,17 -> 501,17 -> 501,13 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +517,81 -> 517,84 -> 509,84 -> 509,92 -> 524,92 -> 524,84 -> 522,84 -> 522,81 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +553,118 -> 553,120 -> 549,120 -> 549,124 -> 561,124 -> 561,120 -> 557,120 -> 557,118 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +531,98 -> 531,102 -> 526,102 -> 526,109 -> 540,109 -> 540,102 -> 535,102 -> 535,98 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +514,55 -> 518,55 +546,114 -> 546,115 -> 554,115 -> 554,114 +557,136 -> 562,136 +571,136 -> 576,136 +546,114 -> 546,115 -> 554,115 -> 554,114 +497,13 -> 497,17 -> 489,17 -> 489,22 -> 502,22 -> 502,17 -> 501,17 -> 501,13 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +553,118 -> 553,120 -> 549,120 -> 549,124 -> 561,124 -> 561,120 -> 557,120 -> 557,118 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +525,60 -> 530,60 +559,127 -> 564,127 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +517,81 -> 517,84 -> 509,84 -> 509,92 -> 524,92 -> 524,84 -> 522,84 -> 522,81 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +529,63 -> 534,63 +526,66 -> 531,66 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +508,55 -> 512,55 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +534,111 -> 534,112 -> 549,112 -> 549,111 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +531,98 -> 531,102 -> 526,102 -> 526,109 -> 540,109 -> 540,102 -> 535,102 -> 535,98 +516,75 -> 521,75 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +523,75 -> 528,75 +523,57 -> 527,57 +519,66 -> 524,66 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +554,139 -> 559,139 +543,144 -> 543,145 -> 560,145 -> 560,144 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +553,118 -> 553,120 -> 549,120 -> 549,124 -> 561,124 -> 561,120 -> 557,120 -> 557,118 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +514,51 -> 518,51 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +517,57 -> 521,57 +531,98 -> 531,102 -> 526,102 -> 526,109 -> 540,109 -> 540,102 -> 535,102 -> 535,98 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +518,94 -> 518,95 -> 532,95 -> 532,94 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +496,35 -> 496,29 -> 496,35 -> 498,35 -> 498,26 -> 498,35 -> 500,35 -> 500,25 -> 500,35 -> 502,35 -> 502,34 -> 502,35 -> 504,35 -> 504,31 -> 504,35 -> 506,35 -> 506,33 -> 506,35 -> 508,35 -> 508,25 -> 508,35 +530,75 -> 535,75 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +519,72 -> 524,72 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +563,130 -> 568,130 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +531,98 -> 531,102 -> 526,102 -> 526,109 -> 540,109 -> 540,102 -> 535,102 -> 535,98 +534,111 -> 534,112 -> 549,112 -> 549,111 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +561,171 -> 561,162 -> 561,171 -> 563,171 -> 563,168 -> 563,171 -> 565,171 -> 565,163 -> 565,171 -> 567,171 -> 567,163 -> 567,171 -> 569,171 -> 569,161 -> 569,171 -> 571,171 -> 571,170 -> 571,171 -> 573,171 -> 573,166 -> 573,171 -> 575,171 -> 575,161 -> 575,171 -> 577,171 -> 577,165 -> 577,171 +501,48 -> 501,44 -> 501,48 -> 503,48 -> 503,39 -> 503,48 -> 505,48 -> 505,39 -> 505,48 -> 507,48 -> 507,41 -> 507,48 -> 509,48 -> 509,41 -> 509,48 -> 511,48 -> 511,47 -> 511,48 -> 513,48 -> 513,47 -> 513,48 -> 515,48 -> 515,43 -> 515,48 +551,158 -> 551,154 -> 551,158 -> 553,158 -> 553,156 -> 553,158 -> 555,158 -> 555,152 -> 555,158 -> 557,158 -> 557,149 -> 557,158 -> 559,158 -> 559,156 -> 559,158 -> 561,158 -> 561,152 -> 561,158 -> 563,158 -> 563,155 -> 563,158 -> 565,158 -> 565,153 -> 565,158 -> 567,158 -> 567,155 -> 567,158 -> 569,158 -> 569,149 -> 569,158 \ No newline at end of file diff --git a/src/days/day14/mod.rs b/src/days/day14/mod.rs new file mode 100644 index 0000000..e8ace33 --- /dev/null +++ b/src/days/day14/mod.rs @@ -0,0 +1,292 @@ +use itertools::Itertools; +use std::{collections::HashSet, num::ParseIntError}; +use thiserror::Error; + +use crate::common::pos::Pos; + +use super::template::{DayTrait, ResultType}; + +const DAY_NUMBER: usize = 14; + +pub struct Day; + +impl DayTrait for Day { + fn get_day_number(&self) -> usize { + DAY_NUMBER + } + + fn part1(&self, lines: &[String]) -> anyhow::Result { + let cave = Cave::parse(lines)?; + Ok(ResultType::Integer(cave.drop_bottomless() as i64)) + } + + fn part2(&self, lines: &[String]) -> anyhow::Result { + let cave = Cave::parse(lines)?; + Ok(ResultType::Integer(cave.drop_floor())) + } +} + +#[derive(Debug, Error)] +enum CaveError { + #[error("Could not parse")] + ParseError, + + #[error("Error, while paring int")] + NotAValidInteger(#[from] ParseIntError), + + #[error("Not a valid Pos {0}")] + NotAValidPos(String), + + #[error("Found an empty path")] + EmptyPath, + + #[error("Found an empty cave")] + EmptyCave, +} + +struct Cave { + map: Vec>, + min_x: i32, + max_x: i32, + height: i32, +} + +impl Cave { + fn get(&self, map: &[Vec], pos: Pos) -> bool { + if pos.y() >= self.height || pos.x() < self.min_x || pos.x() > self.max_x { + false + } else { + map[pos.y() as usize][(pos.x() - self.min_x) as usize] + } + } + + fn set(&self, map: &mut [Vec], pos: Pos) { + map[pos.y() as usize][(pos.x() - self.min_x) as usize] = true + } + + fn walk(from: Pos, to: Pos) -> Result>, CaveError> { + if from == to { + return Ok(vec![from]); + } + if from.x() == to.x() { + if from.y() < to.y() { + Ok((from.y()..to.y()).map(|y| Pos::new(from.x(), y)).collect()) + } else { + Ok(((to.y() + 1)..=from.y()) + .map(|y| Pos::new(from.x(), y)) + .collect()) + } + } else if from.y() == to.y() { + if from.x() < to.x() { + Ok((from.x()..to.x()).map(|x| Pos::new(x, from.y())).collect()) + } else { + Ok(((to.x() + 1)..=from.x()) + .map(|x| Pos::new(x, from.y())) + .collect()) + } + } else { + Err(CaveError::ParseError) + } + } + + fn parse_one(line: &str) -> Result>, CaveError> { + let corners = line + .split("->") + .map(|coord| match coord.split(',').collect::>()[..] { + [first, second] => { + let x: i32 = first.trim().parse()?; + let y = second.trim().parse()?; + Ok(Pos::new(x, y)) + } + _ => Err(CaveError::NotAValidPos(coord.to_owned())), + }) + .collect::, CaveError>>()?; + + if corners.is_empty() { + return Err(CaveError::EmptyPath); + } + + let blocks = corners + .iter() + .tuple_windows() + .map(|(first, second)| Cave::walk(*first, *second)) + .collect::, _>>()?; + + let mut blocks = blocks.iter().flatten().copied().collect::>(); + blocks.insert(*corners.last().unwrap()); + + Ok(blocks) + } + + pub fn parse(lines: &[String]) -> Result { + let mut cave: HashSet> = HashSet::new(); + for line in lines { + cave.extend(Cave::parse_one(line)?.iter()); + } + if cave.is_empty() { + Err(CaveError::EmptyCave) + } else { + let mut max_x = i32::MIN; + let mut min_x = i32::MAX; + let mut max_y = i32::MIN; + for block in &cave { + if block.x() < min_x { + min_x = block.x(); + } + if block.x() > max_x { + max_x = block.x(); + } + if block.y() > max_y { + max_y = block.y() + } + } + let mut map = vec![vec![false; (max_x - min_x + 1) as usize]; (max_y + 1) as usize]; + for block in cave { + map[block.y() as usize][(block.x() - min_x) as usize] = true; + } + Ok(Cave { + map, + min_x, + max_x, + height: max_y + 1, + }) + } + } + + pub fn drop_bottomless(&self) -> u32 { + let mut drops = 0; + let mut filled_map = self.map.to_vec(); + + while let Some(next) = self.drop_one(&filled_map) { + if next.y() <= self.height { + drops += 1; + self.set(&mut filled_map, next); + } else { + break; + } + } + drops + } + + fn drop_one(&self, map: &[Vec]) -> Option> { + let mut drop = Pos::new(500, 0); + loop { + let next_y = drop.y() + 1; + if next_y > self.height { + return None; + } + let mut stuck = true; + for dx in [0, -1, 1] { + let next = Pos::new(drop.x() + dx, next_y); + if !self.get(map, next) { + drop = next; + stuck = false; + break; + } + } + + if stuck { + if drop.y() == 0 { + return None; + } else { + return Some(drop); + } + } + } + } + + pub fn drop_floor(&self) -> i64 { + let last_row = self.height + 1; + let mut drops = 1; + let mut row = vec![500]; + let mut left_exceed = None; + let mut right_exceed = None; + for y in 1..last_row { + let mut next_row = Vec::new(); + for x in row { + for dx in [-1, 0, 1] { + let x = x + dx; + if x < self.min_x { + left_exceed = left_exceed.or(Some(y)); + } else if x > self.max_x { + right_exceed = right_exceed.or(Some(y)); + } else if !next_row.contains(&x) + && (y >= self.height || !self.map[y as usize][(x - self.min_x) as usize]) + { + next_row.push(x); + } + } + } + if let Some(left_exceed) = left_exceed { + if !next_row.contains(&self.min_x) && (y >= self.height || !self.map[y as usize][0]) + { + next_row.push(self.min_x); + } + drops += (y - left_exceed + 1) as i64; + } + if let Some(right_exceed) = right_exceed { + if !next_row.contains(&self.max_x) + && (y >= self.height + || !self.map[y as usize][(self.max_x - self.min_x) as usize]) + { + next_row.push(self.max_x); + } + drops += (y - right_exceed + 1) as i64; + } + drops += next_row.len() as i64; + row = next_row + } + drops + } +} + +#[cfg(test)] +mod test { + use super::*; + use crate::{common::file::read_lines, hashset}; + use anyhow::Result; + + #[test] + fn test_parse() -> Result<()> { + let input = "498,4 -> 498,6 -> 496,6"; + let expected = hashset! {Pos::new(498, 4), Pos::new(498, 5), Pos::new(498, 6), Pos::new(497, 6), Pos::new(496, 6)}; + let result = Cave::parse_one(input)?; + assert_eq!(result, expected); + + Ok(()) + } + + #[test] + fn test_parse_all() -> Result<()> { + let day = Day {}; + let lines = read_lines(day.get_day_number(), "example01.txt")?; + let result = Cave::parse(&lines)?; + assert_eq!(result.min_x, 494); + assert_eq!(result.max_x, 503); + assert_eq!(result.height, 10); + + Ok(()) + } + + #[test] + fn test_part1() -> Result<()> { + let day = Day {}; + let lines = read_lines(day.get_day_number(), "example01.txt")?; + let expected = ResultType::Integer(24); + let result = day.part1(&lines)?; + assert_eq!(result, expected); + + Ok(()) + } + + #[test] + fn test_part2() -> Result<()> { + let day = Day {}; + let lines = read_lines(day.get_day_number(), "example01.txt")?; + let expected = ResultType::Integer(93); + let result = day.part2(&lines)?; + assert_eq!(result, expected); + + Ok(()) + } +} diff --git a/src/days/mod.rs b/src/days/mod.rs index 9435baa..ce2ea67 100644 --- a/src/days/mod.rs +++ b/src/days/mod.rs @@ -11,6 +11,7 @@ mod day10; mod day11; mod day12; mod day13; +mod day14; mod template; pub use template::DayTrait; @@ -20,7 +21,7 @@ pub mod day_provider { use super::*; use thiserror::Error; - const MAX_DAY: usize = 13; + const MAX_DAY: usize = 14; pub fn get_day(day_num: usize) -> Result, ProviderError> { match day_num { @@ -37,6 +38,7 @@ pub mod day_provider { 11 => Ok(Box::new(day11::Day)), 12 => Ok(Box::new(day12::Day)), 13 => Ok(Box::new(day13::Day)), + 14 => Ok(Box::new(day14::Day)), _ => Err(ProviderError::InvalidNumber(day_num)), } }