diff options
author | Yigit Sever | 2021-12-12 02:45:22 +0300 |
---|---|---|
committer | Yigit Sever | 2021-12-12 02:45:22 +0300 |
commit | 54cbcaa842ea9032c850158183eeba45909e26e2 (patch) | |
tree | 959762fa4a2205fd38c4e4b4299df2e63c4b466a /2021/day5 | |
parent | 4bb6f8d06c0e384f3394012b1d48da58ed28cc5e (diff) | |
download | aoc-54cbcaa842ea9032c850158183eeba45909e26e2.tar.gz aoc-54cbcaa842ea9032c850158183eeba45909e26e2.tar.bz2 aoc-54cbcaa842ea9032c850158183eeba45909e26e2.zip |
2021, day5: done
Diffstat (limited to '2021/day5')
-rw-r--r-- | 2021/day5/Cargo.toml | 8 | ||||
-rw-r--r-- | 2021/day5/input | 500 | ||||
-rw-r--r-- | 2021/day5/input.example | 10 | ||||
-rw-r--r-- | 2021/day5/input.mini.example | 2 | ||||
-rw-r--r-- | 2021/day5/src/main.rs | 95 |
5 files changed, 615 insertions, 0 deletions
diff --git a/2021/day5/Cargo.toml b/2021/day5/Cargo.toml new file mode 100644 index 0000000..f9b62bf --- /dev/null +++ b/2021/day5/Cargo.toml | |||
@@ -0,0 +1,8 @@ | |||
1 | [package] | ||
2 | name = "day5" | ||
3 | version = "0.1.0" | ||
4 | edition = "2021" | ||
5 | |||
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
7 | |||
8 | [dependencies] | ||
diff --git a/2021/day5/input b/2021/day5/input new file mode 100644 index 0000000..45eb5f4 --- /dev/null +++ b/2021/day5/input | |||
@@ -0,0 +1,500 @@ | |||
1 | 957,596 -> 957,182 | ||
2 | 763,144 -> 69,144 | ||
3 | 761,794 -> 911,944 | ||
4 | 510,440 -> 147,440 | ||
5 | 859,33 -> 859,409 | ||
6 | 602,518 -> 748,518 | ||
7 | 980,545 -> 676,241 | ||
8 | 60,528 -> 616,528 | ||
9 | 37,242 -> 37,892 | ||
10 | 216,966 -> 216,120 | ||
11 | 372,910 -> 372,307 | ||
12 | 688,864 -> 94,864 | ||
13 | 691,17 -> 167,17 | ||
14 | 989,928 -> 989,816 | ||
15 | 207,84 -> 982,84 | ||
16 | 890,714 -> 502,326 | ||
17 | 286,329 -> 686,329 | ||
18 | 959,62 -> 460,62 | ||
19 | 840,82 -> 780,82 | ||
20 | 960,12 -> 14,958 | ||
21 | 418,45 -> 983,610 | ||
22 | 318,264 -> 988,934 | ||
23 | 458,11 -> 861,11 | ||
24 | 805,197 -> 380,622 | ||
25 | 261,907 -> 261,734 | ||
26 | 409,617 -> 826,617 | ||
27 | 285,457 -> 759,931 | ||
28 | 104,241 -> 913,241 | ||
29 | 781,141 -> 781,671 | ||
30 | 48,956 -> 348,956 | ||
31 | 921,517 -> 974,517 | ||
32 | 565,621 -> 724,621 | ||
33 | 381,276 -> 381,59 | ||
34 | 82,25 -> 946,25 | ||
35 | 978,16 -> 17,977 | ||
36 | 850,438 -> 125,438 | ||
37 | 313,850 -> 313,195 | ||
38 | 789,963 -> 789,29 | ||
39 | 110,156 -> 241,156 | ||
40 | 925,974 -> 458,974 | ||
41 | 93,153 -> 696,756 | ||
42 | 748,312 -> 120,312 | ||
43 | 566,367 -> 360,367 | ||
44 | 687,295 -> 687,284 | ||
45 | 219,925 -> 180,925 | ||
46 | 59,952 -> 59,140 | ||
47 | 641,333 -> 361,53 | ||
48 | 158,587 -> 158,96 | ||
49 | 857,278 -> 857,195 | ||
50 | 653,45 -> 34,664 | ||
51 | 639,384 -> 814,384 | ||
52 | 67,24 -> 902,859 | ||
53 | 850,278 -> 850,448 | ||
54 | 342,505 -> 342,287 | ||
55 | 504,924 -> 536,956 | ||
56 | 408,666 -> 408,310 | ||
57 | 747,347 -> 747,176 | ||
58 | 766,468 -> 54,468 | ||
59 | 283,905 -> 283,421 | ||
60 | 476,334 -> 476,59 | ||
61 | 490,935 -> 753,672 | ||
62 | 385,772 -> 940,772 | ||
63 | 907,316 -> 853,370 | ||
64 | 144,717 -> 746,115 | ||
65 | 741,819 -> 230,819 | ||
66 | 524,397 -> 524,237 | ||
67 | 411,824 -> 288,824 | ||
68 | 160,719 -> 744,135 | ||
69 | 252,550 -> 440,738 | ||
70 | 902,64 -> 902,422 | ||
71 | 392,194 -> 955,757 | ||
72 | 937,735 -> 937,446 | ||
73 | 292,49 -> 985,49 | ||
74 | 899,464 -> 481,46 | ||
75 | 304,369 -> 648,369 | ||
76 | 247,723 -> 247,697 | ||
77 | 665,941 -> 185,461 | ||
78 | 548,25 -> 446,127 | ||
79 | 663,558 -> 154,558 | ||
80 | 52,47 -> 872,867 | ||
81 | 983,68 -> 983,795 | ||
82 | 492,705 -> 654,867 | ||
83 | 82,888 -> 33,888 | ||
84 | 550,443 -> 229,764 | ||
85 | 868,508 -> 375,15 | ||
86 | 120,829 -> 652,829 | ||
87 | 787,296 -> 814,296 | ||
88 | 705,643 -> 351,643 | ||
89 | 52,23 -> 558,23 | ||
90 | 390,92 -> 390,393 | ||
91 | 713,520 -> 897,520 | ||
92 | 280,481 -> 827,481 | ||
93 | 599,181 -> 599,235 | ||
94 | 483,140 -> 773,140 | ||
95 | 571,227 -> 571,779 | ||
96 | 830,45 -> 830,745 | ||
97 | 617,745 -> 449,745 | ||
98 | 89,176 -> 841,928 | ||
99 | 358,868 -> 906,320 | ||
100 | 897,669 -> 654,669 | ||
101 | 717,729 -> 123,135 | ||
102 | 305,330 -> 305,598 | ||
103 | 220,964 -> 600,964 | ||
104 | 607,715 -> 492,715 | ||
105 | 837,561 -> 820,561 | ||
106 | 542,38 -> 542,118 | ||
107 | 390,970 -> 915,445 | ||
108 | 343,160 -> 475,160 | ||
109 | 163,60 -> 972,869 | ||
110 | 786,500 -> 946,500 | ||
111 | 401,393 -> 401,910 | ||
112 | 336,962 -> 528,962 | ||
113 | 520,489 -> 520,525 | ||
114 | 558,584 -> 363,584 | ||
115 | 786,880 -> 584,678 | ||
116 | 704,435 -> 153,986 | ||
117 | 356,522 -> 235,643 | ||
118 | 225,67 -> 229,71 | ||
119 | 389,381 -> 55,47 | ||
120 | 918,229 -> 332,229 | ||
121 | 558,989 -> 558,370 | ||
122 | 307,821 -> 307,447 | ||
123 | 13,232 -> 742,961 | ||
124 | 659,809 -> 467,809 | ||
125 | 905,942 -> 456,942 | ||
126 | 234,810 -> 234,497 | ||
127 | 421,287 -> 643,65 | ||
128 | 183,164 -> 312,164 | ||
129 | 652,955 -> 977,630 | ||
130 | 157,820 -> 853,124 | ||
131 | 278,480 -> 278,384 | ||
132 | 504,399 -> 298,605 | ||
133 | 955,76 -> 798,76 | ||
134 | 565,352 -> 109,352 | ||
135 | 912,16 -> 66,862 | ||
136 | 972,786 -> 235,49 | ||
137 | 146,15 -> 146,186 | ||
138 | 944,149 -> 497,596 | ||
139 | 485,84 -> 762,84 | ||
140 | 975,983 -> 16,24 | ||
141 | 11,896 -> 887,20 | ||
142 | 826,924 -> 126,224 | ||
143 | 246,648 -> 158,736 | ||
144 | 773,377 -> 582,377 | ||
145 | 296,947 -> 378,865 | ||
146 | 592,291 -> 592,861 | ||
147 | 331,470 -> 16,470 | ||
148 | 239,85 -> 705,85 | ||
149 | 409,842 -> 409,966 | ||
150 | 145,438 -> 145,340 | ||
151 | 239,859 -> 239,409 | ||
152 | 651,508 -> 314,845 | ||
153 | 720,39 -> 176,583 | ||
154 | 762,444 -> 762,29 | ||
155 | 983,962 -> 60,39 | ||
156 | 745,248 -> 91,902 | ||
157 | 990,18 -> 990,503 | ||
158 | 441,472 -> 441,211 | ||
159 | 524,837 -> 248,561 | ||
160 | 160,215 -> 842,897 | ||
161 | 469,544 -> 989,544 | ||
162 | 311,241 -> 103,33 | ||
163 | 887,610 -> 746,610 | ||
164 | 377,942 -> 377,803 | ||
165 | 920,401 -> 823,401 | ||
166 | 10,142 -> 10,486 | ||
167 | 850,955 -> 850,578 | ||
168 | 887,728 -> 887,678 | ||
169 | 555,749 -> 84,749 | ||
170 | 839,620 -> 32,620 | ||
171 | 432,709 -> 432,183 | ||
172 | 312,164 -> 859,711 | ||
173 | 20,119 -> 739,838 | ||
174 | 930,871 -> 324,265 | ||
175 | 41,702 -> 41,520 | ||
176 | 48,210 -> 794,956 | ||
177 | 479,526 -> 479,123 | ||
178 | 364,739 -> 364,379 | ||
179 | 920,969 -> 73,122 | ||
180 | 382,314 -> 382,604 | ||
181 | 969,877 -> 129,37 | ||
182 | 274,893 -> 52,671 | ||
183 | 696,296 -> 696,221 | ||
184 | 469,735 -> 626,892 | ||
185 | 682,435 -> 682,937 | ||
186 | 626,550 -> 626,604 | ||
187 | 898,904 -> 898,755 | ||
188 | 836,849 -> 445,458 | ||
189 | 405,237 -> 405,724 | ||
190 | 253,74 -> 908,729 | ||
191 | 837,802 -> 597,802 | ||
192 | 375,450 -> 316,450 | ||
193 | 621,784 -> 314,784 | ||
194 | 856,136 -> 188,804 | ||
195 | 983,11 -> 29,965 | ||
196 | 82,134 -> 752,134 | ||
197 | 677,299 -> 573,299 | ||
198 | 43,726 -> 43,304 | ||
199 | 886,629 -> 886,603 | ||
200 | 439,471 -> 74,836 | ||
201 | 973,879 -> 122,28 | ||
202 | 550,246 -> 497,246 | ||
203 | 49,109 -> 816,876 | ||
204 | 294,493 -> 271,493 | ||
205 | 495,397 -> 495,342 | ||
206 | 846,892 -> 881,927 | ||
207 | 267,397 -> 72,592 | ||
208 | 670,168 -> 22,816 | ||
209 | 482,302 -> 482,681 | ||
210 | 309,692 -> 453,692 | ||
211 | 597,369 -> 597,589 | ||
212 | 518,475 -> 633,475 | ||
213 | 391,484 -> 493,382 | ||
214 | 177,135 -> 139,135 | ||
215 | 458,17 -> 825,17 | ||
216 | 514,292 -> 272,50 | ||
217 | 410,734 -> 142,734 | ||
218 | 465,975 -> 542,898 | ||
219 | 32,901 -> 346,587 | ||
220 | 390,478 -> 571,659 | ||
221 | 835,839 -> 189,839 | ||
222 | 769,407 -> 769,788 | ||
223 | 974,40 -> 103,911 | ||
224 | 710,709 -> 246,709 | ||
225 | 468,857 -> 343,982 | ||
226 | 777,552 -> 951,552 | ||
227 | 23,490 -> 346,490 | ||
228 | 270,384 -> 855,384 | ||
229 | 386,454 -> 166,454 | ||
230 | 166,388 -> 319,388 | ||
231 | 698,514 -> 698,180 | ||
232 | 554,162 -> 528,162 | ||
233 | 651,363 -> 879,363 | ||
234 | 327,123 -> 327,255 | ||
235 | 439,492 -> 719,212 | ||
236 | 903,438 -> 903,356 | ||
237 | 99,611 -> 99,552 | ||
238 | 512,652 -> 45,185 | ||
239 | 565,284 -> 565,180 | ||
240 | 81,710 -> 637,154 | ||
241 | 321,769 -> 164,769 | ||
242 | 32,307 -> 32,204 | ||
243 | 310,338 -> 310,914 | ||
244 | 239,691 -> 357,691 | ||
245 | 573,164 -> 559,164 | ||
246 | 887,961 -> 693,767 | ||
247 | 362,904 -> 362,944 | ||
248 | 467,294 -> 236,294 | ||
249 | 182,53 -> 182,264 | ||
250 | 19,950 -> 951,18 | ||
251 | 191,575 -> 440,824 | ||
252 | 192,168 -> 690,666 | ||
253 | 538,552 -> 891,905 | ||
254 | 243,38 -> 243,403 | ||
255 | 417,140 -> 417,818 | ||
256 | 894,45 -> 726,213 | ||
257 | 245,898 -> 245,527 | ||
258 | 567,946 -> 567,983 | ||
259 | 572,675 -> 363,675 | ||
260 | 318,618 -> 735,618 | ||
261 | 616,580 -> 981,580 | ||
262 | 37,881 -> 134,881 | ||
263 | 624,675 -> 271,322 | ||
264 | 323,686 -> 770,686 | ||
265 | 93,385 -> 626,385 | ||
266 | 715,382 -> 862,382 | ||
267 | 170,342 -> 170,84 | ||
268 | 747,221 -> 380,221 | ||
269 | 981,311 -> 981,577 | ||
270 | 372,186 -> 372,826 | ||
271 | 961,91 -> 130,922 | ||
272 | 48,603 -> 48,110 | ||
273 | 34,975 -> 935,74 | ||
274 | 707,18 -> 707,192 | ||
275 | 261,149 -> 41,369 | ||
276 | 35,589 -> 35,247 | ||
277 | 544,522 -> 437,522 | ||
278 | 797,712 -> 346,712 | ||
279 | 622,47 -> 78,591 | ||
280 | 642,390 -> 642,414 | ||
281 | 793,29 -> 69,29 | ||
282 | 978,905 -> 978,296 | ||
283 | 212,515 -> 212,920 | ||
284 | 835,166 -> 68,933 | ||
285 | 168,742 -> 168,720 | ||
286 | 390,276 -> 666,276 | ||
287 | 507,792 -> 987,792 | ||
288 | 895,242 -> 895,402 | ||
289 | 121,950 -> 943,128 | ||
290 | 303,336 -> 303,205 | ||
291 | 293,390 -> 293,736 | ||
292 | 433,963 -> 433,867 | ||
293 | 824,327 -> 620,531 | ||
294 | 553,689 -> 867,689 | ||
295 | 226,984 -> 226,284 | ||
296 | 153,308 -> 173,308 | ||
297 | 855,959 -> 345,959 | ||
298 | 830,895 -> 830,981 | ||
299 | 557,63 -> 557,205 | ||
300 | 51,857 -> 328,857 | ||
301 | 224,243 -> 224,517 | ||
302 | 830,773 -> 830,520 | ||
303 | 607,210 -> 782,385 | ||
304 | 876,330 -> 327,330 | ||
305 | 985,11 -> 18,978 | ||
306 | 352,936 -> 111,936 | ||
307 | 900,39 -> 986,39 | ||
308 | 10,626 -> 10,795 | ||
309 | 369,942 -> 11,942 | ||
310 | 136,770 -> 654,252 | ||
311 | 209,541 -> 209,557 | ||
312 | 69,671 -> 848,671 | ||
313 | 811,451 -> 194,451 | ||
314 | 149,46 -> 850,747 | ||
315 | 704,386 -> 704,953 | ||
316 | 117,346 -> 387,346 | ||
317 | 238,701 -> 688,251 | ||
318 | 789,220 -> 789,815 | ||
319 | 967,512 -> 967,213 | ||
320 | 641,652 -> 151,162 | ||
321 | 91,942 -> 312,942 | ||
322 | 42,226 -> 801,985 | ||
323 | 166,37 -> 603,37 | ||
324 | 854,976 -> 951,976 | ||
325 | 392,23 -> 772,23 | ||
326 | 299,196 -> 299,288 | ||
327 | 514,560 -> 844,890 | ||
328 | 618,699 -> 348,429 | ||
329 | 604,947 -> 604,735 | ||
330 | 189,851 -> 407,633 | ||
331 | 907,719 -> 907,449 | ||
332 | 167,421 -> 864,421 | ||
333 | 491,383 -> 538,383 | ||
334 | 939,504 -> 939,433 | ||
335 | 78,649 -> 78,975 | ||
336 | 817,246 -> 322,741 | ||
337 | 395,195 -> 205,195 | ||
338 | 872,275 -> 872,500 | ||
339 | 196,621 -> 280,621 | ||
340 | 634,619 -> 634,422 | ||
341 | 395,30 -> 395,232 | ||
342 | 895,628 -> 619,904 | ||
343 | 58,66 -> 186,194 | ||
344 | 626,477 -> 708,559 | ||
345 | 747,712 -> 747,28 | ||
346 | 935,798 -> 220,798 | ||
347 | 459,530 -> 704,530 | ||
348 | 648,679 -> 79,110 | ||
349 | 778,135 -> 778,66 | ||
350 | 657,352 -> 906,352 | ||
351 | 499,160 -> 615,160 | ||
352 | 830,226 -> 830,489 | ||
353 | 364,971 -> 826,971 | ||
354 | 879,923 -> 543,923 | ||
355 | 914,984 -> 612,984 | ||
356 | 594,810 -> 508,810 | ||
357 | 55,467 -> 269,253 | ||
358 | 360,478 -> 360,902 | ||
359 | 176,890 -> 176,431 | ||
360 | 867,121 -> 16,972 | ||
361 | 728,876 -> 65,213 | ||
362 | 606,112 -> 842,112 | ||
363 | 563,532 -> 914,532 | ||
364 | 783,139 -> 369,139 | ||
365 | 564,359 -> 846,359 | ||
366 | 79,326 -> 15,390 | ||
367 | 972,419 -> 972,35 | ||
368 | 686,839 -> 755,839 | ||
369 | 427,856 -> 77,856 | ||
370 | 102,410 -> 925,410 | ||
371 | 468,177 -> 901,610 | ||
372 | 865,249 -> 930,314 | ||
373 | 784,447 -> 863,368 | ||
374 | 684,708 -> 223,708 | ||
375 | 555,228 -> 555,900 | ||
376 | 380,600 -> 222,600 | ||
377 | 900,408 -> 188,408 | ||
378 | 773,677 -> 773,16 | ||
379 | 560,287 -> 560,790 | ||
380 | 130,851 -> 959,22 | ||
381 | 338,951 -> 626,663 | ||
382 | 678,726 -> 405,726 | ||
383 | 243,469 -> 243,276 | ||
384 | 783,486 -> 66,486 | ||
385 | 469,536 -> 469,770 | ||
386 | 689,148 -> 689,340 | ||
387 | 396,689 -> 396,673 | ||
388 | 848,759 -> 848,770 | ||
389 | 965,775 -> 965,605 | ||
390 | 889,907 -> 284,302 | ||
391 | 161,169 -> 942,950 | ||
392 | 619,267 -> 394,492 | ||
393 | 323,786 -> 18,481 | ||
394 | 953,643 -> 884,643 | ||
395 | 371,446 -> 371,252 | ||
396 | 890,915 -> 192,217 | ||
397 | 674,259 -> 674,247 | ||
398 | 877,479 -> 877,117 | ||
399 | 620,843 -> 620,734 | ||
400 | 597,722 -> 597,939 | ||
401 | 935,663 -> 935,469 | ||
402 | 108,844 -> 108,596 | ||
403 | 211,447 -> 211,482 | ||
404 | 123,657 -> 721,59 | ||
405 | 774,858 -> 774,86 | ||
406 | 978,500 -> 978,305 | ||
407 | 152,890 -> 937,105 | ||
408 | 728,356 -> 728,261 | ||
409 | 354,373 -> 433,452 | ||
410 | 586,627 -> 586,949 | ||
411 | 764,381 -> 735,410 | ||
412 | 986,899 -> 199,112 | ||
413 | 251,418 -> 251,596 | ||
414 | 897,379 -> 897,388 | ||
415 | 149,901 -> 253,901 | ||
416 | 650,229 -> 46,229 | ||
417 | 446,707 -> 446,44 | ||
418 | 953,898 -> 697,898 | ||
419 | 772,422 -> 762,432 | ||
420 | 608,756 -> 927,756 | ||
421 | 138,911 -> 716,333 | ||
422 | 414,583 -> 244,583 | ||
423 | 219,267 -> 219,751 | ||
424 | 69,746 -> 69,886 | ||
425 | 444,243 -> 493,194 | ||
426 | 604,950 -> 244,950 | ||
427 | 450,198 -> 31,617 | ||
428 | 918,852 -> 109,43 | ||
429 | 967,800 -> 267,100 | ||
430 | 388,516 -> 760,516 | ||
431 | 656,954 -> 513,954 | ||
432 | 80,680 -> 80,44 | ||
433 | 360,848 -> 360,800 | ||
434 | 10,10 -> 989,989 | ||
435 | 889,927 -> 104,142 | ||
436 | 882,187 -> 812,187 | ||
437 | 416,522 -> 356,522 | ||
438 | 797,795 -> 273,271 | ||
439 | 175,371 -> 12,371 | ||
440 | 726,595 -> 956,595 | ||
441 | 852,355 -> 852,357 | ||
442 | 959,83 -> 338,83 | ||
443 | 822,766 -> 140,84 | ||
444 | 968,129 -> 181,916 | ||
445 | 17,28 -> 975,986 | ||
446 | 15,913 -> 624,304 | ||
447 | 589,322 -> 468,443 | ||
448 | 894,21 -> 309,606 | ||
449 | 83,25 -> 963,905 | ||
450 | 143,380 -> 377,146 | ||
451 | 587,151 -> 507,151 | ||
452 | 257,967 -> 257,882 | ||
453 | 770,552 -> 770,573 | ||
454 | 128,90 -> 886,848 | ||
455 | 456,953 -> 456,669 | ||
456 | 930,434 -> 668,434 | ||
457 | 501,835 -> 796,540 | ||
458 | 36,980 -> 989,27 | ||
459 | 494,690 -> 626,690 | ||
460 | 105,945 -> 972,78 | ||
461 | 409,730 -> 409,62 | ||
462 | 901,160 -> 831,90 | ||
463 | 881,490 -> 28,490 | ||
464 | 736,244 -> 38,942 | ||
465 | 295,770 -> 199,770 | ||
466 | 866,416 -> 808,416 | ||
467 | 875,716 -> 875,189 | ||
468 | 763,393 -> 241,915 | ||
469 | 583,237 -> 704,237 | ||
470 | 29,153 -> 637,153 | ||
471 | 767,282 -> 767,107 | ||
472 | 456,242 -> 456,165 | ||
473 | 455,232 -> 749,232 | ||
474 | 54,128 -> 766,840 | ||
475 | 901,73 -> 939,73 | ||
476 | 928,118 -> 854,118 | ||
477 | 15,983 -> 975,23 | ||
478 | 600,92 -> 260,92 | ||
479 | 247,714 -> 247,490 | ||
480 | 511,332 -> 19,824 | ||
481 | 55,15 -> 968,928 | ||
482 | 246,29 -> 25,29 | ||
483 | 22,101 -> 761,840 | ||
484 | 876,177 -> 139,914 | ||
485 | 165,150 -> 822,807 | ||
486 | 258,707 -> 773,707 | ||
487 | 68,788 -> 68,875 | ||
488 | 858,142 -> 758,142 | ||
489 | 719,642 -> 810,642 | ||
490 | 928,904 -> 928,338 | ||
491 | 287,977 -> 978,286 | ||
492 | 883,13 -> 883,31 | ||
493 | 681,301 -> 681,957 | ||
494 | 762,863 -> 405,506 | ||
495 | 194,657 -> 733,118 | ||
496 | 78,41 -> 497,41 | ||
497 | 840,627 -> 840,168 | ||
498 | 335,54 -> 335,822 | ||
499 | 136,983 -> 526,593 | ||
500 | 120,156 -> 120,630 | ||
diff --git a/2021/day5/input.example b/2021/day5/input.example new file mode 100644 index 0000000..b258f68 --- /dev/null +++ b/2021/day5/input.example | |||
@@ -0,0 +1,10 @@ | |||
1 | 0,9 -> 5,9 | ||
2 | 8,0 -> 0,8 | ||
3 | 9,4 -> 3,4 | ||
4 | 2,2 -> 2,1 | ||
5 | 7,0 -> 7,4 | ||
6 | 6,4 -> 2,0 | ||
7 | 0,9 -> 2,9 | ||
8 | 3,4 -> 1,4 | ||
9 | 0,0 -> 8,8 | ||
10 | 5,5 -> 8,2 | ||
diff --git a/2021/day5/input.mini.example b/2021/day5/input.mini.example new file mode 100644 index 0000000..b775b12 --- /dev/null +++ b/2021/day5/input.mini.example | |||
@@ -0,0 +1,2 @@ | |||
1 | 1,1 -> 3,3 | ||
2 | 9,7 -> 7,9 | ||
diff --git a/2021/day5/src/main.rs b/2021/day5/src/main.rs new file mode 100644 index 0000000..498deb0 --- /dev/null +++ b/2021/day5/src/main.rs | |||
@@ -0,0 +1,95 @@ | |||
1 | use std::cmp::{max, min}; | ||
2 | use std::collections::HashMap; | ||
3 | use std::env; | ||
4 | use std::fs::File; | ||
5 | use std::io::{BufRead, BufReader}; | ||
6 | |||
7 | fn main() { | ||
8 | let reader = open_file(); | ||
9 | |||
10 | let mut coords: HashMap<(i32, i32), i32> = HashMap::new(); | ||
11 | |||
12 | for line in reader.lines() { | ||
13 | if let Ok(line) = line { | ||
14 | let vents = line.split(" -> ").collect::<Vec<&str>>(); | ||
15 | let first = vents[0].split(",").collect::<Vec<&str>>(); | ||
16 | let second = vents[1].split(",").collect::<Vec<&str>>(); | ||
17 | |||
18 | let first: Vec<i32> = first.into_iter().map(|s| s.parse().unwrap()).collect(); | ||
19 | let second: Vec<i32> = second.into_iter().map(|s| s.parse().unwrap()).collect(); | ||
20 | |||
21 | let xstep: i32; | ||
22 | let ystep: i32; | ||
23 | let start_x = min(first[0], second[0]); | ||
24 | let end_x = max(first[0], second[0]); | ||
25 | let start_y = min(first[1], second[1]); | ||
26 | let end_y = max(first[1], second[1]); | ||
27 | let distance = max(end_x - start_x, end_y - start_y); | ||
28 | |||
29 | if first[0] > second[0] { | ||
30 | xstep = -1; | ||
31 | } else if first[0] < second[0] { | ||
32 | xstep = 1; | ||
33 | } else { | ||
34 | xstep = 0; | ||
35 | } | ||
36 | |||
37 | if first[1] > second[1] { | ||
38 | ystep = -1; | ||
39 | } else if first[1] < second[1] { | ||
40 | ystep = 1; | ||
41 | } else { | ||
42 | ystep = 0; | ||
43 | } | ||
44 | |||
45 | for step in 0..=distance { | ||
46 | let counter = coords | ||
47 | .entry((first[0] + step * xstep, first[1] + step * ystep)) | ||
48 | .or_insert(0); | ||
49 | *counter += 1; | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
54 | // println!("coords: {:?}", coords); | ||
55 | // visualize(&coords); | ||
56 | |||
57 | let result = coords.iter().filter(|(_, &y)| y >= 2).count(); | ||
58 | println!("{}", result); | ||
59 | } | ||
60 | |||
61 | fn visualize(map: &HashMap<(i32, i32), i32>) { | ||
62 | let start_x = map.iter().map(|((x, _), _)| x).min().unwrap(); | ||
63 | let start_y = map.iter().map(|((_, y), _)| y).min().unwrap(); | ||
64 | let end_x = map.iter().map(|((x, _), _)| x).max().unwrap(); | ||
65 | let end_y = map.iter().map(|((_, y), _)| y).max().unwrap(); | ||
66 | println!("start_x: {}", start_x); | ||
67 | println!("start_y: {}", start_y); | ||
68 | println!("end_x: {}", end_x); | ||
69 | println!("end_y: {}", end_y); | ||
70 | |||
71 | for y in *start_y..=*end_y { | ||
72 | for x in *start_x..=*end_x { | ||
73 | if let Some(val) = map.get(&(x, y)) { | ||
74 | print!("{}", val); | ||
75 | } else { | ||
76 | print!(".") | ||
77 | } | ||
78 | } | ||
79 | println!(""); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | fn open_file() -> BufReader<File> { | ||
84 | let args: Vec<String> = env::args().collect(); | ||
85 | |||
86 | if args.len() != 2 { | ||
87 | eprintln!("Usage: {} <filename>", args[0]); | ||
88 | std::process::exit(1); | ||
89 | } | ||
90 | |||
91 | let filename = &args[1]; | ||
92 | |||
93 | let file = File::open(filename).unwrap_or_else(|_| panic!("No such file: {}", filename)); | ||
94 | BufReader::new(file) | ||
95 | } | ||