advent2022

Advent of Code 2022 Solutions
git clone git://bsandro.tech/advent2022
Log | Files | Refs | README | LICENSE

commit 6bf87ae41fc0411df5cf2016c74b5fe63efc90c5
parent 67647abfdee54462a6c10a4d61a1840d32f9cc06
Author: bsandro <email@bsandro.tech>
Date:   Wed, 14 Dec 2022 07:47:49 +0000

Day 14 input parsing

Diffstat:
Aday14/input.txt | 144+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aday14/main.go | 158+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aday14/sample.txt | 2++
3 files changed, 304 insertions(+), 0 deletions(-)

diff --git a/day14/input.txt b/day14/input.txt @@ -0,0 +1,144 @@ +513,151 -> 513,155 -> 510,155 -> 510,161 -> 519,161 -> 519,155 -> 515,155 -> 515,151 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +488,36 -> 488,32 -> 488,36 -> 490,36 -> 490,26 -> 490,36 -> 492,36 -> 492,26 -> 492,36 -> 494,36 -> 494,32 -> 494,36 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +510,167 -> 514,167 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +486,120 -> 486,122 -> 482,122 -> 482,128 -> 491,128 -> 491,122 -> 490,122 -> 490,120 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +488,36 -> 488,32 -> 488,36 -> 490,36 -> 490,26 -> 490,36 -> 492,36 -> 492,26 -> 492,36 -> 494,36 -> 494,32 -> 494,36 +498,175 -> 498,176 -> 505,176 +493,39 -> 493,43 -> 489,43 -> 489,51 -> 501,51 -> 501,43 -> 496,43 -> 496,39 +489,79 -> 493,79 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +483,85 -> 487,85 +486,120 -> 486,122 -> 482,122 -> 482,128 -> 491,128 -> 491,122 -> 490,122 -> 490,120 +480,82 -> 484,82 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +494,144 -> 494,145 -> 504,145 -> 504,144 +486,54 -> 490,54 +488,36 -> 488,32 -> 488,36 -> 490,36 -> 490,26 -> 490,36 -> 492,36 -> 492,26 -> 492,36 -> 494,36 -> 494,32 -> 494,36 +492,60 -> 496,60 +493,39 -> 493,43 -> 489,43 -> 489,51 -> 501,51 -> 501,43 -> 496,43 -> 496,39 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +513,151 -> 513,155 -> 510,155 -> 510,161 -> 519,161 -> 519,155 -> 515,155 -> 515,151 +493,39 -> 493,43 -> 489,43 -> 489,51 -> 501,51 -> 501,43 -> 496,43 -> 496,39 +497,147 -> 497,148 -> 513,148 -> 513,147 +493,39 -> 493,43 -> 489,43 -> 489,51 -> 501,51 -> 501,43 -> 496,43 -> 496,39 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +488,36 -> 488,32 -> 488,36 -> 490,36 -> 490,26 -> 490,36 -> 492,36 -> 492,26 -> 492,36 -> 494,36 -> 494,32 -> 494,36 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +513,151 -> 513,155 -> 510,155 -> 510,161 -> 519,161 -> 519,155 -> 515,155 -> 515,151 +474,70 -> 478,70 +466,103 -> 466,104 -> 481,104 -> 481,103 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +471,85 -> 475,85 +490,131 -> 490,134 -> 482,134 -> 482,139 -> 501,139 -> 501,134 -> 495,134 -> 495,131 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +488,36 -> 488,32 -> 488,36 -> 490,36 -> 490,26 -> 490,36 -> 492,36 -> 492,26 -> 492,36 -> 494,36 -> 494,32 -> 494,36 +493,39 -> 493,43 -> 489,43 -> 489,51 -> 501,51 -> 501,43 -> 496,43 -> 496,39 +480,70 -> 484,70 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +468,70 -> 472,70 +480,60 -> 484,60 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +477,68 -> 481,68 +483,79 -> 487,79 +495,85 -> 499,85 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +493,39 -> 493,43 -> 489,43 -> 489,51 -> 501,51 -> 501,43 -> 496,43 -> 496,39 +486,120 -> 486,122 -> 482,122 -> 482,128 -> 491,128 -> 491,122 -> 490,122 -> 490,120 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +474,82 -> 478,82 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +490,131 -> 490,134 -> 482,134 -> 482,139 -> 501,139 -> 501,134 -> 495,134 -> 495,131 +495,63 -> 499,63 +489,63 -> 493,63 +477,79 -> 481,79 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +501,170 -> 505,170 +497,147 -> 497,148 -> 513,148 -> 513,147 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +489,85 -> 493,85 +488,36 -> 488,32 -> 488,36 -> 490,36 -> 490,26 -> 490,36 -> 492,36 -> 492,26 -> 492,36 -> 494,36 -> 494,32 -> 494,36 +490,131 -> 490,134 -> 482,134 -> 482,139 -> 501,139 -> 501,134 -> 495,134 -> 495,131 +490,131 -> 490,134 -> 482,134 -> 482,139 -> 501,139 -> 501,134 -> 495,134 -> 495,131 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +471,68 -> 475,68 +488,36 -> 488,32 -> 488,36 -> 490,36 -> 490,26 -> 490,36 -> 492,36 -> 492,26 -> 492,36 -> 494,36 -> 494,32 -> 494,36 +486,76 -> 490,76 +483,73 -> 487,73 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +513,151 -> 513,155 -> 510,155 -> 510,161 -> 519,161 -> 519,155 -> 515,155 -> 515,151 +466,103 -> 466,104 -> 481,104 -> 481,103 +504,167 -> 508,167 +507,170 -> 511,170 +488,36 -> 488,32 -> 488,36 -> 490,36 -> 490,26 -> 490,36 -> 492,36 -> 492,26 -> 492,36 -> 494,36 -> 494,32 -> 494,36 +486,120 -> 486,122 -> 482,122 -> 482,128 -> 491,128 -> 491,122 -> 490,122 -> 490,120 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +513,151 -> 513,155 -> 510,155 -> 510,161 -> 519,161 -> 519,155 -> 515,155 -> 515,151 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +507,164 -> 511,164 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +486,120 -> 486,122 -> 482,122 -> 482,128 -> 491,128 -> 491,122 -> 490,122 -> 490,120 +474,66 -> 478,66 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +486,120 -> 486,122 -> 482,122 -> 482,128 -> 491,128 -> 491,122 -> 490,122 -> 490,120 +488,36 -> 488,32 -> 488,36 -> 490,36 -> 490,26 -> 490,36 -> 492,36 -> 492,26 -> 492,36 -> 494,36 -> 494,32 -> 494,36 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +486,120 -> 486,122 -> 482,122 -> 482,128 -> 491,128 -> 491,122 -> 490,122 -> 490,120 +489,57 -> 493,57 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +488,36 -> 488,32 -> 488,36 -> 490,36 -> 490,26 -> 490,36 -> 492,36 -> 492,26 -> 492,36 -> 494,36 -> 494,32 -> 494,36 +480,76 -> 484,76 +488,36 -> 488,32 -> 488,36 -> 490,36 -> 490,26 -> 490,36 -> 492,36 -> 492,26 -> 492,36 -> 494,36 -> 494,32 -> 494,36 +477,63 -> 481,63 +492,82 -> 496,82 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +513,170 -> 517,170 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +490,131 -> 490,134 -> 482,134 -> 482,139 -> 501,139 -> 501,134 -> 495,134 -> 495,131 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +483,57 -> 487,57 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +498,175 -> 498,176 -> 505,176 +486,60 -> 490,60 +497,147 -> 497,148 -> 513,148 -> 513,147 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +513,151 -> 513,155 -> 510,155 -> 510,161 -> 519,161 -> 519,155 -> 515,155 -> 515,151 +486,82 -> 490,82 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +490,131 -> 490,134 -> 482,134 -> 482,139 -> 501,139 -> 501,134 -> 495,134 -> 495,131 +477,85 -> 481,85 +493,23 -> 493,21 -> 493,23 -> 495,23 -> 495,18 -> 495,23 -> 497,23 -> 497,19 -> 497,23 -> 499,23 -> 499,18 -> 499,23 -> 501,23 -> 501,18 -> 501,23 -> 503,23 -> 503,15 -> 503,23 -> 505,23 -> 505,16 -> 505,23 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +483,63 -> 487,63 +513,151 -> 513,155 -> 510,155 -> 510,161 -> 519,161 -> 519,155 -> 515,155 -> 515,151 +466,103 -> 466,104 -> 481,104 -> 481,103 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +463,98 -> 463,97 -> 463,98 -> 465,98 -> 465,94 -> 465,98 -> 467,98 -> 467,94 -> 467,98 -> 469,98 -> 469,88 -> 469,98 -> 471,98 -> 471,90 -> 471,98 -> 473,98 -> 473,97 -> 473,98 -> 475,98 -> 475,95 -> 475,98 +494,144 -> 494,145 -> 504,145 -> 504,144 +493,39 -> 493,43 -> 489,43 -> 489,51 -> 501,51 -> 501,43 -> 496,43 -> 496,39 +490,131 -> 490,134 -> 482,134 -> 482,139 -> 501,139 -> 501,134 -> 495,134 -> 495,131 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 +494,144 -> 494,145 -> 504,145 -> 504,144 +476,117 -> 476,114 -> 476,117 -> 478,117 -> 478,110 -> 478,117 -> 480,117 -> 480,110 -> 480,117 -> 482,117 -> 482,114 -> 482,117 -> 484,117 -> 484,113 -> 484,117 -> 486,117 -> 486,113 -> 486,117 diff --git a/day14/main.go b/day14/main.go @@ -0,0 +1,158 @@ +package main + +import ( + "bufio" + "fmt" + "log" + "os" + "strconv" + "strings" +) + +type Pos struct { + x, y int +} + +type Shape []Pos +type Shapes []Shape + +func (ss Shapes) GetMinX() int { + x := -1 + for _, s := range ss { + for _, e := range s { + if x == -1 { + x = e.x + } + if e.x < x { + x = e.x + } + } + } + return x +} +func (ss Shapes) GetMaxX() int { + x := 0 + for _, s := range ss { + for _, e := range s { + if e.x > x { + x = e.x + } + } + } + return x +} +func (ss Shapes) GetMaxY() int { + y := 0 + for _, s := range ss { + for _, e := range s { + if e.y > y { + y = e.y + } + } + } + return y +} + +type Grid [][]byte + +func (grid Grid) String() string { + var s string + for y := 0; y < len(grid); y++ { + for x := 0; x < len(grid[y]); x++ { + switch grid[y][x] { + case 0: + s += "." + case 1: + s += "#" + case 2: + s += "O" + default: + s += " " + } + } + s += "\n" + } + return s +} +func (grid *Grid) Init(width, height int) { + *grid = make(Grid, height) + for y := 0; y < height; y++ { + (*grid)[y] = make([]byte, width) + } +} +func (grid *Grid) AddShape(s Shape, offset int) { + for i := 1; i < len(s); i++ { + x1, y1 := s[i-1].x-offset, s[i-1].y + x2, y2 := s[i].x-offset, s[i].y + if x1 > x2 { + x1, x2 = x2, x1 + } + if y1 > y2 { + y1, y2 = y2, y1 + } + for x := x1; x <= x2; x++ { + for y := y1; y <= y2; y++ { + (*grid)[y][x] = 1 + } + } + } +} + +func main() { + if len(os.Args) > 1 { + day14(os.Args[1]) + } else if len(os.Args) == 1 { + fmt.Printf("usage: %s inputfile.txt\n", os.Args[0]) + } else { + fmt.Println("No input data") + } +} + +func day14(input_file string) { + fmt.Printf("day 14 input filename: %s\n", input_file) + input, err := os.Open(input_file) + if err != nil { + log.Fatal(err) + } + defer input.Close() + scanner := bufio.NewScanner(input) + var shapes Shapes + for scanner.Scan() { + in := scanner.Text() + edges := strings.Split(in, " -> ") + var s Shape + for _, edge := range edges { + var p Pos + xs, ys, found := strings.Cut(edge, ",") + if !found { + log.Fatal("invalid input") + } + p.x, err = strconv.Atoi(xs) + if err != nil { + log.Fatal(err) + } + p.y, err = strconv.Atoi(ys) + if err != nil { + log.Fatal(err) + } + s = append(s, p) + } + if len(s) <= 1 { + log.Fatal("invalid shape", s) + } + shapes = append(shapes, s) + } + if err = scanner.Err(); err != nil { + log.Fatal(err) + } + + height := shapes.GetMaxY() + 1 + offsetX := shapes.GetMinX() + width := shapes.GetMaxX() - offsetX + 1 + var grid Grid + grid.Init(width, height) + for _, s := range shapes { + grid.AddShape(s, offsetX) + } + fmt.Printf("%v\n", grid) +} diff --git a/day14/sample.txt b/day14/sample.txt @@ -0,0 +1,2 @@ +498,4 -> 498,6 -> 496,6 +503,4 -> 502,4 -> 502,9 -> 494,9