diff --git a/2022/day14/input b/2022/day14/input new file mode 100644 index 0000000..049aec7 --- /dev/null +++ b/2022/day14/input @@ -0,0 +1,129 @@ +490,51 -> 490,54 -> 486,54 -> 486,59 -> 499,59 -> 499,54 -> 492,54 -> 492,51 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +472,79 -> 472,73 -> 472,79 -> 474,79 -> 474,69 -> 474,79 -> 476,79 -> 476,77 -> 476,79 +477,148 -> 477,138 -> 477,148 -> 479,148 -> 479,144 -> 479,148 -> 481,148 -> 481,146 -> 481,148 +484,132 -> 489,132 +501,15 -> 506,15 +485,85 -> 485,88 -> 482,88 -> 482,93 -> 499,93 -> 499,88 -> 491,88 -> 491,85 +472,79 -> 472,73 -> 472,79 -> 474,79 -> 474,69 -> 474,79 -> 476,79 -> 476,77 -> 476,79 +503,43 -> 514,43 -> 514,42 +497,13 -> 502,13 +490,51 -> 490,54 -> 486,54 -> 486,59 -> 499,59 -> 499,54 -> 492,54 -> 492,51 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +498,17 -> 503,17 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +490,51 -> 490,54 -> 486,54 -> 486,59 -> 499,59 -> 499,54 -> 492,54 -> 492,51 +467,81 -> 467,82 -> 487,82 -> 487,81 +481,135 -> 486,135 +485,85 -> 485,88 -> 482,88 -> 482,93 -> 499,93 -> 499,88 -> 491,88 -> 491,85 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +470,122 -> 470,123 -> 485,123 -> 485,122 +491,132 -> 496,132 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +491,17 -> 496,17 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +497,26 -> 501,26 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +491,22 -> 495,22 +477,148 -> 477,138 -> 477,148 -> 479,148 -> 479,144 -> 479,148 -> 481,148 -> 481,146 -> 481,148 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +480,129 -> 485,129 +490,51 -> 490,54 -> 486,54 -> 486,59 -> 499,59 -> 499,54 -> 492,54 -> 492,51 +477,132 -> 482,132 +477,148 -> 477,138 -> 477,148 -> 479,148 -> 479,144 -> 479,148 -> 481,148 -> 481,146 -> 481,148 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +488,20 -> 492,20 +492,48 -> 506,48 -> 506,47 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +477,148 -> 477,138 -> 477,148 -> 479,148 -> 479,144 -> 479,148 -> 481,148 -> 481,146 -> 481,148 +474,135 -> 479,135 +479,64 -> 484,64 +510,29 -> 510,33 -> 506,33 -> 506,39 -> 517,39 -> 517,33 -> 512,33 -> 512,29 +486,64 -> 491,64 +490,66 -> 495,66 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +472,79 -> 472,73 -> 472,79 -> 474,79 -> 474,69 -> 474,79 -> 476,79 -> 476,77 -> 476,79 +494,24 -> 498,24 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +471,109 -> 471,112 -> 467,112 -> 467,120 -> 477,120 -> 477,112 -> 475,112 -> 475,109 +503,43 -> 514,43 -> 514,42 +477,148 -> 477,138 -> 477,148 -> 479,148 -> 479,144 -> 479,148 -> 481,148 -> 481,146 -> 481,148 +485,85 -> 485,88 -> 482,88 -> 482,93 -> 499,93 -> 499,88 -> 491,88 -> 491,85 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +510,29 -> 510,33 -> 506,33 -> 506,39 -> 517,39 -> 517,33 -> 512,33 -> 512,29 +488,135 -> 493,135 +472,79 -> 472,73 -> 472,79 -> 474,79 -> 474,69 -> 474,79 -> 476,79 -> 476,77 -> 476,79 +467,81 -> 467,82 -> 487,82 -> 487,81 +483,126 -> 488,126 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +483,66 -> 488,66 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +477,148 -> 477,138 -> 477,148 -> 479,148 -> 479,144 -> 479,148 -> 481,148 -> 481,146 -> 481,148 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +476,66 -> 481,66 +472,79 -> 472,73 -> 472,79 -> 474,79 -> 474,69 -> 474,79 -> 476,79 -> 476,77 -> 476,79 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +494,15 -> 499,15 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +485,85 -> 485,88 -> 482,88 -> 482,93 -> 499,93 -> 499,88 -> 491,88 -> 491,85 +485,22 -> 489,22 +487,129 -> 492,129 +477,148 -> 477,138 -> 477,148 -> 479,148 -> 479,144 -> 479,148 -> 481,148 -> 481,146 -> 481,148 +471,109 -> 471,112 -> 467,112 -> 467,120 -> 477,120 -> 477,112 -> 475,112 -> 475,109 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +485,85 -> 485,88 -> 482,88 -> 482,93 -> 499,93 -> 499,88 -> 491,88 -> 491,85 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +488,24 -> 492,24 +490,51 -> 490,54 -> 486,54 -> 486,59 -> 499,59 -> 499,54 -> 492,54 -> 492,51 +472,79 -> 472,73 -> 472,79 -> 474,79 -> 474,69 -> 474,79 -> 476,79 -> 476,77 -> 476,79 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +485,85 -> 485,88 -> 482,88 -> 482,93 -> 499,93 -> 499,88 -> 491,88 -> 491,85 +472,79 -> 472,73 -> 472,79 -> 474,79 -> 474,69 -> 474,79 -> 476,79 -> 476,77 -> 476,79 +477,148 -> 477,138 -> 477,148 -> 479,148 -> 479,144 -> 479,148 -> 481,148 -> 481,146 -> 481,148 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +510,29 -> 510,33 -> 506,33 -> 506,39 -> 517,39 -> 517,33 -> 512,33 -> 512,29 +495,135 -> 500,135 +471,109 -> 471,112 -> 467,112 -> 467,120 -> 477,120 -> 477,112 -> 475,112 -> 475,109 +510,29 -> 510,33 -> 506,33 -> 506,39 -> 517,39 -> 517,33 -> 512,33 -> 512,29 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +471,109 -> 471,112 -> 467,112 -> 467,120 -> 477,120 -> 477,112 -> 475,112 -> 475,109 +482,24 -> 486,24 +471,109 -> 471,112 -> 467,112 -> 467,120 -> 477,120 -> 477,112 -> 475,112 -> 475,109 +510,29 -> 510,33 -> 506,33 -> 506,39 -> 517,39 -> 517,33 -> 512,33 -> 512,29 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +491,26 -> 495,26 +470,122 -> 470,123 -> 485,123 -> 485,122 +505,17 -> 510,17 +470,122 -> 470,123 -> 485,123 -> 485,122 +510,29 -> 510,33 -> 506,33 -> 506,39 -> 517,39 -> 517,33 -> 512,33 -> 512,29 +485,26 -> 489,26 +471,109 -> 471,112 -> 467,112 -> 467,120 -> 477,120 -> 477,112 -> 475,112 -> 475,109 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +471,109 -> 471,112 -> 467,112 -> 467,120 -> 477,120 -> 477,112 -> 475,112 -> 475,109 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +485,85 -> 485,88 -> 482,88 -> 482,93 -> 499,93 -> 499,88 -> 491,88 -> 491,85 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +472,79 -> 472,73 -> 472,79 -> 474,79 -> 474,69 -> 474,79 -> 476,79 -> 476,77 -> 476,79 +510,29 -> 510,33 -> 506,33 -> 506,39 -> 517,39 -> 517,33 -> 512,33 -> 512,29 +467,81 -> 467,82 -> 487,82 -> 487,81 +479,26 -> 483,26 +492,48 -> 506,48 -> 506,47 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +490,51 -> 490,54 -> 486,54 -> 486,59 -> 499,59 -> 499,54 -> 492,54 -> 492,51 +482,62 -> 487,62 +476,161 -> 476,156 -> 476,161 -> 478,161 -> 478,160 -> 478,161 -> 480,161 -> 480,154 -> 480,161 -> 482,161 -> 482,155 -> 482,161 -> 484,161 -> 484,158 -> 484,161 -> 486,161 -> 486,159 -> 486,161 +490,51 -> 490,54 -> 486,54 -> 486,59 -> 499,59 -> 499,54 -> 492,54 -> 492,51 +457,106 -> 457,99 -> 457,106 -> 459,106 -> 459,98 -> 459,106 -> 461,106 -> 461,97 -> 461,106 -> 463,106 -> 463,105 -> 463,106 -> 465,106 -> 465,99 -> 465,106 -> 467,106 -> 467,103 -> 467,106 -> 469,106 -> 469,101 -> 469,106 -> 471,106 -> 471,103 -> 471,106 -> 473,106 -> 473,100 -> 473,106 diff --git a/2022/day14/main.go b/2022/day14/main.go new file mode 100644 index 0000000..f425d54 --- /dev/null +++ b/2022/day14/main.go @@ -0,0 +1,180 @@ +package main + +import ( + "errors" + "fmt" + "strings" + "time" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +var debug bool + +func main() { + inp := h.StdinToStringSlice() + part1(inp) + part2(inp) +} + +func Check(spot h.Coordinate, walls, sand *h.CoordByteMap) byte { + if v := walls.Get(spot); v != 0 { + return v + } + return sand.Get(spot) +} + +func part1(inp []string) { + m := BuildMap(inp) + // Now start dropping sand + var err error + for err == nil { + entry := &h.Coordinate{X: 500, Y: 0} + err = Drop(entry, m) + if err != nil { + } else { + m.Put(*entry, 'o') + } + } + fmt.Println("# Part 1") + fmt.Println(m.Count('o'), "grains of sand") +} + +// Drop 'grain' into the field described by 'walls', and 'sand' +// It returns the path that it took +// If it flows off the map, error is returned +func Drop(grain *h.Coordinate, m *h.CoordByteMap) error { + var path []h.Coordinate + prevX, prevY := grain.X, grain.Y + for { + if grain.South().Y > m.BRY { + return errors.New("Overflow") + } else if m.Get(grain.South()) == 0 { + path = append(path, grain.South()) + grain.MoveSouth() + } else if m.Get(grain.SW()) == 0 { + path = append(path, grain.SW()) + grain.MoveSW() + } else if m.Get(grain.SE()) == 0 { + path = append(path, grain.SE()) + grain.MoveSE() + } + if debug { + fmt.Println(h.CLEAR_SCREEN) + m.Put(*grain, 'o') + fmt.Println(m) + m.Delete(*grain) + time.Sleep(time.Second / 100) + } + // Grain didn't move, must be at rest + if grain.X == prevX && grain.Y == prevY { + return nil + } + prevX, prevY = grain.X, grain.Y + } +} + +func part2(inp []string) { + m := BuildMap(inp) + m.BRY += 1 + // Now start dropping sand + var err error + for err == nil { + entry := &h.Coordinate{X: 500, Y: 0} + err = Drop2(entry, m) + m.Put(*entry, 'o') + } + fmt.Println("# Part 2") + fmt.Println(m.Count('o'), "grains of sand") +} +func Drop2(grain *h.Coordinate, m *h.CoordByteMap) error { + var path []h.Coordinate + prevX, prevY := grain.X, grain.Y + var moved bool + for { + if grain.Y == m.BRY { + return nil + } + if m.Get(grain.South()) == 0 { + path = append(path, grain.South()) + grain.MoveSouth() + moved = true + } else if m.Get(grain.SW()) == 0 { + path = append(path, grain.SW()) + grain.MoveSW() + moved = true + } else if m.Get(grain.SE()) == 0 { + path = append(path, grain.SE()) + grain.MoveSE() + moved = true + } + if debug { + fmt.Println(h.CLEAR_SCREEN) + m.Put(*grain, 'o') + fmt.Println(m) + m.Delete(*grain) + time.Sleep(time.Second / 100) + } + if grain.X == prevX && grain.Y == prevY { + // Grain didn't move, must be at rest + if !moved { + return errors.New("Full") + } + return nil + } + prevX, prevY = grain.X, grain.Y + } +} + +func BuildMap(inp []string) *h.CoordByteMap { + m := h.NewCoordByteMap() + m.TLY = 0 + m.StringEmptyIsSpace = true + m.StringEmptyByte = '.' + for i := range inp { + var start, end *h.Coordinate + pts := strings.Split(inp[i], " -> ") + for j := range pts { + if start == nil { + start = h.CoordinateFromString(pts[j]) + } else if end == nil { + end = h.CoordinateFromString(pts[j]) + } + if start != nil && end != nil { + puts := GetLine(start, end) + for _, coord := range puts { + m.Put(*coord, '#') + } + start, end = end, nil + } + } + } + return &m +} + +func GetLine(c1, c2 *h.Coordinate) []*h.Coordinate { + var ret []*h.Coordinate + if c1.X == c2.X { + if c1.Y < c2.Y { + for y := c1.Y; y <= c2.Y; y++ { + ret = append(ret, &h.Coordinate{X: c1.X, Y: y}) + } + return ret + } else if c1.Y > c2.Y { + for y := c2.Y; y <= c1.Y; y++ { + ret = append(ret, &h.Coordinate{X: c1.X, Y: y}) + } + } + } else if c1.Y == c2.Y { + if c1.X < c2.X { + for x := c1.X; x <= c2.X; x++ { + ret = append(ret, &h.Coordinate{X: x, Y: c1.Y}) + } + } else if c1.X > c2.X { + for x := c2.X; x <= c1.X; x++ { + ret = append(ret, &h.Coordinate{X: x, Y: c1.Y}) + } + } + } + return ret +} diff --git a/2022/day14/problem b/2022/day14/problem new file mode 100644 index 0000000..9e8cabf --- /dev/null +++ b/2022/day14/problem @@ -0,0 +1,213 @@ +Advent of Code +br0xen (AoC++) 28* + +--- Day 14: Regolith Reservoir --- + + The distress signal leads you to a giant waterfall! Actually, hang on - the signal seems like it's coming from the + waterfall itself, and that doesn't make any sense. However, you do notice a little path that leads behind the waterfall. + + Correction: the distress signal leads you behind a giant waterfall! There seems to be a large cave system here, and the + signal definitely leads further inside. + + As you begin to make your way deeper underground, you feel the ground rumble for a moment. Sand begins pouring into the + cave! If you don't quickly figure out where the sand is going, you could quickly become trapped! + + Fortunately, your familiarity with analyzing the path of falling material will come in handy here. You scan a + two-dimensional vertical slice of the cave above you (your puzzle input) and discover that it is mostly air with + structures made of rock. + + Your scan traces the path of each solid rock structure and reports the x,y coordinates that form the shape of the path, + where x represents distance to the right and y represents distance down. Each path appears as a single line of text in + your scan. After the first point of each path, each point indicates the end of a straight horizontal or vertical line to + be drawn from the previous point. For example: + + 498,4 -> 498,6 -> 496,6 + 503,4 -> 502,4 -> 502,9 -> 494,9 + + This scan means that there are two paths of rock; the first path consists of two straight lines, and the second path + consists of three straight lines. (Specifically, the first path consists of a line of rock from 498,4 through 498,6 and + another line of rock from 498,6 through 496,6.) + + The sand is pouring into the cave from point 500,0. + + Drawing rock as #, air as ., and the source of the sand as +, this becomes: + + 4 5 5 + 9 0 0 + 4 0 3 + 0 ......+... + 1 .......... + 2 .......... + 3 .......... + 4 ....#...## + 5 ....#...#. + 6 ..###...#. + 7 ........#. + 8 ........#. + 9 #########. + + Sand is produced one unit at a time, and the next unit of sand is not produced until the previous unit of sand comes to + rest. A unit of sand is large enough to fill one tile of air in your scan. + + A unit of sand always falls down one step if possible. If the tile immediately below is blocked (by rock or sand), the + unit of sand attempts to instead move diagonally one step down and to the left. If that tile is blocked, the unit of + sand attempts to instead move diagonally one step down and to the right. Sand keeps moving as long as it is able to do + so, at each step trying to move down, then down-left, then down-right. If all three possible destinations are blocked, + the unit of sand comes to rest and no longer moves, at which point the next unit of sand is created back at the source. + + So, drawing sand that has come to rest as o, the first unit of sand simply falls straight down and then stops: + + ......+... + .......... + .......... + .......... + ....#...## + ....#...#. + ..###...#. + ........#. + ......o.#. + #########. + + The second unit of sand then falls straight down, lands on the first one, and then comes to rest to its left: + + ......+... + .......... + .......... + .......... + ....#...## + ....#...#. + ..###...#. + ........#. + .....oo.#. + #########. + + After a total of five units of sand have come to rest, they form this pattern: + + ......+... + .......... + .......... + .......... + ....#...## + ....#...#. + ..###...#. + ......o.#. + ....oooo#. + #########. + + After a total of 22 units of sand: + + ......+... + .......... + ......o... + .....ooo.. + ....#ooo## + ....#ooo#. + ..###ooo#. + ....oooo#. + ...ooooo#. + #########. + + Finally, only two more units of sand can possibly come to rest: + + ......+... + .......... + ......o... + .....ooo.. + ....#ooo## + ...o#ooo#. + ..###ooo#. + ....oooo#. + .o.ooooo#. + #########. + + Once all 24 units of sand shown above have come to rest, all further sand flows out the bottom, falling into the endless + void. Just for fun, the path any new sand takes before falling forever is shown here with ~: + + .......+... + .......~... + ......~o... + .....~ooo.. + ....~#ooo## + ...~o#ooo#. + ..~###ooo#. + ..~..oooo#. + .~o.ooooo#. + ~#########. + ~.......... + ~.......... + ~.......... + + Using your scan, simulate the falling sand. How many units of sand come to rest before sand starts flowing into the + abyss below? + + Your puzzle answer was 757. + +--- Part Two --- + + You realize you misread the scan. There isn't an endless void at the bottom of the scan - there's floor, and you're + standing on it! + + You don't have time to scan the floor, so assume the floor is an infinite horizontal line with a y coordinate equal to + two plus the highest y coordinate of any point in your scan. + + In the example above, the highest y coordinate of any point is 9, and so the floor is at y=11. (This is as if your scan + contained one extra rock path like -infinity,11 -> infinity,11.) With the added floor, the example above now looks like + this: + + ...........+........ + .................... + .................... + .................... + .........#...##..... + .........#...#...... + .......###...#...... + .............#...... + .............#...... + .....#########...... + .................... + <-- etc #################### etc --> + + To find somewhere safe to stand, you'll need to simulate falling sand until a unit of sand comes to rest at 500,0, + blocking the source entirely and stopping the flow of sand into the cave. In the example above, the situation finally + looks like this after 93 units of sand come to rest: + + ............o............ + ...........ooo........... + ..........ooooo.......... + .........ooooooo......... + ........oo#ooo##o........ + .......ooo#ooo#ooo....... + ......oo###ooo#oooo...... + .....oooo.oooo#ooooo..... + ....oooooooooo#oooooo.... + ...ooo#########ooooooo... + ..ooooo.......ooooooooo.. + ######################### + + Using your scan, simulate the falling sand until the source of the sand becomes blocked. How many units of sand come to + rest? + + Your puzzle answer was 24943. + + Both parts of this puzzle are complete! They provide two gold stars: ** + +References + + Visible links + . https://adventofcode.com/ + . https://adventofcode.com/2022/about + . https://adventofcode.com/2022/events + . https://adventofcode.com/2022/settings + . https://adventofcode.com/2022/auth/logout + . Advent of Code Supporter + https://adventofcode.com/2022/support + . https://adventofcode.com/2022 + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/support + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022/leaderboard + . https://adventofcode.com/2022/stats + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2018/day/17 + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/day/14/input diff --git a/2022/day14/testinput b/2022/day14/testinput new file mode 100644 index 0000000..4e87bb5 --- /dev/null +++ b/2022/day14/testinput @@ -0,0 +1,2 @@ +498,4 -> 498,6 -> 496,6 +503,4 -> 502,4 -> 502,9 -> 494,9 diff --git a/helpers/coordinate.go b/helpers/coordinate.go index 766e10d..df9b8b4 100644 --- a/helpers/coordinate.go +++ b/helpers/coordinate.go @@ -18,6 +18,27 @@ func (c Coordinate) Relative(t Coordinate) Coordinate { return Coordinate{X: c.X + t.X, Y: c.Y + t.Y} } +func (c *Coordinate) MoveSouth() { c.Y++ } +func (c *Coordinate) MoveNorth() { c.Y-- } +func (c *Coordinate) MoveEast() { c.X++ } +func (c *Coordinate) MoveWest() { c.X-- } +func (c *Coordinate) MoveNE() { + c.X++ + c.Y-- +} +func (c *Coordinate) MoveSE() { + c.X++ + c.Y++ +} +func (c *Coordinate) MoveSW() { + c.X-- + c.Y++ +} +func (c *Coordinate) MoveNW() { + c.X-- + c.Y-- +} + func (c Coordinate) North() Coordinate { return Coordinate{X: c.X, Y: c.Y - 1} } @@ -75,6 +96,9 @@ func CoordinateFromString(str string) *Coordinate { c := Coordinate{} r := strings.NewReader(str) _, err := fmt.Fscanf(r, "[%d, %d]", &c.X, &c.Y) + if err != nil { + _, err = fmt.Fscanf(r, "%d,%d", &c.X, &c.Y) + } if err != nil { panic(err) } diff --git a/helpers/coordinateByteMap.go b/helpers/coordinateByteMap.go index 3806d50..ea3a498 100644 --- a/helpers/coordinateByteMap.go +++ b/helpers/coordinateByteMap.go @@ -3,6 +3,7 @@ package aoc import ( "errors" "fmt" + "math" ) type CoordByteMap struct { @@ -14,11 +15,20 @@ type CoordByteMap struct { TLX, TLY int // The Bottom-Right-most X/Y BRX, BRY int + + // Options for the 'String' method + StringEmptyIsSpace bool + StringEmptyByte byte } func NewCoordByteMap() CoordByteMap { return CoordByteMap{ - Field: make(map[Coordinate]byte), + Field: make(map[Coordinate]byte), + TLX: math.MaxInt, + TLY: math.MaxInt, + BRX: math.MinInt, + BRY: math.MinInt, + StringEmptyByte: ' ', } } @@ -196,6 +206,9 @@ func (m *CoordByteMap) Put(pos Coordinate, val byte) { m.Height = m.BRY - m.TLY + 1 } } +func (m *CoordByteMap) Delete(pos Coordinate) { + delete(m.Field, pos) +} func (m *CoordByteMap) GrowNorth(size int, val byte) { tlY := m.TLY - 1 @@ -249,7 +262,11 @@ func (m CoordByteMap) String() string { var ret string for y := m.TLY; y <= m.BRY; y++ { for x := m.TLX; x <= m.BRX; x++ { - ret = ret + string(m.Field[Coordinate{X: x, Y: y}]) + if m.StringEmptyIsSpace { + ret = ret + string(m.Opt(Coordinate{X: x, Y: y}, m.StringEmptyByte)) + } else { + ret = ret + string(m.Field[Coordinate{X: x, Y: y}]) + } } ret = ret + "\n" }