diff options
author | Marvin Borner | 2021-12-05 13:39:11 +0100 |
---|---|---|
committer | Marvin Borner | 2021-12-05 13:39:11 +0100 |
commit | b19dc6dd3da8e3b3fe6dc8e1faafd9606380de42 (patch) | |
tree | f61238568d773d8b3fa1d029d9933fdd72e4cf66 | |
parent | d039c980716fdc1dd83ae9bc9a54f1e0c9fdc85a (diff) |
muahahaha
-rw-r--r-- | 2021/05/Makefile | 19 | ||||
-rw-r--r-- | 2021/05/input | 500 | ||||
-rw-r--r-- | 2021/05/solve.c | 81 |
3 files changed, 600 insertions, 0 deletions
diff --git a/2021/05/Makefile b/2021/05/Makefile new file mode 100644 index 0000000..4a881b7 --- /dev/null +++ b/2021/05/Makefile @@ -0,0 +1,19 @@ +DEBUG = -Wno-error -Og -g -s -fsanitize=undefined -fsanitize=address -fstack-protector-all +CFLAGS = -Wall -Wextra -Werror -Wshadow -Wpointer-arith -Wwrite-strings -Wredundant-decls -Wnested-externs -Wformat=2 -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wswitch-default -Wswitch-enum -Wunreachable-code -Wundef -Wold-style-definition -Wvla -pedantic-errors -Ofast + +# Not the best makefile but idc + +debug: + @gcc $(CFLAGS) $(DEBUG) solve.c -o solve.o -L/usr/lib -lcrypto + +build: + @gcc $(CFLAGS) solve.c -o solve.o -L/usr/lib -lcrypto + +clean: + @rm -f *.o + +run: debug + @./solve.o + +time: build + @./solve.o diff --git a/2021/05/input b/2021/05/input new file mode 100644 index 0000000..69f6044 --- /dev/null +++ b/2021/05/input @@ -0,0 +1,500 @@ +365,809 -> 365,271 +899,814 -> 899,921 +967,913 -> 434,913 +971,362 -> 631,362 +597,422 -> 597,575 +722,82 -> 722,365 +98,891 -> 972,17 +361,534 -> 361,52 +958,858 -> 958,612 +261,683 -> 261,477 +859,381 -> 850,372 +773,305 -> 703,305 +527,318 -> 281,72 +29,119 -> 863,953 +428,723 -> 428,971 +582,787 -> 582,326 +795,495 -> 795,525 +920,548 -> 920,718 +421,264 -> 714,557 +635,310 -> 635,983 +751,479 -> 534,696 +121,768 -> 121,129 +679,858 -> 737,858 +499,549 -> 603,653 +398,95 -> 398,537 +459,626 -> 473,626 +611,905 -> 854,662 +139,124 -> 568,124 +230,921 -> 960,191 +550,258 -> 883,258 +866,830 -> 681,645 +501,840 -> 774,840 +383,900 -> 383,536 +635,690 -> 868,690 +37,948 -> 954,31 +785,598 -> 785,955 +844,957 -> 130,243 +395,307 -> 562,307 +463,286 -> 374,286 +798,351 -> 52,351 +549,79 -> 549,300 +153,847 -> 977,23 +499,976 -> 499,576 +687,281 -> 621,215 +765,640 -> 794,640 +776,287 -> 906,157 +879,108 -> 333,108 +340,565 -> 340,521 +706,809 -> 159,262 +725,896 -> 941,896 +673,470 -> 792,470 +446,562 -> 638,754 +315,626 -> 189,500 +816,637 -> 77,637 +171,313 -> 171,82 +941,19 -> 150,810 +885,854 -> 513,854 +864,177 -> 864,213 +156,150 -> 544,538 +810,20 -> 344,486 +651,757 -> 623,729 +567,475 -> 126,475 +436,975 -> 707,975 +948,977 -> 138,167 +498,186 -> 601,289 +532,900 -> 532,515 +12,809 -> 60,761 +561,344 -> 453,452 +241,600 -> 780,61 +600,574 -> 258,232 +53,661 -> 224,490 +735,134 -> 735,707 +850,14 -> 398,14 +472,489 -> 472,22 +949,196 -> 492,196 +220,30 -> 959,769 +354,889 -> 632,889 +779,537 -> 397,919 +136,876 -> 896,116 +12,983 -> 930,65 +716,856 -> 716,516 +595,604 -> 595,97 +863,70 -> 946,70 +13,988 -> 988,13 +595,955 -> 978,955 +138,300 -> 138,452 +801,883 -> 830,854 +189,13 -> 110,13 +315,68 -> 147,68 +594,977 -> 594,707 +424,726 -> 836,314 +596,790 -> 842,790 +135,135 -> 823,823 +257,639 -> 718,178 +462,859 -> 965,859 +935,29 -> 18,946 +308,841 -> 676,473 +372,607 -> 946,607 +518,806 -> 201,489 +620,689 -> 620,480 +376,378 -> 376,900 +86,675 -> 179,768 +509,790 -> 509,501 +778,143 -> 778,474 +965,140 -> 194,911 +621,458 -> 316,153 +83,931 -> 959,55 +533,647 -> 402,778 +957,336 -> 397,336 +929,788 -> 929,587 +642,978 -> 647,978 +429,275 -> 276,275 +662,821 -> 120,279 +137,208 -> 85,260 +815,641 -> 763,589 +222,510 -> 881,510 +892,930 -> 845,930 +288,268 -> 288,509 +900,13 -> 79,13 +438,764 -> 248,764 +391,495 -> 391,771 +868,713 -> 223,68 +680,180 -> 680,553 +911,389 -> 911,578 +107,182 -> 107,555 +944,787 -> 944,25 +405,193 -> 569,193 +341,182 -> 952,182 +497,197 -> 820,197 +204,224 -> 693,224 +342,290 -> 342,479 +881,281 -> 881,899 +971,987 -> 11,27 +389,729 -> 501,729 +638,939 -> 316,617 +923,799 -> 923,84 +17,744 -> 17,47 +305,163 -> 305,506 +703,414 -> 74,414 +572,537 -> 122,987 +385,364 -> 385,403 +667,825 -> 667,607 +466,86 -> 842,86 +591,209 -> 151,649 +329,526 -> 329,772 +756,769 -> 122,135 +638,454 -> 380,454 +316,98 -> 654,98 +273,740 -> 627,386 +88,982 -> 963,107 +913,710 -> 913,157 +530,410 -> 129,410 +660,237 -> 256,641 +865,149 -> 865,934 +769,47 -> 76,740 +520,876 -> 520,630 +101,839 -> 394,546 +422,874 -> 330,874 +987,19 -> 20,986 +398,771 -> 174,771 +574,546 -> 582,546 +896,52 -> 11,937 +927,927 -> 927,923 +111,822 -> 953,822 +633,130 -> 76,130 +193,74 -> 193,400 +887,828 -> 887,160 +284,313 -> 500,97 +813,500 -> 839,500 +312,534 -> 129,534 +202,34 -> 202,196 +740,597 -> 681,597 +37,979 -> 892,124 +494,235 -> 494,426 +334,892 -> 334,788 +679,728 -> 947,728 +635,557 -> 242,950 +301,713 -> 326,738 +261,867 -> 986,867 +959,344 -> 412,891 +605,659 -> 647,701 +806,931 -> 270,395 +546,107 -> 150,107 +836,793 -> 131,88 +231,572 -> 99,572 +257,580 -> 257,459 +254,669 -> 254,52 +105,26 -> 973,894 +101,532 -> 339,770 +854,695 -> 319,160 +599,190 -> 227,562 +783,816 -> 370,816 +505,638 -> 889,638 +742,615 -> 742,399 +984,750 -> 984,662 +295,736 -> 937,94 +762,435 -> 239,958 +876,89 -> 758,89 +178,964 -> 651,964 +385,389 -> 67,71 +514,967 -> 462,915 +819,758 -> 819,978 +541,109 -> 767,109 +137,262 -> 137,815 +720,591 -> 934,805 +56,79 -> 752,775 +493,519 -> 493,278 +202,718 -> 202,344 +665,24 -> 446,24 +426,845 -> 426,193 +116,930 -> 982,64 +625,587 -> 625,908 +13,965 -> 919,59 +124,466 -> 124,194 +793,249 -> 480,562 +20,174 -> 359,174 +982,988 -> 25,31 +71,416 -> 586,416 +157,122 -> 363,122 +31,453 -> 344,453 +435,284 -> 387,284 +389,446 -> 379,446 +913,536 -> 32,536 +505,952 -> 505,495 +489,159 -> 222,426 +267,118 -> 954,805 +15,833 -> 15,323 +77,197 -> 946,197 +955,22 -> 955,798 +620,707 -> 620,915 +740,495 -> 740,334 +770,735 -> 770,184 +420,524 -> 420,108 +382,982 -> 556,982 +111,777 -> 867,21 +280,105 -> 915,740 +235,23 -> 863,651 +679,402 -> 197,884 +72,77 -> 829,834 +858,486 -> 443,486 +403,115 -> 403,342 +489,547 -> 489,53 +404,280 -> 950,826 +680,458 -> 260,458 +10,610 -> 315,915 +386,630 -> 128,888 +293,732 -> 293,861 +204,378 -> 116,378 +90,269 -> 90,173 +893,869 -> 92,68 +741,694 -> 741,136 +620,449 -> 620,62 +866,678 -> 441,253 +885,212 -> 167,930 +868,853 -> 868,852 +392,926 -> 982,336 +252,930 -> 829,930 +758,606 -> 949,606 +79,895 -> 798,176 +394,688 -> 901,688 +355,217 -> 355,732 +43,23 -> 903,883 +426,691 -> 695,422 +970,416 -> 970,950 +317,334 -> 957,974 +198,160 -> 198,195 +610,191 -> 852,191 +388,569 -> 899,58 +490,662 -> 517,689 +691,627 -> 643,627 +404,564 -> 539,564 +946,623 -> 478,155 +686,608 -> 686,213 +573,508 -> 47,508 +610,262 -> 610,905 +782,602 -> 581,602 +987,378 -> 987,391 +443,243 -> 447,243 +710,493 -> 54,493 +564,179 -> 564,966 +828,673 -> 828,691 +761,869 -> 260,869 +810,949 -> 192,331 +674,263 -> 467,263 +481,81 -> 940,540 +779,301 -> 159,301 +763,457 -> 574,646 +794,770 -> 784,780 +19,964 -> 973,10 +809,720 -> 809,142 +822,324 -> 822,112 +120,980 -> 354,980 +238,277 -> 636,675 +747,647 -> 550,450 +419,205 -> 419,494 +34,968 -> 719,283 +306,591 -> 401,496 +648,673 -> 526,795 +486,426 -> 44,426 +441,642 -> 137,338 +396,740 -> 585,740 +741,227 -> 117,851 +620,263 -> 319,263 +421,321 -> 300,321 +732,387 -> 732,784 +445,59 -> 445,273 +151,910 -> 220,841 +836,599 -> 274,599 +598,193 -> 95,193 +718,765 -> 884,931 +403,165 -> 591,165 +241,441 -> 736,441 +902,986 -> 190,274 +190,671 -> 190,342 +887,301 -> 887,216 +878,747 -> 244,113 +93,747 -> 814,26 +764,604 -> 764,444 +510,852 -> 175,852 +50,718 -> 132,718 +791,436 -> 95,436 +751,122 -> 751,146 +953,162 -> 953,168 +113,546 -> 113,828 +752,407 -> 482,407 +398,412 -> 305,412 +912,630 -> 830,630 +699,155 -> 354,155 +842,874 -> 451,483 +18,83 -> 580,645 +63,594 -> 945,594 +557,286 -> 557,773 +21,448 -> 21,11 +955,724 -> 955,353 +857,411 -> 857,41 +605,932 -> 605,159 +985,64 -> 216,833 +34,673 -> 610,97 +888,764 -> 888,415 +574,801 -> 646,801 +290,593 -> 290,694 +151,72 -> 887,808 +632,53 -> 632,98 +346,686 -> 963,69 +258,129 -> 582,453 +189,205 -> 646,662 +272,821 -> 946,147 +409,531 -> 462,478 +725,575 -> 894,575 +885,888 -> 885,878 +475,210 -> 763,210 +42,963 -> 920,85 +985,213 -> 271,213 +538,842 -> 482,842 +175,529 -> 662,529 +853,670 -> 259,76 +656,364 -> 373,647 +114,134 -> 827,134 +58,878 -> 58,569 +45,340 -> 684,979 +35,829 -> 611,829 +625,166 -> 625,898 +849,980 -> 143,980 +720,92 -> 330,92 +689,255 -> 689,389 +842,526 -> 867,526 +834,399 -> 395,838 +325,212 -> 786,673 +934,941 -> 31,38 +211,640 -> 812,39 +449,896 -> 82,896 +795,757 -> 630,592 +894,691 -> 894,11 +639,839 -> 639,360 +941,862 -> 676,862 +480,757 -> 480,123 +425,734 -> 425,332 +391,704 -> 350,745 +173,352 -> 131,352 +814,703 -> 814,150 +347,156 -> 609,156 +427,520 -> 862,520 +787,724 -> 206,724 +313,587 -> 312,587 +743,491 -> 743,580 +277,964 -> 845,396 +132,65 -> 864,797 +227,619 -> 227,365 +360,484 -> 299,484 +717,790 -> 875,790 +798,480 -> 413,95 +643,518 -> 643,407 +939,530 -> 440,31 +241,44 -> 241,82 +362,49 -> 316,49 +160,98 -> 382,98 +67,593 -> 508,593 +363,456 -> 470,456 +644,63 -> 273,63 +341,696 -> 72,696 +270,303 -> 270,60 +716,391 -> 716,983 +678,904 -> 756,826 +480,487 -> 290,487 +762,316 -> 762,969 +380,735 -> 380,652 +223,922 -> 436,709 +690,733 -> 815,733 +185,130 -> 555,130 +10,931 -> 924,17 +678,940 -> 891,940 +702,112 -> 702,673 +554,559 -> 812,301 +406,758 -> 377,758 +361,119 -> 96,384 +787,356 -> 787,963 +957,54 -> 23,988 +636,650 -> 34,48 +170,21 -> 170,541 +955,103 -> 85,973 +144,698 -> 381,698 +85,55 -> 925,895 +12,15 -> 978,981 +32,954 -> 32,301 +438,234 -> 195,477 +121,438 -> 121,542 +353,607 -> 919,607 +978,646 -> 978,643 +925,112 -> 925,646 +447,120 -> 447,104 +332,398 -> 568,162 +399,841 -> 276,841 +923,853 -> 923,820 +890,202 -> 964,202 +306,782 -> 871,217 +547,558 -> 21,32 +893,164 -> 508,549 +485,76 -> 361,76 +713,768 -> 570,768 +314,18 -> 461,18 +618,281 -> 715,281 +374,787 -> 374,209 +324,97 -> 405,97 +890,729 -> 566,729 +762,438 -> 762,978 +274,49 -> 274,525 +905,34 -> 905,741 +799,384 -> 799,742 +378,358 -> 378,17 +805,131 -> 31,905 +640,453 -> 640,800 +563,305 -> 563,945 +898,590 -> 57,590 +513,187 -> 513,76 +706,407 -> 500,407 +235,69 -> 861,695 +408,259 -> 624,43 +327,308 -> 722,308 +109,247 -> 183,247 +487,493 -> 619,625 +769,452 -> 899,452 +727,765 -> 524,968 +887,472 -> 801,472 +157,100 -> 936,879 +584,658 -> 584,582 +557,488 -> 557,510 +790,35 -> 28,797 +458,920 -> 350,812 +54,797 -> 790,61 +59,387 -> 59,334 +565,368 -> 268,368 +70,146 -> 70,525 +681,451 -> 242,890 +869,831 -> 869,272 +276,184 -> 276,517 +984,922 -> 984,426 +616,572 -> 307,881 +323,806 -> 700,806 +595,547 -> 595,651 +731,638 -> 731,582 +760,836 -> 31,107 +768,377 -> 347,798 +847,765 -> 431,765 +777,95 -> 777,837 +832,330 -> 460,330 +423,213 -> 423,110 +937,549 -> 937,882 +529,735 -> 570,735 +436,343 -> 771,343 +965,833 -> 965,143 +518,484 -> 65,31 +940,989 -> 940,293 +983,63 -> 63,983 +237,733 -> 237,735 +624,281 -> 624,330 +473,719 -> 633,719 +312,489 -> 872,489 +369,520 -> 539,520 +80,705 -> 133,652 +659,289 -> 163,785 diff --git a/2021/05/solve.c b/2021/05/solve.c new file mode 100644 index 0000000..b0f6777 --- /dev/null +++ b/2021/05/solve.c @@ -0,0 +1,81 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#define FORLINE \ + char *line = NULL; \ + size_t len = 0; \ + while (getline(&line, &len, fp) != EOF) +#define FREELINE \ + if (line) \ + free(line) + +#define SIZE 1024 +static void solve(FILE *fp) +{ + int one = 0, two = 0; // Parts + + int *straight = calloc(4, SIZE * SIZE); + int *diagonal = calloc(4, SIZE * SIZE); + + FORLINE + { + int x1, y1, x2, y2; + sscanf(line, "%d,%d -> %d,%d\n", &x1, &y1, &x2, &y2); + + int xstart = x1 <= x2 ? x1 : x2; + int xend = x1 >= x2 ? x1 : x2; + + if (x1 == x2 || y1 == y2) { // Straight + int ystart = y1 <= y2 ? y1 : y2; + int yend = y1 >= y2 ? y1 : y2; + + for (int y = ystart; y <= yend; y++) { + for (int x = xstart; x <= xend; x++) { + straight[y * SIZE + x]++; + diagonal[y * SIZE + x]++; + } + } + } else { // Diagonal + int xneg = x1 > x2 ? -1 : 1; + int yneg = y1 > y2 ? -1 : 1; + for (int a = 0; xstart + a <= xend; a++) + diagonal[(y1 + a * yneg) * SIZE + (x1 + a * xneg)]++; + } + } + FREELINE; + + for (int y = 0; y < SIZE; y++) { + for (int x = 0; x < SIZE; x++) { + if (straight[y * SIZE + x] >= 2) + one++; + if (diagonal[y * SIZE + x] >= 2) + two++; + } + } + + free(straight); + free(diagonal); + + printf("%d\n", one); + printf("%d\n", two); +} + +int main(int argc, char *argv[]) +{ + (void)argc; + (void)argv; + + FILE *fp = fopen("input", "r"); + if (!fp) + exit(EXIT_FAILURE); + + clock_t tic = clock(); + solve(fp); + clock_t toc = clock(); + printf("TIME: %f seconds\n", (double)(toc - tic) / CLOCKS_PER_SEC); + + fclose(fp); + return 0; +} |