14
This commit is contained in:
parent
30af58efcf
commit
bbb8000456
16
2022/14/Makefile
Normal file
16
2022/14/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
CXX ?= c++
|
||||
CXXFLAGS ?= -std=c++11 -Wall -Wextra -pedantic -g #-O2
|
||||
PROJECT = sand
|
||||
|
||||
all: ${PROJECT}
|
||||
|
||||
${PROJECT}: main.cpp
|
||||
${CXX} ${CXXFLAGS} -o $@ $^
|
||||
|
||||
test: ${PROJECT}
|
||||
./${PROJECT}
|
||||
|
||||
clean:
|
||||
${RM} *.o ${PROJECT}
|
||||
|
||||
.PHONY: all clean test
|
155
2022/14/input
Normal file
155
2022/14/input
Normal file
@ -0,0 +1,155 @@
|
||||
529,71 -> 529,72 -> 539,72 -> 539,71
|
||||
484,168 -> 489,168
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
502,165 -> 507,165
|
||||
481,165 -> 486,165
|
||||
527,96 -> 527,98 -> 525,98 -> 525,106 -> 536,106 -> 536,98 -> 530,98 -> 530,96
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
500,176 -> 505,176
|
||||
513,124 -> 513,126 -> 510,126 -> 510,134 -> 524,134 -> 524,126 -> 518,126 -> 518,124
|
||||
498,140 -> 498,142 -> 497,142 -> 497,150 -> 507,150 -> 507,142 -> 502,142 -> 502,140
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
527,96 -> 527,98 -> 525,98 -> 525,106 -> 536,106 -> 536,98 -> 530,98 -> 530,96
|
||||
506,42 -> 510,42
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
490,156 -> 495,156
|
||||
496,174 -> 501,174
|
||||
503,40 -> 507,40
|
||||
501,136 -> 501,137 -> 514,137 -> 514,136
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
495,165 -> 500,165
|
||||
537,85 -> 537,77 -> 537,85 -> 539,85 -> 539,76 -> 539,85 -> 541,85 -> 541,75 -> 541,85
|
||||
527,96 -> 527,98 -> 525,98 -> 525,106 -> 536,106 -> 536,98 -> 530,98 -> 530,96
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
529,71 -> 529,72 -> 539,72 -> 539,71
|
||||
488,165 -> 493,165
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
524,42 -> 528,42
|
||||
537,85 -> 537,77 -> 537,85 -> 539,85 -> 539,76 -> 539,85 -> 541,85 -> 541,75 -> 541,85
|
||||
533,118 -> 538,118
|
||||
537,85 -> 537,77 -> 537,85 -> 539,85 -> 539,76 -> 539,85 -> 541,85 -> 541,75 -> 541,85
|
||||
500,42 -> 504,42
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
493,153 -> 498,153
|
||||
472,176 -> 477,176
|
||||
491,162 -> 496,162
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
487,159 -> 492,159
|
||||
521,40 -> 525,40
|
||||
501,136 -> 501,137 -> 514,137 -> 514,136
|
||||
475,174 -> 480,174
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
484,162 -> 489,162
|
||||
515,40 -> 519,40
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
485,172 -> 490,172
|
||||
512,34 -> 516,34
|
||||
537,85 -> 537,77 -> 537,85 -> 539,85 -> 539,76 -> 539,85 -> 541,85 -> 541,75 -> 541,85
|
||||
492,172 -> 497,172
|
||||
501,136 -> 501,137 -> 514,137 -> 514,136
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
489,174 -> 494,174
|
||||
516,121 -> 521,121
|
||||
512,118 -> 517,118
|
||||
529,115 -> 534,115
|
||||
519,118 -> 524,118
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
513,124 -> 513,126 -> 510,126 -> 510,134 -> 524,134 -> 524,126 -> 518,126 -> 518,124
|
||||
505,26 -> 505,28 -> 500,28 -> 500,31 -> 513,31 -> 513,28 -> 509,28 -> 509,26
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
505,26 -> 505,28 -> 500,28 -> 500,31 -> 513,31 -> 513,28 -> 509,28 -> 509,26
|
||||
498,140 -> 498,142 -> 497,142 -> 497,150 -> 507,150 -> 507,142 -> 502,142 -> 502,140
|
||||
509,40 -> 513,40
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
525,112 -> 530,112
|
||||
527,96 -> 527,98 -> 525,98 -> 525,106 -> 536,106 -> 536,98 -> 530,98 -> 530,96
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
537,121 -> 542,121
|
||||
494,159 -> 499,159
|
||||
513,124 -> 513,126 -> 510,126 -> 510,134 -> 524,134 -> 524,126 -> 518,126 -> 518,124
|
||||
509,121 -> 514,121
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
537,85 -> 537,77 -> 537,85 -> 539,85 -> 539,76 -> 539,85 -> 541,85 -> 541,75 -> 541,85
|
||||
528,88 -> 528,89 -> 542,89 -> 542,88
|
||||
498,140 -> 498,142 -> 497,142 -> 497,150 -> 507,150 -> 507,142 -> 502,142 -> 502,140
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
513,124 -> 513,126 -> 510,126 -> 510,134 -> 524,134 -> 524,126 -> 518,126 -> 518,124
|
||||
529,71 -> 529,72 -> 539,72 -> 539,71
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
505,26 -> 505,28 -> 500,28 -> 500,31 -> 513,31 -> 513,28 -> 509,28 -> 509,26
|
||||
505,162 -> 510,162
|
||||
523,121 -> 528,121
|
||||
493,176 -> 498,176
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
501,159 -> 506,159
|
||||
478,172 -> 483,172
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
527,96 -> 527,98 -> 525,98 -> 525,106 -> 536,106 -> 536,98 -> 530,98 -> 530,96
|
||||
498,140 -> 498,142 -> 497,142 -> 497,150 -> 507,150 -> 507,142 -> 502,142 -> 502,140
|
||||
497,156 -> 502,156
|
||||
521,109 -> 526,109
|
||||
518,112 -> 523,112
|
||||
518,42 -> 522,42
|
||||
505,26 -> 505,28 -> 500,28 -> 500,31 -> 513,31 -> 513,28 -> 509,28 -> 509,26
|
||||
519,92 -> 519,93 -> 528,93
|
||||
522,115 -> 527,115
|
||||
505,26 -> 505,28 -> 500,28 -> 500,31 -> 513,31 -> 513,28 -> 509,28 -> 509,26
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
512,42 -> 516,42
|
||||
537,85 -> 537,77 -> 537,85 -> 539,85 -> 539,76 -> 539,85 -> 541,85 -> 541,75 -> 541,85
|
||||
513,124 -> 513,126 -> 510,126 -> 510,134 -> 524,134 -> 524,126 -> 518,126 -> 518,124
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
498,140 -> 498,142 -> 497,142 -> 497,150 -> 507,150 -> 507,142 -> 502,142 -> 502,140
|
||||
482,174 -> 487,174
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
537,85 -> 537,77 -> 537,85 -> 539,85 -> 539,76 -> 539,85 -> 541,85 -> 541,75 -> 541,85
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
479,176 -> 484,176
|
||||
486,176 -> 491,176
|
||||
498,140 -> 498,142 -> 497,142 -> 497,150 -> 507,150 -> 507,142 -> 502,142 -> 502,140
|
||||
481,170 -> 486,170
|
||||
513,124 -> 513,126 -> 510,126 -> 510,134 -> 524,134 -> 524,126 -> 518,126 -> 518,124
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
515,36 -> 519,36
|
||||
512,38 -> 516,38
|
||||
498,140 -> 498,142 -> 497,142 -> 497,150 -> 507,150 -> 507,142 -> 502,142 -> 502,140
|
||||
528,88 -> 528,89 -> 542,89 -> 542,88
|
||||
537,85 -> 537,77 -> 537,85 -> 539,85 -> 539,76 -> 539,85 -> 541,85 -> 541,75 -> 541,85
|
||||
498,162 -> 503,162
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
513,124 -> 513,126 -> 510,126 -> 510,134 -> 524,134 -> 524,126 -> 518,126 -> 518,124
|
||||
505,26 -> 505,28 -> 500,28 -> 500,31 -> 513,31 -> 513,28 -> 509,28 -> 509,26
|
||||
515,115 -> 520,115
|
||||
509,165 -> 514,165
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
518,38 -> 522,38
|
||||
509,36 -> 513,36
|
||||
528,88 -> 528,89 -> 542,89 -> 542,88
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
506,38 -> 510,38
|
||||
526,118 -> 531,118
|
||||
519,92 -> 519,93 -> 528,93
|
||||
527,96 -> 527,98 -> 525,98 -> 525,106 -> 536,106 -> 536,98 -> 530,98 -> 530,96
|
||||
505,26 -> 505,28 -> 500,28 -> 500,31 -> 513,31 -> 513,28 -> 509,28 -> 509,26
|
||||
488,170 -> 493,170
|
||||
530,121 -> 535,121
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
528,68 -> 528,59 -> 528,68 -> 530,68 -> 530,63 -> 530,68 -> 532,68 -> 532,64 -> 532,68 -> 534,68 -> 534,66 -> 534,68 -> 536,68 -> 536,60 -> 536,68
|
||||
524,55 -> 524,46 -> 524,55 -> 526,55 -> 526,45 -> 526,55 -> 528,55 -> 528,47 -> 528,55 -> 530,55 -> 530,46 -> 530,55 -> 532,55 -> 532,48 -> 532,55
|
||||
493,23 -> 493,13 -> 493,23 -> 495,23 -> 495,19 -> 495,23 -> 497,23 -> 497,15 -> 497,23 -> 499,23 -> 499,14 -> 499,23 -> 501,23 -> 501,14 -> 501,23 -> 503,23 -> 503,21 -> 503,23 -> 505,23 -> 505,18 -> 505,23
|
||||
527,96 -> 527,98 -> 525,98 -> 525,106 -> 536,106 -> 536,98 -> 530,98 -> 530,96
|
111
2022/14/main.cpp
Normal file
111
2022/14/main.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
std::vector<std::vector<bool>> getMap( std::ifstream &file ) {
|
||||
std::vector<std::vector<bool>> ret{};
|
||||
std::vector<std::vector<std::pair<int,int>>> rocks{};
|
||||
int max_y = 0;
|
||||
std::string str;
|
||||
char tmp_c;
|
||||
while ( std::getline( file, str ) ) {
|
||||
rocks.emplace_back();
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
std::stringstream ss( str );
|
||||
while(ss >> x) {
|
||||
ss >> tmp_c;
|
||||
ss >> y;
|
||||
if(y > max_y) {
|
||||
max_y = y;
|
||||
}
|
||||
rocks.back().push_back({x,y});
|
||||
ss >> tmp_c;
|
||||
ss >> tmp_c;
|
||||
}
|
||||
}
|
||||
// std::cout << "Resizing: " << max_y << std::endl;
|
||||
ret.resize(max_y+1);
|
||||
for(int i = 0; i <= max_y; i++) {
|
||||
ret[i].resize(1000, false);
|
||||
}
|
||||
for(auto &rock_line : rocks) {
|
||||
for(size_t i = 0; i < rock_line.size() - 1; i++) {
|
||||
// std::cout << "i: " << i << std::endl;
|
||||
// std::cout << "X: " << rock_line[i].first << "->" << rock_line[i+1].first << std::endl;
|
||||
// std::cout << "Y: " << rock_line[i].second << "->" << rock_line[i+1].second << std::endl;
|
||||
int x_diff = rock_line[i+1].first - rock_line[i].first;
|
||||
x_diff /= abs(x_diff);
|
||||
int y_diff = rock_line[i+1].second - rock_line[i].second;
|
||||
y_diff /= abs(y_diff);
|
||||
|
||||
int x = rock_line[i].first;
|
||||
int y = rock_line[i].second;
|
||||
while(x != rock_line[i+1].first || y != rock_line[i+1].second) {
|
||||
// std::cout << "X: " << x << ", Y: " << y << std::endl;
|
||||
ret[y][x] = true;
|
||||
x += x_diff;
|
||||
y += y_diff;
|
||||
}
|
||||
ret[y][x] = true;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool willRest(std::vector<std::vector<bool>> &map, size_t x_source, size_t y_source) {
|
||||
size_t x = x_source;
|
||||
size_t y = y_source;
|
||||
while(y < map.size() - 1) {
|
||||
// std::cout << "CHECKING " << "{" << x << ", " << y << "}" << std::endl;
|
||||
if(!map[y+1][x]) {
|
||||
y++;
|
||||
} else if(!map[y+1][x-1]) {
|
||||
y++;
|
||||
x--;
|
||||
} else if(!map[y+1][x+1]) {
|
||||
y++;
|
||||
x++;
|
||||
} else {
|
||||
map[y][x] = true;
|
||||
if(x == x_source && y == y_source) {
|
||||
return false;
|
||||
}
|
||||
// std::cout << "TRUE" << std::endl;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t part1(const std::vector<std::vector<bool>> &map_in) {
|
||||
auto map = map_in;
|
||||
size_t result = 0;
|
||||
while(willRest(map, 500, 0)) {
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t part2(const std::vector<std::vector<bool>> &map_in) {
|
||||
auto map = map_in;
|
||||
map.resize(map.size()+2);
|
||||
map[map.size()-2].resize(1000, false);
|
||||
map.back().resize(1000, true);
|
||||
size_t result = 0;
|
||||
while(willRest(map, 500, 0)) {
|
||||
result++;
|
||||
}
|
||||
result++; // the source position sand
|
||||
return result;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ifstream input_file( "input" );
|
||||
auto map = getMap( input_file );
|
||||
std::cout << "There will be \033[91;1m" << part1(map)
|
||||
<< "\033[0m grains of sand before it starts falling into the abyss." << std::endl;
|
||||
std::cout << "There will be \033[91;1m" << part2(map)
|
||||
<< "\033[0m grains of sand before it stabilizes." << std::endl;
|
||||
}
|
Loading…
Reference in New Issue
Block a user