From e163794fdc39c44e38c82f4de4d067dc2356986c Mon Sep 17 00:00:00 2001 From: Mia Herkt Date: Mon, 13 Dec 2021 13:46:53 +0100 Subject: [PATCH] Day 13: Add C solution --- 13/input.txt | 817 ++++++++++++++++++++++++++++++++++++++++++++++++++ 13/solution.c | 40 +++ 2 files changed, 857 insertions(+) create mode 100644 13/input.txt create mode 100644 13/solution.c diff --git a/13/input.txt b/13/input.txt new file mode 100644 index 0000000..2774d37 --- /dev/null +++ b/13/input.txt @@ -0,0 +1,817 @@ +323,305 +512,845 +780,175 +308,50 +266,604 +152,425 +199,618 +214,572 +977,596 +1113,756 +1019,316 +972,322 +1181,138 +785,756 +504,378 +597,537 +1068,485 +738,108 +437,359 +1163,567 +585,549 +490,527 +616,5 +258,605 +1265,473 +728,421 +659,626 +162,781 +725,549 +165,23 +1148,554 +169,710 +388,290 +989,746 +619,361 +951,850 +1136,770 +592,284 +298,430 +441,408 +1014,534 +147,77 +822,429 +1210,162 +109,647 +65,605 +319,595 +535,315 +691,420 +266,290 +127,824 +435,779 +306,161 +248,653 +23,478 +751,276 +1295,752 +60,855 +1041,757 +639,773 +564,757 +1295,142 +1158,21 +311,868 +1265,421 +1285,884 +89,26 +45,677 +358,222 +261,880 +216,173 +440,213 +738,666 +1183,294 +527,829 +447,483 +112,225 +970,364 +269,137 +1163,631 +1004,161 +952,584 +616,889 +589,737 +957,275 +142,581 +238,131 +378,30 +152,770 +127,600 +311,569 +994,852 +180,254 +850,590 +1091,173 +927,115 +246,536 +574,341 +325,891 +460,590 +1004,682 +248,857 +629,660 +912,107 +850,30 +480,507 +454,691 +818,106 +802,142 +498,490 +112,290 +1019,644 +589,856 +256,339 +314,364 +186,191 +920,564 +119,747 +914,737 +566,131 +1203,372 +0,578 +807,121 +882,484 +805,477 +633,446 +438,309 +142,458 +485,354 +147,406 +1225,757 +873,359 +1039,235 +544,217 +825,51 +750,801 +818,815 +187,30 +360,325 +199,177 +1305,242 +569,757 +510,40 +853,756 +964,182 +1083,332 +1136,322 +1248,663 +187,526 +894,259 +470,173 +990,35 +457,427 +433,620 +1248,834 +169,582 +1158,737 +157,632 +459,626 +1289,112 +850,752 +62,834 +1200,777 +711,435 +1287,507 +82,532 +646,816 +80,756 +323,813 +691,690 +1016,569 +892,585 +557,350 +972,200 +179,38 +1083,226 +853,467 +1153,428 +1081,350 +1275,578 +856,203 +338,200 +157,578 +1300,246 +363,809 +1245,856 +857,691 +236,585 +950,325 +480,322 +525,875 +1046,508 +1125,110 +348,234 +985,443 +346,712 +818,113 +560,93 +1044,537 +1041,309 +53,269 +510,187 +110,777 +898,801 +1136,613 +694,453 +1044,290 +15,133 +1289,894 +1245,84 +562,374 +619,499 +482,144 +877,722 +1253,144 +868,256 +855,152 +1300,648 +691,586 +676,234 +1275,196 +652,247 +144,259 +668,516 +460,870 +843,365 +281,809 +351,556 +494,656 +1290,749 +554,746 +527,294 +353,499 +996,812 +880,353 +1153,578 +119,203 +15,142 +393,761 +816,208 +0,92 +557,296 +460,534 +117,5 +766,117 +231,276 +507,775 +1245,810 +1111,600 +363,44 +110,341 +1305,298 +338,710 +227,668 +343,868 +850,669 +72,197 +870,233 +497,276 +800,707 +336,750 +72,25 +738,786 +1265,453 +1181,427 +480,572 +311,89 +157,170 +922,255 +179,182 +1002,498 +634,301 +825,312 +843,529 +398,787 +209,560 +438,361 +490,336 +1203,277 +135,872 +321,302 +57,144 +987,589 +1029,670 +1200,677 +1285,10 +594,639 +1193,633 +320,859 +8,816 +20,145 +649,596 +756,430 +490,367 +803,119 +773,185 +851,626 +266,703 +492,781 +343,569 +768,793 +634,833 +109,269 +872,585 +440,777 +246,470 +1153,262 +15,316 +1128,488 +594,761 +296,528 +1238,25 +748,374 +989,354 +1201,359 +412,409 +1292,171 +920,711 +721,352 +977,200 +457,756 +750,93 +682,96 +725,345 +1116,142 +964,712 +30,248 +1002,264 +1084,679 +1081,805 +355,246 +1250,639 +1014,254 +283,371 +127,177 +989,298 +453,203 +65,856 +169,354 +502,59 +373,229 +187,309 +1126,143 +1250,581 +291,250 +569,529 +636,764 +383,779 +1210,264 +117,633 +565,110 +460,478 +518,409 +825,876 +333,694 +631,416 +599,459 +152,280 +1126,173 +542,792 +271,235 +569,137 +785,875 +1153,316 +333,724 +512,591 +957,499 +999,325 +512,581 +435,721 +231,724 +1004,733 +100,264 +488,465 +846,572 +674,764 +836,864 +800,75 +980,768 +65,220 +850,416 +343,343 +835,856 +470,537 +460,30 +321,536 +182,187 +1191,131 +463,424 +474,254 +321,540 +31,850 +85,757 +803,631 +152,852 +505,477 +910,249 +333,802 +766,217 +464,322 +147,567 +763,372 +1128,406 +502,322 +537,409 +904,205 +321,648 +525,756 +544,777 +679,478 +346,182 +490,760 +825,746 +952,310 +62,679 +18,746 +348,857 +999,327 +117,392 +1292,723 +880,541 +281,869 +773,236 +248,205 +753,350 +119,147 +808,59 +830,572 +264,576 +1052,289 +1067,322 +1191,147 +346,731 +467,365 +1198,604 +552,353 +266,357 +480,59 +30,672 +1128,187 +880,31 +996,530 +1113,138 +502,729 +147,460 +1193,502 +333,799 +745,334 +408,536 +328,313 +494,208 +271,211 +982,114 +238,579 +716,761 +1179,850 +219,280 +830,281 +592,215 +328,786 +863,483 +485,648 +440,98 +669,29 +109,625 +1124,191 +589,84 +164,367 +1039,504 +69,560 +741,529 +470,50 +199,742 +437,535 +989,799 +686,248 +991,299 +112,604 +475,856 +184,50 +226,231 +1002,182 +129,467 +457,467 +855,45 +1245,289 +5,652 +338,470 +267,555 +15,752 +72,869 +311,855 +475,712 +1175,872 +504,516 +247,12 +3,813 +582,645 +1163,775 +974,144 +217,712 +152,21 +633,275 +21,446 +162,554 +343,39 +557,213 +1136,611 +1068,37 +897,473 +1007,142 +592,610 +979,813 +1230,536 +609,339 +902,536 +736,553 +194,640 +1310,578 +378,478 +1275,462 +467,368 +947,872 +830,59 +659,529 +783,276 +430,31 +1131,182 +741,305 +1305,652 +855,618 +639,142 +10,54 +1044,156 +174,611 +493,471 +492,106 +870,322 +316,852 +701,555 +920,186 +112,792 +1098,270 +438,809 +398,555 +686,222 +1164,304 +1228,532 +1074,585 +127,294 +1163,406 +1131,38 +1279,492 +820,880 +1191,763 +482,592 +1158,469 +661,806 +199,294 +80,134 +746,757 +1198,290 +967,262 +60,581 +1111,275 +428,679 +291,316 +65,457 +32,673 +117,684 +711,420 +766,397 +35,698 +323,589 +825,18 +976,490 +718,4 +745,784 +537,658 +1044,39 +1111,294 +952,528 +808,490 +219,721 +676,833 +1123,526 +431,787 +187,611 +460,304 +97,598 +209,334 +227,332 +348,733 +172,368 +385,361 +35,204 +920,330 +619,756 +641,29 +1255,420 +174,283 +15,119 +962,485 +920,708 +447,147 +989,302 +1101,782 +340,530 +165,871 +1007,30 +1225,589 +1148,340 +320,707 +172,144 +182,747 +800,676 +604,550 +972,470 +535,147 +681,884 +753,744 +691,361 +226,36 +1201,269 +1265,665 +433,674 +1153,632 +110,117 +1096,572 +316,42 +1248,610 +738,413 +1011,694 +686,360 +1288,754 +604,553 +22,754 +477,641 +321,298 +885,350 +1072,763 +877,805 +126,467 +535,579 +55,196 +1163,460 +898,485 +199,724 +977,802 +169,802 +413,421 +1158,165 +18,316 +1123,368 +820,134 +718,610 +624,222 +1278,221 +455,605 +870,661 +1111,177 +1310,316 +574,760 +318,750 +1265,677 +152,56 +990,859 +507,142 +718,215 +1307,813 +838,147 +798,49 +49,486 +1138,368 +445,670 +103,339 +674,130 +999,474 +527,618 +825,582 +197,756 +1280,646 +701,441 +1196,718 +1029,224 +308,498 +470,261 +813,276 +1131,108 +651,529 +569,305 +1062,857 +741,757 +592,890 +1295,295 +972,710 +187,864 +709,247 +907,842 +741,137 +291,764 +557,96 +927,698 +1044,191 +238,187 +527,65 +547,372 +1158,770 +340,628 +21,894 +721,674 +927,196 +1287,478 +1041,361 +537,185 +1198,796 +1198,156 +1049,133 +502,381 +748,53 +1131,712 +977,694 +907,108 +964,264 +169,312 +485,312 +843,368 +455,45 +425,798 +475,12 +15,540 +393,374 +1125,334 +318,144 +146,478 +207,131 +840,261 +455,401 +1029,809 +803,142 +306,37 +152,614 +812,490 +468,639 +582,249 +31,44 +870,669 +1144,877 +999,773 +545,199 +400,249 +231,618 +140,639 +609,453 +65,542 +1136,572 +853,427 +266,156 +482,302 +117,658 +877,674 +808,165 +649,592 +1113,586 +1062,653 +783,518 +1059,786 +490,880 +850,192 +132,198 +972,872 +1093,712 +870,213 +1141,354 +1014,366 +485,876 +226,663 +691,196 +60,255 +887,724 +55,698 +694,889 +194,142 +5,596 +1310,92 +639,121 +1072,187 +691,200 +314,812 +1063,12 +932,416 +1168,709 +705,486 +1272,217 +214,225 +989,358 +65,437 +1158,56 +475,38 +38,217 +678,588 +311,26 +840,751 +1207,339 + +fold along x=655 +fold along y=447 +fold along x=327 +fold along y=223 +fold along x=163 +fold along y=111 +fold along x=81 +fold along y=55 +fold along x=40 +fold along y=27 +fold along y=13 +fold along y=6 \ No newline at end of file diff --git a/13/solution.c b/13/solution.c new file mode 100644 index 0000000..0439dd1 --- /dev/null +++ b/13/solution.c @@ -0,0 +1,40 @@ +#include +#include +#include + + + int Q + #define U\ + x=D[i] >> 32, \ + y= D[i] & 0xffffffff + (const void * A, const + void*B){int64_t a= *(int64_t + + *) A,b=*( + int64_t*)B; + return a>b?a + /************************/ + a)D= realloc(D, /*************/ sizeof( + int64_t)*(a+=500)) /**/ ;D[n++]=(L<<32) |R;} + while(scanf("%*" "[^xy]%c=%ld\n",&c,&L )==2) + {for(i =0;iL) x=2*L-x + ;else if(c=='y'&&y>L)y=2*L-y;D[i]= y|(x<<32) + ;}qsort(D,n,sizeof(int64_t),Q);for(i=1,l=D[0 ];i0;i--){if(D[i ]==-1)n=i;}if( + !t)t=n;}printf("%lu dots left " "after first fol" + "d instruction\n",t);for( i=0;iX ?x:X;Y=y>Y ?y:Y;}char O[X*Y]; + memset(O,' ',X*Y );for(i=0;i