Solutions for day five

This commit is contained in:
Eric Wagoner 2021-12-05 23:59:01 -05:00
parent 1443aa828f
commit d306294bda
2 changed files with 564 additions and 0 deletions

64
05/code.js Normal file
View File

@ -0,0 +1,64 @@
const fs = require('fs');
const inputArray = fs.readFileSync('input.txt').toString().split("\n");
const seabed = new Array(1000).fill(0).map(() => new Array(1000).fill(0));
const vents = [];
for (const vent of inputArray) {
const ventArray = [];
const endpoints = vent.split(" -> ");
ventArray.push(endpoints[0].split(",").map(Number));
ventArray.push(endpoints[1].split(",").map(Number));
vents.push(ventArray);
}
// Part One
// const part = 1;
// Part Two
const part = 2;
for (const vent of vents) {
let x1 = vent[0][0];
let x2 = vent[1][0];
let y1 = vent[0][1];
let y2 = vent[1][1];
if (x1 === x2) {
if (y1 > y2) {
[y1, y2] = [y2, y1];
}
for (let y = y1; y <= y2; y++) {
seabed[x1][y]++;
}
} else if (y1 === y2) {
if (x1 > x2) {
[x1, x2] = [x2, x1];
}
for (let x = x1; x <= x2; x++) {
seabed[x][y1]++;
}
} else if (part === 2) {
const distance = Math.abs(x2 - x1);
for (let i = 0; i <= distance; i++) {
if (y1 > y2 && x1 > x2) {
seabed[x1 - i][y1 - i]++;
} else if (y1 > y2) {
seabed[x1 + i][y1 - i]++;
} else if (x1 > x2) {
seabed[x1 - i][y1 + i]++;
} else {
seabed[x1 + i][y1 + i]++;
}
}
}
}
let multiples = 0;
for (const coordinate of seabed.flat(1)) {
if (coordinate > 1) {
multiples++;
}
}
console.log(multiples);

500
05/input.txt Normal file
View File

@ -0,0 +1,500 @@
556,286 -> 341,71
337,201 -> 782,646
786,780 -> 117,111
977,864 -> 199,86
544,127 -> 544,144
539,471 -> 539,972
364,765 -> 364,285
282,325 -> 892,935
536,941 -> 158,941
280,39 -> 806,565
168,662 -> 363,857
639,676 -> 639,701
397,809 -> 466,809
716,118 -> 625,209
153,582 -> 497,926
35,706 -> 398,706
61,41 -> 519,41
158,557 -> 158,922
320,177 -> 624,481
800,779 -> 466,779
292,270 -> 292,497
919,17 -> 757,17
935,520 -> 935,688
948,480 -> 303,480
306,811 -> 306,467
227,582 -> 464,819
757,807 -> 757,688
983,12 -> 30,965
632,262 -> 640,262
755,314 -> 138,931
179,599 -> 179,144
556,246 -> 801,491
114,218 -> 114,60
183,70 -> 423,70
561,661 -> 231,331
875,738 -> 723,890
812,828 -> 812,78
98,707 -> 88,707
804,979 -> 188,979
503,178 -> 453,178
902,678 -> 248,678
603,618 -> 737,752
788,735 -> 559,964
839,134 -> 839,408
569,356 -> 491,356
566,543 -> 566,77
624,386 -> 111,386
781,109 -> 781,52
187,709 -> 23,545
220,123 -> 856,123
210,528 -> 398,716
942,935 -> 58,51
102,13 -> 102,560
926,588 -> 969,545
529,117 -> 146,117
989,211 -> 739,461
207,201 -> 207,106
799,876 -> 284,876
370,773 -> 687,456
571,972 -> 571,351
877,910 -> 877,12
384,205 -> 384,940
493,915 -> 912,496
764,412 -> 368,16
368,220 -> 333,220
526,271 -> 778,271
379,203 -> 417,165
168,577 -> 168,709
529,808 -> 598,739
959,506 -> 959,626
576,89 -> 863,89
277,412 -> 311,378
12,19 -> 975,982
620,951 -> 240,571
937,206 -> 954,206
231,177 -> 918,864
499,825 -> 315,825
289,876 -> 289,302
408,569 -> 46,207
461,838 -> 91,838
281,294 -> 281,737
61,541 -> 61,747
768,857 -> 768,276
782,97 -> 33,97
544,563 -> 251,856
731,216 -> 731,19
767,142 -> 242,667
469,612 -> 952,129
508,363 -> 508,540
614,845 -> 614,739
342,362 -> 235,362
880,703 -> 880,653
942,669 -> 651,669
884,976 -> 884,924
158,822 -> 945,35
510,716 -> 884,342
523,946 -> 73,496
334,430 -> 157,253
593,77 -> 105,565
269,132 -> 243,132
902,529 -> 180,529
554,767 -> 554,938
164,615 -> 425,615
51,713 -> 51,341
428,606 -> 89,945
600,402 -> 600,185
774,550 -> 774,207
465,204 -> 697,436
577,719 -> 255,719
647,990 -> 970,990
649,170 -> 886,407
428,503 -> 428,394
381,608 -> 381,444
778,175 -> 778,121
795,379 -> 379,379
929,792 -> 218,81
504,837 -> 504,449
212,216 -> 212,76
446,744 -> 446,116
824,247 -> 577,247
77,214 -> 553,214
913,234 -> 913,670
949,24 -> 43,930
733,758 -> 733,62
628,659 -> 962,659
172,749 -> 755,749
901,717 -> 184,717
457,578 -> 923,112
943,11 -> 912,11
728,597 -> 116,597
465,134 -> 465,159
170,953 -> 170,533
231,715 -> 231,219
209,187 -> 984,962
798,515 -> 798,601
479,123 -> 479,148
360,387 -> 360,356
962,818 -> 962,770
852,607 -> 852,886
159,838 -> 967,30
823,659 -> 642,478
374,893 -> 545,893
248,819 -> 248,978
894,473 -> 894,47
182,975 -> 278,879
75,248 -> 913,248
969,533 -> 969,827
18,40 -> 842,864
972,909 -> 220,157
378,159 -> 571,159
875,478 -> 238,478
95,807 -> 264,638
418,68 -> 418,387
784,548 -> 332,548
365,354 -> 365,836
731,615 -> 235,615
885,104 -> 513,476
816,47 -> 385,478
626,741 -> 626,499
371,372 -> 920,921
83,150 -> 922,989
623,520 -> 645,498
612,305 -> 561,305
845,149 -> 788,149
914,35 -> 829,35
143,165 -> 143,520
164,218 -> 266,218
118,644 -> 397,644
59,942 -> 970,31
616,774 -> 970,420
30,468 -> 874,468
454,208 -> 454,536
524,488 -> 524,931
54,479 -> 560,479
815,591 -> 815,813
959,971 -> 30,42
23,181 -> 149,181
841,294 -> 841,681
34,47 -> 367,47
913,590 -> 913,374
690,64 -> 690,672
541,112 -> 781,112
380,843 -> 687,536
303,330 -> 465,330
408,403 -> 326,403
352,962 -> 925,389
121,882 -> 873,130
979,294 -> 29,294
228,688 -> 228,738
845,930 -> 901,930
726,189 -> 27,888
223,888 -> 989,888
483,632 -> 483,321
606,810 -> 820,810
225,31 -> 225,342
841,18 -> 841,417
375,185 -> 375,413
641,189 -> 307,523
126,900 -> 126,990
530,220 -> 690,220
496,263 -> 154,263
140,503 -> 419,503
349,733 -> 349,819
43,29 -> 928,914
683,842 -> 683,489
113,634 -> 806,634
771,145 -> 130,145
88,467 -> 908,467
328,642 -> 328,795
986,191 -> 218,959
857,166 -> 857,594
950,763 -> 229,42
263,940 -> 101,940
689,182 -> 689,835
241,237 -> 733,237
965,150 -> 279,150
871,242 -> 474,639
688,947 -> 688,11
319,738 -> 945,112
21,853 -> 853,21
69,533 -> 69,741
492,981 -> 492,210
942,69 -> 249,69
63,364 -> 203,364
340,505 -> 15,505
41,43 -> 979,981
395,623 -> 217,801
540,37 -> 540,381
64,112 -> 882,930
887,212 -> 217,882
168,159 -> 108,159
117,22 -> 959,864
413,500 -> 413,616
775,597 -> 962,597
171,901 -> 143,901
777,391 -> 41,391
901,139 -> 70,970
215,75 -> 215,261
973,433 -> 786,433
757,568 -> 612,423
363,347 -> 185,525
274,363 -> 274,709
435,569 -> 880,569
267,297 -> 86,478
221,852 -> 985,88
322,560 -> 322,962
470,259 -> 470,508
861,860 -> 843,860
172,474 -> 172,714
53,839 -> 499,839
600,40 -> 600,227
820,952 -> 99,231
650,486 -> 586,486
305,273 -> 305,392
826,417 -> 826,92
309,934 -> 309,720
381,644 -> 381,623
38,78 -> 38,54
326,450 -> 173,450
474,100 -> 474,135
607,536 -> 192,121
686,504 -> 164,504
538,623 -> 429,623
200,385 -> 933,385
568,275 -> 31,275
105,201 -> 706,201
582,584 -> 827,584
24,469 -> 24,519
306,224 -> 32,224
429,528 -> 304,528
272,851 -> 272,927
636,113 -> 636,244
481,107 -> 783,107
834,87 -> 175,746
684,50 -> 61,673
30,335 -> 739,335
621,893 -> 266,893
968,942 -> 968,390
895,23 -> 136,23
742,650 -> 756,636
42,582 -> 368,582
890,266 -> 786,266
591,807 -> 921,807
915,333 -> 915,160
746,326 -> 826,326
663,803 -> 34,174
533,513 -> 692,513
205,133 -> 935,133
730,138 -> 58,810
290,87 -> 290,488
693,513 -> 693,323
188,491 -> 188,587
562,593 -> 562,122
629,457 -> 629,299
132,781 -> 381,781
356,965 -> 356,899
720,715 -> 487,715
356,120 -> 954,120
657,507 -> 323,173
13,190 -> 742,190
677,640 -> 491,640
145,605 -> 366,605
143,683 -> 681,145
700,787 -> 557,787
958,406 -> 212,406
267,734 -> 705,734
470,333 -> 257,120
790,656 -> 523,389
13,904 -> 898,19
29,970 -> 961,38
846,454 -> 846,153
564,488 -> 98,488
904,19 -> 60,863
493,112 -> 472,133
945,977 -> 141,173
720,231 -> 720,367
783,133 -> 783,422
165,754 -> 165,604
752,308 -> 715,271
413,969 -> 431,951
833,437 -> 833,881
612,802 -> 612,64
974,187 -> 543,618
655,183 -> 675,183
696,833 -> 906,623
756,792 -> 756,741
338,140 -> 878,680
854,955 -> 241,342
602,466 -> 326,466
470,125 -> 464,131
568,141 -> 43,666
826,318 -> 783,275
194,986 -> 194,466
896,330 -> 621,55
482,709 -> 704,931
345,912 -> 345,741
758,119 -> 758,841
11,777 -> 11,249
88,945 -> 795,945
665,74 -> 124,615
243,831 -> 249,837
40,69 -> 720,749
757,804 -> 757,900
803,265 -> 336,732
299,155 -> 758,614
787,173 -> 172,788
251,400 -> 251,168
217,480 -> 486,480
939,974 -> 21,56
767,649 -> 378,649
197,764 -> 561,400
767,577 -> 579,577
952,982 -> 28,58
282,527 -> 282,640
944,125 -> 184,125
149,848 -> 351,848
36,437 -> 350,437
63,527 -> 764,527
66,313 -> 302,549
805,485 -> 577,485
660,626 -> 903,626
927,542 -> 897,542
577,344 -> 577,934
624,284 -> 624,497
649,618 -> 153,122
942,32 -> 227,747
10,190 -> 10,629
84,638 -> 470,252
362,89 -> 362,762
351,844 -> 916,279
683,561 -> 497,747
628,473 -> 103,473
319,525 -> 782,62
842,131 -> 551,131
980,960 -> 51,31
662,12 -> 666,12
337,814 -> 337,736
720,99 -> 760,99
867,515 -> 867,650
248,872 -> 142,872
295,274 -> 298,274
102,369 -> 102,648
523,142 -> 54,611
369,798 -> 978,189
215,688 -> 835,688
846,242 -> 786,182
68,923 -> 68,342
690,416 -> 559,547
567,134 -> 278,134
89,126 -> 846,883
779,325 -> 389,325
675,461 -> 675,622
278,925 -> 953,250
907,460 -> 519,848
769,60 -> 592,60
331,103 -> 331,49
148,366 -> 148,516
933,52 -> 332,52
488,642 -> 488,523
632,403 -> 83,952
321,840 -> 756,405
302,627 -> 907,22
650,449 -> 650,553
219,466 -> 219,297
841,947 -> 78,184
40,746 -> 712,74
559,306 -> 895,306
317,592 -> 317,275
267,183 -> 267,428
43,397 -> 43,359
952,705 -> 952,634
921,837 -> 258,174
634,783 -> 656,805
366,309 -> 224,309
383,470 -> 526,613
717,419 -> 717,332
543,752 -> 543,500
954,892 -> 101,39
294,379 -> 583,379
829,388 -> 829,491
748,509 -> 283,509
347,75 -> 467,195
618,958 -> 371,711
986,827 -> 213,54
34,617 -> 982,617
716,902 -> 716,429
970,52 -> 107,915
563,33 -> 563,680
803,82 -> 136,749
24,968 -> 273,968
816,483 -> 620,287
783,588 -> 623,588
397,210 -> 988,801
911,387 -> 911,446
770,730 -> 786,730
22,11 -> 982,971
395,316 -> 151,316
301,420 -> 301,248
10,10 -> 989,989
637,358 -> 247,358
932,341 -> 642,341
162,594 -> 162,448
51,946 -> 396,946
591,253 -> 958,620
567,849 -> 567,713
879,910 -> 879,603
889,642 -> 437,642
669,528 -> 945,252
644,237 -> 774,237
488,870 -> 738,620
692,388 -> 959,388
506,17 -> 701,17
663,514 -> 663,216
684,862 -> 289,862
511,235 -> 519,227
866,940 -> 153,227
381,518 -> 87,518
837,573 -> 181,573
337,191 -> 337,135
324,573 -> 945,573
449,800 -> 390,741
763,378 -> 763,695
24,457 -> 444,877
267,875 -> 798,344
724,848 -> 395,848
931,322 -> 931,244
426,241 -> 280,241
175,879 -> 175,883
496,158 -> 560,158
899,319 -> 805,319
799,424 -> 563,188
958,388 -> 958,290
558,95 -> 314,95
768,646 -> 961,839
246,534 -> 246,147
808,720 -> 808,385
912,147 -> 912,305
670,676 -> 776,676
534,594 -> 696,594
736,768 -> 736,364
377,784 -> 377,368
799,105 -> 978,284
763,575 -> 763,253
581,205 -> 581,45
932,782 -> 678,782
400,950 -> 936,414
68,616 -> 897,616
399,662 -> 291,554
354,397 -> 354,489
219,276 -> 862,919
115,138 -> 195,138
863,326 -> 863,335
884,130 -> 271,743
986,148 -> 234,900
254,186 -> 973,905
975,971 -> 672,971
122,533 -> 19,636
316,512 -> 219,609
113,480 -> 716,480
483,540 -> 845,178