Compare commits

...

5 Commits

Author SHA1 Message Date
ryan
61e3520ede parse day 14 grid
haven't implemented the falling sand yet, but theres a cool expect test
that draws the grid
2023-10-31 17:04:20 -07:00
ryan
98f47654f8 change Vec2 implementation to a record type 2023-10-31 15:57:13 -07:00
ryan
88acb381f1 move Grid into its own file 2023-10-31 15:57:11 -07:00
ryan
1d60878428 add init_grid func 2023-10-31 14:43:12 -07:00
ryan
63bad67c1b create angstrom wrapper in Utils for int parser
and other common parsers for the future
2023-10-31 14:40:22 -07:00
10 changed files with 346 additions and 88 deletions

148
inputs/day14.tt Normal file
View File

@ -0,0 +1,148 @@
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
502,32 -> 507,32
522,47 -> 522,43 -> 522,47 -> 524,47 -> 524,41 -> 524,47 -> 526,47 -> 526,39 -> 526,47 -> 528,47 -> 528,39 -> 528,47
516,32 -> 521,32
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
512,30 -> 517,30
522,47 -> 522,43 -> 522,47 -> 524,47 -> 524,41 -> 524,47 -> 526,47 -> 526,39 -> 526,47 -> 528,47 -> 528,39 -> 528,47
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
520,130 -> 520,133 -> 515,133 -> 515,138 -> 533,138 -> 533,133 -> 525,133 -> 525,130
506,34 -> 511,34
529,112 -> 529,116 -> 526,116 -> 526,122 -> 541,122 -> 541,116 -> 535,116 -> 535,112
498,13 -> 498,15 -> 492,15 -> 492,23 -> 506,23 -> 506,15 -> 501,15 -> 501,13
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
523,63 -> 523,66 -> 515,66 -> 515,71 -> 529,71 -> 529,66 -> 528,66 -> 528,63
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
512,173 -> 517,173
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
498,13 -> 498,15 -> 492,15 -> 492,23 -> 506,23 -> 506,15 -> 501,15 -> 501,13
545,94 -> 550,94
539,100 -> 544,100
522,47 -> 522,43 -> 522,47 -> 524,47 -> 524,41 -> 524,47 -> 526,47 -> 526,39 -> 526,47 -> 528,47 -> 528,39 -> 528,47
529,112 -> 529,116 -> 526,116 -> 526,122 -> 541,122 -> 541,116 -> 535,116 -> 535,112
553,100 -> 558,100
501,170 -> 506,170
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
498,13 -> 498,15 -> 492,15 -> 492,23 -> 506,23 -> 506,15 -> 501,15 -> 501,13
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
498,13 -> 498,15 -> 492,15 -> 492,23 -> 506,23 -> 506,15 -> 501,15 -> 501,13
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
546,100 -> 551,100
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
542,97 -> 547,97
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
535,97 -> 540,97
533,108 -> 533,109 -> 538,109 -> 538,108
522,47 -> 522,43 -> 522,47 -> 524,47 -> 524,41 -> 524,47 -> 526,47 -> 526,39 -> 526,47 -> 528,47 -> 528,39 -> 528,47
509,32 -> 514,32
513,34 -> 518,34
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
520,130 -> 520,133 -> 515,133 -> 515,138 -> 533,138 -> 533,133 -> 525,133 -> 525,130
507,164 -> 512,164
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
557,103 -> 562,103
538,94 -> 543,94
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
520,130 -> 520,133 -> 515,133 -> 515,138 -> 533,138 -> 533,133 -> 525,133 -> 525,130
520,130 -> 520,133 -> 515,133 -> 515,138 -> 533,138 -> 533,133 -> 525,133 -> 525,130
498,13 -> 498,15 -> 492,15 -> 492,23 -> 506,23 -> 506,15 -> 501,15 -> 501,13
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
523,63 -> 523,66 -> 515,66 -> 515,71 -> 529,71 -> 529,66 -> 528,66 -> 528,63
501,28 -> 506,28
505,173 -> 510,173
531,87 -> 531,88 -> 543,88
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
520,130 -> 520,133 -> 515,133 -> 515,138 -> 533,138 -> 533,133 -> 525,133 -> 525,130
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
524,126 -> 524,127 -> 528,127 -> 528,126
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
523,63 -> 523,66 -> 515,66 -> 515,71 -> 529,71 -> 529,66 -> 528,66 -> 528,63
508,28 -> 513,28
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
523,63 -> 523,66 -> 515,66 -> 515,71 -> 529,71 -> 529,66 -> 528,66 -> 528,63
511,167 -> 516,167
549,97 -> 554,97
541,91 -> 546,91
522,47 -> 522,43 -> 522,47 -> 524,47 -> 524,41 -> 524,47 -> 526,47 -> 526,39 -> 526,47 -> 528,47 -> 528,39 -> 528,47
522,47 -> 522,43 -> 522,47 -> 524,47 -> 524,41 -> 524,47 -> 526,47 -> 526,39 -> 526,47 -> 528,47 -> 528,39 -> 528,47
520,34 -> 525,34
522,47 -> 522,43 -> 522,47 -> 524,47 -> 524,41 -> 524,47 -> 526,47 -> 526,39 -> 526,47 -> 528,47 -> 528,39 -> 528,47
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
522,47 -> 522,43 -> 522,47 -> 524,47 -> 524,41 -> 524,47 -> 526,47 -> 526,39 -> 526,47 -> 528,47 -> 528,39 -> 528,47
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
505,30 -> 510,30
543,103 -> 548,103
510,146 -> 515,146
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
498,173 -> 503,173
498,13 -> 498,15 -> 492,15 -> 492,23 -> 506,23 -> 506,15 -> 501,15 -> 501,13
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
523,63 -> 523,66 -> 515,66 -> 515,71 -> 529,71 -> 529,66 -> 528,66 -> 528,63
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
522,47 -> 522,43 -> 522,47 -> 524,47 -> 524,41 -> 524,47 -> 526,47 -> 526,39 -> 526,47 -> 528,47 -> 528,39 -> 528,47
498,13 -> 498,15 -> 492,15 -> 492,23 -> 506,23 -> 506,15 -> 501,15 -> 501,13
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
533,108 -> 533,109 -> 538,109 -> 538,108
517,146 -> 522,146
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
513,144 -> 518,144
515,170 -> 520,170
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
520,130 -> 520,133 -> 515,133 -> 515,138 -> 533,138 -> 533,133 -> 525,133 -> 525,130
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
523,63 -> 523,66 -> 515,66 -> 515,71 -> 529,71 -> 529,66 -> 528,66 -> 528,63
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
519,173 -> 524,173
532,100 -> 537,100
524,126 -> 524,127 -> 528,127 -> 528,126
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
529,112 -> 529,116 -> 526,116 -> 526,122 -> 541,122 -> 541,116 -> 535,116 -> 535,112
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
521,148 -> 526,148
504,167 -> 509,167
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
529,112 -> 529,116 -> 526,116 -> 526,122 -> 541,122 -> 541,116 -> 535,116 -> 535,112
520,130 -> 520,133 -> 515,133 -> 515,138 -> 533,138 -> 533,133 -> 525,133 -> 525,130
514,148 -> 519,148
510,141 -> 515,141
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
533,108 -> 533,109 -> 538,109 -> 538,108
524,126 -> 524,127 -> 528,127 -> 528,126
550,103 -> 555,103
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
529,103 -> 534,103
504,26 -> 509,26
529,112 -> 529,116 -> 526,116 -> 526,122 -> 541,122 -> 541,116 -> 535,116 -> 535,112
508,170 -> 513,170
523,63 -> 523,66 -> 515,66 -> 515,71 -> 529,71 -> 529,66 -> 528,66 -> 528,63
499,34 -> 504,34
522,47 -> 522,43 -> 522,47 -> 524,47 -> 524,41 -> 524,47 -> 526,47 -> 526,39 -> 526,47 -> 528,47 -> 528,39 -> 528,47
529,112 -> 529,116 -> 526,116 -> 526,122 -> 541,122 -> 541,116 -> 535,116 -> 535,112
495,32 -> 500,32
507,148 -> 512,148
515,60 -> 515,52 -> 515,60 -> 517,60 -> 517,55 -> 517,60 -> 519,60 -> 519,50 -> 519,60 -> 521,60 -> 521,56 -> 521,60 -> 523,60 -> 523,53 -> 523,60 -> 525,60 -> 525,53 -> 525,60
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
531,87 -> 531,88 -> 543,88
536,103 -> 541,103
501,161 -> 501,152 -> 501,161 -> 503,161 -> 503,157 -> 503,161 -> 505,161 -> 505,155 -> 505,161 -> 507,161 -> 507,154 -> 507,161 -> 509,161 -> 509,155 -> 509,161
522,84 -> 522,76 -> 522,84 -> 524,84 -> 524,75 -> 524,84 -> 526,84 -> 526,81 -> 526,84 -> 528,84 -> 528,74 -> 528,84 -> 530,84 -> 530,79 -> 530,84 -> 532,84 -> 532,77 -> 532,84 -> 534,84 -> 534,78 -> 534,84 -> 536,84 -> 536,80 -> 536,84
522,47 -> 522,43 -> 522,47 -> 524,47 -> 524,41 -> 524,47 -> 526,47 -> 526,39 -> 526,47 -> 528,47 -> 528,39 -> 528,47
498,30 -> 503,30
492,34 -> 497,34
529,112 -> 529,116 -> 526,116 -> 526,122 -> 541,122 -> 541,116 -> 535,116 -> 535,112

View File

@ -15,10 +15,10 @@ let parse_grid start_anywhere =
let unvisited = ref [] in
let grid =
Utils.lines_of_input 12
|> Vec2.parse_grid (fun char -> { char; visited = false; distance = infinity })
|> Grid.of_lines (fun char -> { char; visited = false; distance = infinity })
in
Vec2.iter_grid grid (fun pos ->
let n = Vec2.at_e grid pos in
Grid.iter grid (fun pos ->
let n = Grid.at_e grid pos in
match n.char with
| 'E' -> e := pos
| 'S' ->
@ -42,11 +42,11 @@ let reachable f t =
;;
let rec path grid goal current unvisited =
let current_node = Vec2.at_e grid current in
let current_node = Grid.at_e grid current in
Vec2.directions
|> List.map (fun dir -> Vec2.(current + dir))
|> List.iter (fun neighbor ->
match Vec2.at grid neighbor with
match Grid.at grid neighbor with
| Some node when (not node.visited) && reachable current_node.char node.char ->
let new_distance = current_node.distance + 1 in
if new_distance < node.distance then node.distance <- new_distance;
@ -57,12 +57,12 @@ let rec path grid goal current unvisited =
unvisited
:= List.sort
(fun a b ->
let a = Vec2.at_e grid a in
let b = Vec2.at_e grid b in
let a = Grid.at_e grid a in
let b = Grid.at_e grid b in
a.distance - b.distance)
!unvisited;
match !unvisited with
| shortest :: _ when Vec2.(shortest = goal) -> Vec2.at grid shortest
| shortest :: _ when Vec2.(shortest = goal) -> Grid.at grid shortest
| shortest :: rest -> path grid goal shortest @@ ref rest
| [] -> None
;;

View File

@ -7,13 +7,8 @@ module Packet = struct
[@@deriving show { with_path = false }]
let of_str line =
let open Angstrom in
let int =
take_while1 (function
| '0' .. '9' -> true
| _ -> false)
>>= fun s -> return @@ I (int_of_string s) <?> "int"
in
let open Utils.Parse in
let int = int >>= fun i -> return @@ I i in
let packet =
fix (fun packet ->
let lb, delimited, rb = char '[', sep_by (char ','), char ']' in

48
src/day14.ml Normal file
View File

@ -0,0 +1,48 @@
open Containers
type tile =
| Empty
| Rock
| Sand
[@@deriving show]
let parse_line line =
let open Utils.Parse in
let vec = Vec2.of_tuple <$> both int (char ',' *> int) in
let vec_list = sep_by (string " -> ") vec in
Result.get_or_failwith @@ parse_string ~consume:All vec_list line
;;
let draw_rocks grid points =
let open Grid in
let _ =
points
|> List.reduce (fun a b ->
iter_region grid a b (fun pos -> grid.%(pos) <- Rock);
b)
in
()
;;
let%expect_test "Day 14 example" =
let grid = Grid.init ~width:20 ~height:10 (fun _ -> Empty) in
[ "8,4 -> 8,6 -> 6,6"; "13,4 -> 12,4 -> 12,9 -> 4,9" ]
|> List.iter (fun line -> parse_line line |> draw_rocks grid);
Printf.printf "%s"
@@ Grid.draw grid (function
| Empty -> '.'
| Rock -> '#'
| Sand -> 'o');
[%expect
{|
....................
....................
....................
....................
........#...##......
........#...#.......
......###...#.......
............#.......
............#.......
....#########....... |}]
;;

View File

@ -1,17 +1,17 @@
open Containers
let parse_grid () =
Vec2.parse_grid Fun.(Char.to_string %> int_of_string) @@ Utils.lines_of_input 8
Grid.of_lines Fun.(Char.to_string %> int_of_string) @@ Utils.lines_of_input 8
;;
let part1 () =
let grid = parse_grid () in
let num_visible = ref 0 in
Vec2.iter_grid grid (fun start ->
let start_height = Option.get_exn_or "unreachable" @@ Vec2.at grid start in
Grid.iter grid (fun start ->
let start_height = Option.get_exn_or "unreachable" @@ Grid.at grid start in
let rec walk_shorter_trees start step =
let next = Vec2.(start + step) in
match Vec2.at grid next with
match Grid.at grid next with
| Some height when height < start_height -> walk_shorter_trees next step
| opt -> opt
in
@ -28,11 +28,11 @@ let part1 () =
let part2 () =
let grid = parse_grid () in
let best_score = ref 0 in
Vec2.iter_grid grid (fun start ->
let start_height = Option.get_exn_or "unreachable" @@ Vec2.at grid start in
Grid.iter grid (fun start ->
let start_height = Option.get_exn_or "unreachable" @@ Grid.at grid start in
let rec trees_in_view start in_view step =
let next = Vec2.(start + step) in
match Vec2.at grid next with
match Grid.at grid next with
| Some height when height < start_height -> trees_in_view next (in_view + 1) step
| Some _ -> in_view + 1
| None -> in_view

90
src/grid.ml Normal file
View File

@ -0,0 +1,90 @@
open Containers
type 'a t =
{ width : int
; height : int
; items : 'a array
}
[@@deriving show]
let vec2_of_idx ~width ~idx =
let y = idx / width in
let x = idx mod width in
Vec2.of_tuple (x, y)
;;
let idx_of_vec2 width vec = Vec2.(Int.((width * vec.y) + vec.x))
let in_bounds grid point =
let x, y = Vec2.to_tuple point in
x >= 0 && x < grid.width && y >= 0 && y < grid.height
;;
let at grid point =
if in_bounds grid point
then Array.get_safe grid.items @@ idx_of_vec2 grid.width point
else None
;;
let at_e (grid : 'a t) (point : Vec2.t) =
Option.get_exn_or "point out of bounds!" @@ at grid point
;;
let set_e grid point item = Array.set grid.items (idx_of_vec2 grid.width point) item
let ( .%() ) = at_e
let ( .%()<- ) = set_e
let find (grid : 'a t) pred =
let open Option.Infix in
let* idx, item = Array.find_idx pred grid.items in
Some (vec2_of_idx ~width:grid.width ~idx, item)
;;
let init ~width ~height init =
{ width
; height
; items = Array.init (width * height) (fun idx -> init @@ vec2_of_idx ~width ~idx)
}
;;
let of_lines parse_char lines : 'a t =
match lines with
| first_line :: _ ->
let width = String.length first_line in
let height = List.length lines in
let yeet =
lines
|> List.map String.to_list
|> List.flatten
|> List.map parse_char
|> Array.of_list
in
{ width; height; items = yeet }
| _ -> failwith "somethin fucd up"
;;
let iter_region grid a b callback =
let open Vec2 in
for y = min a.y b.y to max a.y b.y do
for x = min a.x b.x to max a.x b.x do
let pos = { x; y } in
if in_bounds grid pos then callback pos
done
done
;;
let iter grid callback =
let a = Vec2.of_tuple (0, 0) in
let b = Vec2.of_tuple (grid.width - 1, grid.height - 1) in
iter_region grid a b callback
;;
let draw grid printer =
let str = ref [] in
iter grid (fun point ->
let item = grid.%(point) in
let char = printer item in
str := !str @ [ char ];
if point.x = grid.width - 1 then str := !str @ [ '\n' ]);
String.of_list !str
;;

13
src/grid.mli Normal file
View File

@ -0,0 +1,13 @@
type 'a t [@@deriving show]
val at : 'a t -> Vec2.t -> 'a option
val at_e : 'a t -> Vec2.t -> 'a
val set_e : 'a t -> Vec2.t -> 'a -> unit
val ( .%() ) : 'a t -> Vec2.t -> 'a
val ( .%()<- ) : 'a t -> Vec2.t -> 'a -> unit
val init : width:int -> height:int -> (Vec2.t -> 'a) -> 'a t
val of_lines : (char -> 'a) -> string list -> 'a t
val find : 'a t -> ('a -> bool) -> (Vec2.t * 'a) option
val iter_region : 'a t -> Vec2.t -> Vec2.t -> (Vec2.t -> unit) -> unit
val iter : 'a t -> (Vec2.t -> unit) -> unit
val draw : 'a t -> ('a -> char) -> string

View File

@ -9,3 +9,15 @@ let lines_of_input day =
let path = Printf.sprintf "%s/day%d.tt" base_path day in
IO.(with_in path read_lines_l)
;;
module Parse = struct
include Angstrom
let int =
take_while1 (function
| '0' .. '9' -> true
| _ -> false)
>>| int_of_string
<?> "int"
;;
end

View File

@ -1,65 +1,19 @@
open Containers
type t = int * int [@@deriving show]
type 'a grid =
{ width : int
; height : int
; items : 'a array
type t =
{ x : int
; y : int
}
[@@deriving show]
let origin = 0, 0
let up = 0, 1
let down = 0, -1
let left = -1, 0
let right = 1, 0
let origin = { x = 0; y = 0 }
let up = { x = 0; y = 1 }
let down = { x = 0; y = -1 }
let left = { x = -1; y = 0 }
let right = { x = 1; y = 0 }
let directions = [ up; down; left; right ]
let of_tuple x = x
let to_tuple x = x
let ( + ) a b = Pair.map_same2 ( + ) a b
let ( - ) a b = Pair.map_same2 ( - ) a b
let ( = ) a b = Pair.equal ( = ) ( = ) a b
let at (grid : 'a grid) (point : t) =
let x, y = point in
if x >= 0 && x < grid.width && y >= 0 && y < grid.height
then Array.get_safe grid.items @@ Int.((grid.width * y) + x)
else None
;;
let at_e (grid : 'a grid) (point : t) =
Option.get_exn_or "out of bounds!" @@ at grid point
;;
let find (grid : 'a grid) pred =
let open Option.Infix in
let* idx, item = Array.find_idx pred grid.items in
let y = idx / grid.width in
let x = idx mod grid.width in
Some ((x, y), item)
;;
let parse_grid parse_char lines : 'a grid =
match lines with
| first_line :: _ ->
let width = String.length first_line in
let height = List.length lines in
let yeet =
lines
|> List.map String.to_list
|> List.flatten
|> List.map parse_char
|> Array.of_list
in
{ width; height; items = yeet }
| _ -> failwith "somethin fucd up"
;;
let iter_grid (grid : 'a grid) callback =
for y = 0 to Int.(grid.height - 1) do
for x = 0 to Int.(grid.width - 1) do
callback (x, y)
done
done
;;
let of_tuple (x, y) = { x; y }
let to_tuple { x; y } = x, y
let ( + ) a b = { x = a.x + b.x; y = a.y + b.y }
let ( - ) a b = { x = a.x - b.x; y = a.y - b.y }
let ( = ) a b = a.x = b.x && a.y = b.y

View File

@ -1,5 +1,8 @@
type t [@@deriving show]
type 'a grid [@@deriving show]
type t =
{ x : int
; y : int
}
[@@deriving show]
val origin : t
val up : t
@ -12,8 +15,3 @@ val to_tuple : t -> int * int
val ( + ) : t -> t -> t
val ( - ) : t -> t -> t
val ( = ) : t -> t -> bool
val at : 'a grid -> t -> 'a option
val at_e : 'a grid -> t -> 'a
val parse_grid : (char -> 'a) -> string list -> 'a grid
val find : 'a grid -> ('a -> bool) -> (t * 'a) option
val iter_grid : 'a grid -> (t -> unit) -> unit