~ihabunek/aoc2022

dca3d571f1b2bdc3832b882aad94dab8980fd9d3 — Ivan Habunek 1 year, 8 months ago 74c2954 master
Day 14
4 files changed, 343 insertions(+), 3 deletions(-)

A input/day14.example.txt
A input/day14.txt
M src/aoc2022.gleam
A src/aoc2022/day14.gleam
A input/day14.example.txt => input/day14.example.txt +2 -0
@@ 0,0 1,2 @@
498,4 -> 498,6 -> 496,6
503,4 -> 502,4 -> 502,9 -> 494,9
\ No newline at end of file

A input/day14.txt => input/day14.txt +141 -0
@@ 0,0 1,141 @@
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
549,140 -> 549,143 -> 541,143 -> 541,147 -> 555,147 -> 555,143 -> 554,143 -> 554,140
519,98 -> 523,98
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
511,50 -> 511,51 -> 525,51 -> 525,50
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
555,150 -> 555,154 -> 550,154 -> 550,157 -> 561,157 -> 561,154 -> 557,154 -> 557,150
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
520,56 -> 525,56
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
517,58 -> 522,58
513,94 -> 517,94
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
498,70 -> 503,70
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
519,94 -> 523,94
515,30 -> 520,30
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
524,58 -> 529,58
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
507,98 -> 511,98
549,140 -> 549,143 -> 541,143 -> 541,147 -> 555,147 -> 555,143 -> 554,143 -> 554,140
527,56 -> 532,56
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
522,96 -> 526,96
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
549,140 -> 549,143 -> 541,143 -> 541,147 -> 555,147 -> 555,143 -> 554,143 -> 554,140
535,60 -> 540,60
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
511,50 -> 511,51 -> 525,51 -> 525,50
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
555,150 -> 555,154 -> 550,154 -> 550,157 -> 561,157 -> 561,154 -> 557,154 -> 557,150
533,114 -> 533,118 -> 525,118 -> 525,124 -> 541,124 -> 541,118 -> 538,118 -> 538,114
549,140 -> 549,143 -> 541,143 -> 541,147 -> 555,147 -> 555,143 -> 554,143 -> 554,140
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
513,98 -> 517,98
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
555,150 -> 555,154 -> 550,154 -> 550,157 -> 561,157 -> 561,154 -> 557,154 -> 557,150
505,33 -> 510,33
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
498,13 -> 498,16 -> 492,16 -> 492,19 -> 506,19 -> 506,16 -> 501,16 -> 501,13
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
533,114 -> 533,118 -> 525,118 -> 525,124 -> 541,124 -> 541,118 -> 538,118 -> 538,114
498,13 -> 498,16 -> 492,16 -> 492,19 -> 506,19 -> 506,16 -> 501,16 -> 501,13
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
549,140 -> 549,143 -> 541,143 -> 541,147 -> 555,147 -> 555,143 -> 554,143 -> 554,140
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
549,140 -> 549,143 -> 541,143 -> 541,147 -> 555,147 -> 555,143 -> 554,143 -> 554,140
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
533,114 -> 533,118 -> 525,118 -> 525,124 -> 541,124 -> 541,118 -> 538,118 -> 538,114
498,13 -> 498,16 -> 492,16 -> 492,19 -> 506,19 -> 506,16 -> 501,16 -> 501,13
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
503,76 -> 513,76 -> 513,75
498,13 -> 498,16 -> 492,16 -> 492,19 -> 506,19 -> 506,16 -> 501,16 -> 501,13
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
533,114 -> 533,118 -> 525,118 -> 525,124 -> 541,124 -> 541,118 -> 538,118 -> 538,114
521,60 -> 526,60
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
516,92 -> 520,92
498,13 -> 498,16 -> 492,16 -> 492,19 -> 506,19 -> 506,16 -> 501,16 -> 501,13
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
512,33 -> 517,33
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
528,60 -> 533,60
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
498,13 -> 498,16 -> 492,16 -> 492,19 -> 506,19 -> 506,16 -> 501,16 -> 501,13
503,76 -> 513,76 -> 513,75
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
498,24 -> 513,24
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
525,98 -> 529,98
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
555,150 -> 555,154 -> 550,154 -> 550,157 -> 561,157 -> 561,154 -> 557,154 -> 557,150
511,27 -> 516,27
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
514,60 -> 519,60
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
523,54 -> 528,54
511,50 -> 511,51 -> 525,51 -> 525,50
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
549,140 -> 549,143 -> 541,143 -> 541,147 -> 555,147 -> 555,143 -> 554,143 -> 554,140
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
533,114 -> 533,118 -> 525,118 -> 525,124 -> 541,124 -> 541,118 -> 538,118 -> 538,114
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
508,30 -> 513,30
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
497,66 -> 502,66
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
531,58 -> 536,58
519,33 -> 524,33
555,150 -> 555,154 -> 550,154 -> 550,157 -> 561,157 -> 561,154 -> 557,154 -> 557,150
555,150 -> 555,154 -> 550,154 -> 550,157 -> 561,157 -> 561,154 -> 557,154 -> 557,150
501,63 -> 511,63
491,70 -> 496,70
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
516,96 -> 520,96
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
505,70 -> 510,70
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
501,68 -> 506,68
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
510,96 -> 514,96
533,114 -> 533,118 -> 525,118 -> 525,124 -> 541,124 -> 541,118 -> 538,118 -> 538,114
524,111 -> 524,109 -> 524,111 -> 526,111 -> 526,103 -> 526,111 -> 528,111 -> 528,110 -> 528,111 -> 530,111 -> 530,108 -> 530,111 -> 532,111 -> 532,108 -> 532,111 -> 534,111 -> 534,107 -> 534,111
498,13 -> 498,16 -> 492,16 -> 492,19 -> 506,19 -> 506,16 -> 501,16 -> 501,13
532,137 -> 532,130 -> 532,137 -> 534,137 -> 534,127 -> 534,137 -> 536,137 -> 536,135 -> 536,137 -> 538,137 -> 538,127 -> 538,137 -> 540,137 -> 540,132 -> 540,137 -> 542,137 -> 542,135 -> 542,137 -> 544,137 -> 544,127 -> 544,137 -> 546,137 -> 546,131 -> 546,137 -> 548,137 -> 548,134 -> 548,137 -> 550,137 -> 550,133 -> 550,137
555,150 -> 555,154 -> 550,154 -> 550,157 -> 561,157 -> 561,154 -> 557,154 -> 557,150
494,68 -> 499,68
533,114 -> 533,118 -> 525,118 -> 525,124 -> 541,124 -> 541,118 -> 538,118 -> 538,114
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
506,46 -> 506,43 -> 506,46 -> 508,46 -> 508,37 -> 508,46 -> 510,46 -> 510,40 -> 510,46 -> 512,46 -> 512,45 -> 512,46 -> 514,46 -> 514,38 -> 514,46
509,89 -> 509,80 -> 509,89 -> 511,89 -> 511,84 -> 511,89 -> 513,89 -> 513,88 -> 513,89 -> 515,89 -> 515,84 -> 515,89 -> 517,89 -> 517,88 -> 517,89
\ No newline at end of file

M src/aoc2022.gleam => src/aoc2022.gleam +3 -3
@@ 1,9 1,9 @@
import gleam/io
import aoc2022/day12
import aoc2022/day14

pub fn main() {
  io.print("Part 1: ")
  io.debug(day12.part1())
  io.debug(day14.part1())
  io.print("Part 2: ")
  io.debug(day12.part2())
  io.debug(day14.part2())
}

A src/aoc2022/day14.gleam => src/aoc2022/day14.gleam +197 -0
@@ 0,0 1,197 @@
//// --- Day 14: Regolith Reservoir ---
//// https://adventofcode.com/2022/day/14

import aoc2022/ncurses
import aoc2022/utils
import gleam/int
import gleam/list
import gleam/set.{Set}
import gleam/string

type Pos {
  Pos(x: Int, y: Int)
}

type Bounds {
  Bounds(min_x: Int, min_y: Int, max_x: Int, max_y: Int)
}

type Map =
  Set(Pos)

pub fn part1() {
  let map = parse_input()
  let bounds = bounds(map)
  //init_curses()
  //draw_map(map, bounds)
  let result = play1(map, bounds)
  //utils.sleep(2000)
  //ncurses.n_end()
  result
}

pub fn part2() {
  let map = parse_input()
  let bounds = bounds(map)
  //init_curses()
  //draw_map(map, bounds)
  //draw_floor(bounds)
  let result = play2(map, bounds)
  //utils.sleep(3000)
  //ncurses.n_end()
  result
}

fn play1(map: Map, bounds: Bounds) {
  do_play1(map, bounds, 0)
}

fn do_play1(map, bounds, count) -> Int {
  case drop(map, bounds) {
    Ok(pos) -> {
      //draw_char(pos, bounds, "o")
      //utils.sleep(10)
      let map = set.insert(map, pos)
      do_play1(map, bounds, count + 1)
    }
    Error(_) -> count
  }
}

fn play2(map: Map, bounds: Bounds) {
  do_play2(map, bounds, 0)
}

fn do_play2(map, bounds, count) -> Int {
  let pos = case drop(map, bounds) {
    Ok(pos) -> pos
    Error(pos) -> pos
  }

  //draw_char(pos, bounds, "o")
  //utils.sleep(1)
  case pos.x == 500 && pos.y == 0 {
    True -> count + 1
    False -> {
      let map = set.insert(map, pos)
      do_play2(map, bounds, count + 1)
    }
  }
}

// Returns Error(pos) if sand fell out of bounds (part1) or is resting on the
// floor (part 2).
fn drop(map, bounds) -> Result(Pos, Pos) {
  do_drop(map, bounds, Pos(500, 0))
}

fn do_drop(map, bounds, pos) -> Result(Pos, Pos) {
  case pos.y <= bounds.max_y {
    True ->
      case step(map, pos) {
        Ok(next) -> do_drop(map, bounds, next)
        Error(Nil) -> Ok(pos)
      }
    // Fell of the bottom
    False -> Error(pos)
  }
}

// Returns Error if sand is at rest
fn step(map, pos) -> Result(Pos, Nil) {
  let candidates = [
    Pos(pos.x, pos.y + 1),
    Pos(pos.x - 1, pos.y + 1),
    Pos(pos.x + 1, pos.y + 1),
  ]

  candidates
  |> list.find(fn(next) { !set.contains(map, next) })
}

// -----------------------------------------------------------------------------
// Curses
// -----------------------------------------------------------------------------

const x_offset = 180

const y_offset = 15

fn init_curses() {
  ncurses.n_begin()
  ncurses.curs_set(0)
  ncurses.start_color()
  ncurses.init_pair(1, "white", "blue")
  ncurses.init_pair(2, "green", "black")
}

fn draw_map(map: Map, bounds) {
  list.each(set.to_list(map), fn(pos) { draw_char(pos, bounds, "#") })
  ncurses.refresh()
}

fn draw_floor(bounds: Bounds) {
  let y = bounds.max_y + 2

  list.range(bounds.min_x - x_offset, bounds.max_x + x_offset)
  |> list.each(fn(x) { draw_char(Pos(x, y), bounds, "=") })
}

fn bounds(map: Map) -> Bounds {
  let map = set.to_list(map)
  let xs = list.map(map, fn(pos) { pos.x })
  let ys = list.map(map, fn(pos) { pos.y })
  let min_x = utils.assert_ok(list.reduce(xs, int.min))
  let max_x = utils.assert_ok(list.reduce(xs, int.max))
  let min_y = utils.assert_ok(list.reduce(ys, int.min))
  let max_y = utils.assert_ok(list.reduce(ys, int.max))
  Bounds(min_x, min_y, max_x, max_y)
}

fn draw_char(pos: Pos, bounds: Bounds, char: String) {
  let x = pos.x - bounds.min_x + x_offset
  let y = pos.y - bounds.min_y + y_offset
  ncurses.mvprintw(y, x, char)
  ncurses.refresh()
}

// -----------------------------------------------------------------------------
// Input Parsing
// -----------------------------------------------------------------------------

fn parse_input() -> Map {
  "day14.txt"
  //"day14.example.txt"
  |> utils.read_input
  |> string.split("\n")
  |> list.flat_map(fn(line) {
    string.split(line, " -> ")
    |> list.map(parse_pos)
    |> list.window(2)
  })
  |> list.flat_map(pos_range)
  |> set.from_list
}

fn parse_pos(pos) {
  let [x, y] =
    string.split(pos, ",")
    |> list.map(utils.parse_int)

  Pos(x, y)
}

fn pos_range(window) {
  let [pos1, pos2] = window
  let same_x = pos1.x == pos2.x
  let same_y = pos1.y == pos2.y

  case Nil {
    _ if same_x ->
      list.range(pos1.y, pos2.y)
      |> list.map(Pos(pos1.x, _))
    _ if same_y ->
      list.range(pos1.x, pos2.x)
      |> list.map(Pos(_, pos1.y))
  }
}