diff options
Diffstat (limited to 'Advent-of-Code-2021')
56 files changed, 7485 insertions, 0 deletions
diff --git a/Advent-of-Code-2021/AOC-1/aoc-1 b/Advent-of-Code-2021/AOC-1/aoc-1 Binary files differnew file mode 100755 index 0000000..eb5fe13 --- /dev/null +++ b/Advent-of-Code-2021/AOC-1/aoc-1 diff --git a/Advent-of-Code-2021/AOC-1/aoc-1.c b/Advent-of-Code-2021/AOC-1/aoc-1.c new file mode 100644 index 0000000..5574481 --- /dev/null +++ b/Advent-of-Code-2021/AOC-1/aoc-1.c @@ -0,0 +1,81 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define N 5000 + +int numbers[N]; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if (fp == NULL) + { + perror("Error while opening the file.\n"); + exit(EXIT_FAILURE); + } + + int i = 0; + int n = 0; + char *str = malloc(sizeof(char)*N); + while((ch= fgetc(fp)) != EOF) + { + if(ch != '\n') + { + str[i] = ch; + i += 1; + } + else + { + i = 0; + numbers[n] = atoi(str); + n += 1; + memset(str, ' ', sizeof(char)*N); + } + } + + free(str); + + fclose(fp); +} + +void PrintNumbers() +{ + for(int i=0; i<N; i++) + { + printf("%d\n", numbers[i]); + } +} + +int main (void) +{ + ParseInput("input-1.txt"); + + /* Part One + int bigger = 0; + for(int i=1; i<N; i++) + { + if(numbers[i] > numbers[(i-1)]) + bigger += 1; + } + + printf("Answer: %d", bigger); + */ + + // Part Two + int bigger = 0; + for(int i = 3; i<N; i++) + { + if( + (numbers[i-2] + numbers[i-1] + numbers[i]) > + (numbers[i-3] + numbers[i-2] + numbers[i -1])) + bigger += 1; + } + + printf("Answer: %d", bigger); + + return 0; +} diff --git a/Advent-of-Code-2021/AOC-1/aoc-1.c~ b/Advent-of-Code-2021/AOC-1/aoc-1.c~ new file mode 100644 index 0000000..4525d8c --- /dev/null +++ b/Advent-of-Code-2021/AOC-1/aoc-1.c~ @@ -0,0 +1 @@ +#includ diff --git a/Advent-of-Code-2021/AOC-1/input-1.txt b/Advent-of-Code-2021/AOC-1/input-1.txt new file mode 100644 index 0000000..0bed5fe --- /dev/null +++ b/Advent-of-Code-2021/AOC-1/input-1.txt @@ -0,0 +1,2000 @@ +159 +158 +174 +196 +197 +194 +209 +213 +214 +222 +223 +228 +229 +236 +237 +238 +241 +248 +255 +256 +257 +269 +276 +292 +302 +304 +308 +309 +311 +315 +314 +320 +323 +324 +329 +330 +311 +340 +341 +342 +341 +347 +349 +350 +367 +370 +378 +379 +378 +379 +389 +390 +393 +388 +393 +402 +405 +404 +402 +410 +411 +441 +449 +448 +449 +450 +412 +414 +415 +418 +420 +440 +439 +458 +459 +457 +463 +465 +469 +470 +479 +480 +481 +482 +475 +468 +467 +472 +484 +486 +498 +489 +493 +511 +510 +493 +495 +494 +514 +517 +520 +521 +544 +557 +563 +565 +568 +572 +571 +572 +575 +584 +583 +599 +600 +605 +612 +615 +618 +625 +627 +633 +663 +665 +666 +669 +683 +706 +716 +722 +731 +734 +739 +741 +754 +760 +765 +783 +788 +795 +811 +813 +818 +805 +816 +821 +829 +830 +854 +855 +850 +859 +860 +866 +867 +866 +867 +874 +875 +876 +870 +875 +878 +880 +884 +898 +915 +918 +922 +923 +949 +942 +945 +949 +970 +956 +969 +964 +972 +973 +975 +974 +970 +989 +990 +993 +994 +1002 +1003 +1007 +1013 +1025 +1035 +1033 +1040 +1045 +1055 +1056 +1057 +1059 +1060 +1063 +1051 +1056 +1057 +1047 +1054 +1055 +1051 +1052 +1058 +1061 +1066 +1067 +1070 +1074 +1075 +1076 +1084 +1122 +1128 +1140 +1141 +1139 +1152 +1151 +1152 +1156 +1167 +1166 +1165 +1169 +1162 +1175 +1202 +1212 +1218 +1219 +1240 +1238 +1224 +1230 +1245 +1253 +1285 +1295 +1297 +1309 +1323 +1329 +1333 +1336 +1339 +1318 +1321 +1318 +1345 +1347 +1349 +1352 +1353 +1360 +1358 +1345 +1352 +1356 +1357 +1370 +1373 +1393 +1423 +1424 +1431 +1447 +1454 +1444 +1470 +1477 +1479 +1485 +1483 +1497 +1518 +1536 +1539 +1544 +1549 +1558 +1557 +1581 +1585 +1591 +1632 +1633 +1636 +1639 +1633 +1637 +1638 +1639 +1640 +1642 +1658 +1676 +1675 +1707 +1708 +1709 +1710 +1711 +1715 +1707 +1712 +1733 +1734 +1732 +1722 +1730 +1746 +1747 +1748 +1749 +1755 +1759 +1771 +1772 +1771 +1770 +1771 +1773 +1772 +1771 +1780 +1781 +1782 +1781 +1775 +1786 +1798 +1814 +1818 +1826 +1791 +1793 +1796 +1821 +1822 +1825 +1834 +1838 +1867 +1907 +1908 +1910 +1921 +1926 +1924 +1921 +1941 +1945 +1958 +1957 +1978 +1973 +1974 +1977 +1978 +1984 +1992 +1998 +2002 +1998 +1993 +1984 +2013 +2014 +2017 +2016 +2019 +2024 +2031 +2032 +2042 +2041 +2047 +2055 +2057 +2059 +2066 +2086 +2090 +2091 +2094 +2112 +2113 +2123 +2125 +2123 +2124 +2135 +2152 +2155 +2158 +2157 +2169 +2168 +2166 +2167 +2168 +2185 +2190 +2189 +2190 +2198 +2170 +2171 +2177 +2184 +2186 +2187 +2162 +2174 +2175 +2172 +2180 +2182 +2188 +2213 +2226 +2228 +2227 +2216 +2220 +2221 +2220 +2212 +2215 +2220 +2223 +2226 +2228 +2236 +2237 +2238 +2258 +2257 +2256 +2260 +2261 +2271 +2294 +2297 +2309 +2311 +2327 +2326 +2340 +2339 +2342 +2343 +2346 +2352 +2363 +2364 +2371 +2386 +2387 +2392 +2401 +2407 +2415 +2418 +2432 +2457 +2458 +2459 +2461 +2463 +2464 +2465 +2486 +2487 +2490 +2509 +2510 +2518 +2522 +2525 +2527 +2521 +2522 +2526 +2529 +2530 +2552 +2548 +2564 +2566 +2568 +2569 +2570 +2565 +2576 +2577 +2581 +2582 +2587 +2588 +2568 +2569 +2563 +2575 +2576 +2577 +2578 +2588 +2603 +2604 +2605 +2620 +2622 +2627 +2630 +2639 +2629 +2631 +2632 +2644 +2646 +2655 +2658 +2663 +2660 +2659 +2657 +2655 +2656 +2657 +2658 +2669 +2679 +2678 +2684 +2677 +2721 +2728 +2729 +2728 +2729 +2730 +2733 +2742 +2730 +2731 +2733 +2735 +2740 +2750 +2746 +2748 +2751 +2771 +2786 +2792 +2797 +2799 +2803 +2814 +2825 +2832 +2839 +2844 +2854 +2833 +2842 +2844 +2866 +2868 +2871 +2872 +2876 +2877 +2901 +2910 +2916 +2940 +2951 +2966 +2967 +2972 +2976 +2978 +2977 +2980 +2993 +3004 +3005 +3031 +3030 +3036 +3035 +3038 +3041 +3040 +3043 +3046 +3068 +3080 +3081 +3101 +3104 +3111 +3118 +3119 +3112 +3111 +3113 +3140 +3165 +3164 +3174 +3184 +3200 +3183 +3185 +3187 +3188 +3197 +3215 +3233 +3232 +3243 +3220 +3221 +3224 +3226 +3263 +3275 +3286 +3287 +3300 +3304 +3314 +3316 +3311 +3314 +3324 +3325 +3329 +3347 +3341 +3346 +3348 +3363 +3369 +3396 +3384 +3390 +3391 +3394 +3393 +3399 +3405 +3411 +3417 +3408 +3378 +3383 +3379 +3385 +3386 +3406 +3397 +3374 +3378 +3373 +3358 +3357 +3381 +3387 +3422 +3420 +3415 +3416 +3432 +3419 +3422 +3423 +3436 +3437 +3439 +3441 +3449 +3453 +3488 +3499 +3513 +3536 +3576 +3570 +3569 +3570 +3571 +3575 +3573 +3617 +3594 +3589 +3587 +3596 +3583 +3588 +3589 +3583 +3594 +3612 +3617 +3634 +3628 +3629 +3630 +3640 +3642 +3647 +3644 +3657 +3658 +3657 +3660 +3661 +3662 +3681 +3684 +3694 +3698 +3697 +3707 +3709 +3710 +3723 +3741 +3747 +3752 +3753 +3747 +3751 +3756 +3752 +3781 +3800 +3804 +3792 +3809 +3805 +3806 +3812 +3813 +3814 +3818 +3820 +3835 +3836 +3837 +3806 +3812 +3837 +3840 +3845 +3842 +3879 +3880 +3890 +3919 +3927 +3929 +3920 +3916 +3928 +3892 +3865 +3876 +3913 +3933 +3934 +3901 +3902 +3903 +3909 +3910 +3911 +3912 +3920 +3949 +3944 +3946 +3947 +3963 +3976 +3977 +3979 +3985 +3997 +4006 +4014 +4021 +4026 +4030 +4031 +4054 +4044 +4045 +4055 +4053 +4051 +4055 +4068 +4066 +4068 +4069 +4072 +4071 +4063 +4064 +4067 +4075 +4099 +4140 +4141 +4172 +4171 +4172 +4182 +4191 +4192 +4194 +4201 +4207 +4211 +4213 +4220 +4258 +4257 +4256 +4258 +4271 +4270 +4263 +4265 +4266 +4292 +4290 +4297 +4298 +4299 +4316 +4333 +4335 +4346 +4349 +4354 +4355 +4357 +4373 +4371 +4361 +4366 +4369 +4373 +4374 +4378 +4380 +4394 +4395 +4400 +4406 +4412 +4419 +4417 +4424 +4440 +4443 +4449 +4459 +4461 +4466 +4461 +4463 +4462 +4464 +4472 +4475 +4476 +4478 +4464 +4481 +4483 +4493 +4504 +4505 +4513 +4516 +4527 +4526 +4514 +4515 +4544 +4545 +4560 +4562 +4561 +4573 +4572 +4571 +4592 +4600 +4589 +4606 +4612 +4628 +4629 +4597 +4623 +4624 +4619 +4620 +4636 +4637 +4647 +4649 +4650 +4653 +4655 +4663 +4681 +4677 +4696 +4698 +4704 +4709 +4706 +4696 +4698 +4697 +4698 +4711 +4716 +4740 +4741 +4742 +4743 +4740 +4750 +4742 +4745 +4753 +4754 +4755 +4756 +4757 +4758 +4788 +4791 +4802 +4811 +4800 +4808 +4817 +4789 +4809 +4820 +4821 +4802 +4804 +4805 +4807 +4808 +4799 +4810 +4807 +4806 +4791 +4801 +4808 +4818 +4828 +4841 +4837 +4841 +4860 +4880 +4909 +4913 +4910 +4909 +4925 +4927 +4929 +4932 +4933 +4932 +4933 +4949 +4938 +4940 +4930 +4944 +4950 +4944 +4957 +4967 +4973 +4979 +4974 +4962 +4949 +4950 +4952 +4956 +4961 +4962 +4981 +4983 +4985 +5000 +5001 +5004 +5031 +5035 +5036 +5037 +5040 +5048 +5057 +5056 +5045 +5047 +5031 +5034 +5036 +5047 +5065 +5068 +5069 +5053 +5046 +5043 +5048 +5050 +5059 +5092 +5088 +5089 +5090 +5091 +5090 +5091 +5104 +5109 +5112 +5113 +5107 +5106 +5121 +5114 +5122 +5117 +5135 +5146 +5149 +5150 +5151 +5157 +5158 +5160 +5158 +5163 +5181 +5182 +5160 +5161 +5131 +5149 +5152 +5150 +5151 +5154 +5153 +5163 +5170 +5190 +5193 +5199 +5201 +5205 +5206 +5202 +5206 +5208 +5209 +5208 +5212 +5224 +5225 +5226 +5234 +5216 +5239 +5233 +5232 +5209 +5218 +5227 +5226 +5230 +5233 +5244 +5249 +5250 +5251 +5249 +5266 +5264 +5296 +5303 +5322 +5308 +5331 +5334 +5339 +5345 +5346 +5347 +5350 +5351 +5357 +5353 +5354 +5356 +5357 +5370 +5371 +5370 +5373 +5376 +5384 +5385 +5392 +5394 +5395 +5407 +5413 +5419 +5422 +5435 +5432 +5437 +5440 +5442 +5444 +5441 +5442 +5445 +5447 +5450 +5459 +5477 +5478 +5482 +5476 +5475 +5476 +5480 +5481 +5475 +5487 +5507 +5506 +5507 +5510 +5505 +5508 +5509 +5520 +5515 +5518 +5525 +5511 +5486 +5516 +5533 +5532 +5545 +5548 +5547 +5560 +5562 +5566 +5570 +5574 +5576 +5586 +5558 +5566 +5552 +5541 +5545 +5553 +5550 +5546 +5555 +5551 +5547 +5562 +5578 +5604 +5608 +5614 +5613 +5601 +5611 +5622 +5621 +5619 +5618 +5625 +5627 +5630 +5623 +5624 +5619 +5616 +5618 +5629 +5635 +5636 +5637 +5638 +5647 +5648 +5649 +5650 +5649 +5650 +5652 +5655 +5664 +5665 +5666 +5673 +5674 +5689 +5694 +5696 +5715 +5716 +5713 +5712 +5743 +5767 +5768 +5769 +5770 +5778 +5793 +5794 +5793 +5799 +5800 +5803 +5804 +5805 +5806 +5829 +5830 +5833 +5834 +5836 +5838 +5844 +5843 +5851 +5852 +5851 +5887 +5891 +5872 +5877 +5880 +5875 +5879 +5880 +5887 +5878 +5882 +5884 +5883 +5864 +5876 +5882 +5896 +5899 +5886 +5887 +5891 +5894 +5937 +5934 +5931 +5940 +5943 +5941 +5942 +5951 +5948 +5958 +5947 +5945 +5947 +5958 +5964 +5967 +5966 +5957 +5958 +5959 +5962 +5946 +5970 +5978 +5972 +5986 +5974 +5968 +5985 +5997 +6001 +6042 +6038 +6041 +6068 +6082 +6087 +6090 +6101 +6102 +6106 +6110 +6097 +6098 +6105 +6106 +6122 +6121 +6140 +6173 +6187 +6193 +6195 +6197 +6198 +6208 +6215 +6217 +6220 +6232 +6247 +6248 +6252 +6249 +6252 +6269 +6270 +6274 +6299 +6301 +6313 +6334 +6335 +6342 +6343 +6344 +6378 +6377 +6376 +6378 +6369 +6362 +6369 +6371 +6370 +6379 +6384 +6387 +6407 +6373 +6392 +6402 +6405 +6407 +6412 +6420 +6419 +6422 +6435 +6436 +6435 +6437 +6421 +6422 +6421 +6425 +6415 +6431 +6425 +6426 +6427 +6426 +6429 +6443 +6435 +6454 +6455 +6456 +6474 +6475 +6476 +6483 +6485 +6489 +6490 +6493 +6499 +6505 +6513 +6517 +6507 +6508 +6514 +6516 +6515 +6530 +6523 +6520 +6525 +6513 +6514 +6529 +6531 +6524 +6537 +6525 +6529 +6535 +6555 +6561 +6562 +6570 +6571 +6572 +6573 +6579 +6577 +6579 +6582 +6593 +6597 +6600 +6598 +6593 +6610 +6612 +6613 +6614 +6592 +6593 +6599 +6593 +6594 +6559 +6560 +6564 +6561 +6560 +6557 +6562 +6564 +6538 +6551 +6552 +6557 +6567 +6568 +6566 +6547 +6549 +6550 +6551 +6552 +6547 +6545 +6550 +6555 +6561 +6584 +6597 +6599 +6607 +6616 +6619 +6626 +6637 +6645 +6646 +6648 +6664 +6665 +6669 +6673 +6677 +6684 +6698 +6699 +6700 +6704 +6712 +6724 +6738 +6748 +6751 +6753 +6756 +6781 +6782 +6785 +6794 +6795 +6770 +6781 +6777 +6779 +6784 +6793 +6785 +6786 +6790 +6773 +6778 +6789 +6799 +6804 +6805 +6806 +6816 +6823 +6829 +6831 +6834 +6836 +6838 +6857 +6859 +6860 +6889 +6913 +6914 +6917 +6919 +6929 +6924 +6919 +6924 +6899 +6904 +6924 +6925 +6932 +6936 +6931 +6921 +6922 +6923 +6947 +6951 +6963 +6960 +6965 +6970 +6973 +6965 +6966 +6978 +7010 +7015 +7012 +7017 +7027 +7035 +7036 +7026 +7035 +7007 +7006 +6997 +6995 +7003 +7021 +7028 +7031 +7041 +7039 +7056 +7072 +7080 +7081 +7055 +7056 +7088 +7101 +7105 +7107 +7108 +7104 +7105 +7084 +7087 +7084 +7088 +7086 +7098 +7100 +7081 +7083 +7081 +7084 +7085 +7089 +7098 +7097 +7101 +7104 +7105 +7114 +7117 +7118 +7115 +7117 +7122 +7121 +7127 +7128 +7132 +7149 +7166 +7127 +7122 +7123 +7124 +7126 +7127 +7146 +7148 +7161 +7166 +7167 +7160 +7155 +7154 +7155 +7158 +7177 +7189 +7192 +7194 +7204 +7212 +7199 +7206 +7207 +7212 +7219 +7198 +7208 +7217 +7223 +7216 +7217 +7224 +7223 +7222 +7219 +7223 +7222 +7224 +7230 +7231 +7230 +7231 +7229 +7231 +7232 +7228 +7241 +7243 +7240 +7239 +7241 +7248 +7251 +7254 +7292 +7297 +7296 +7297 +7301 +7306 +7308 +7311 +7310 +7312 +7317 +7319 +7324 +7323 +7330 +7332 +7345 +7352 +7355 +7382 +7403 +7391 +7395 +7416 +7417 +7418 +7410 +7411 +7412 +7414 +7415 +7429 +7408 +7407 +7408 +7411 +7410 +7413 +7411 +7408 +7410 +7408 +7409 +7410 +7416 +7417 +7419 +7420 +7424 +7428 +7450 +7453 +7468 +7469 +7470 +7449 +7450 +7435 +7436 +7455 +7460 +7461 +7462 +7465 +7485 +7496 +7502 +7503 +7514 +7526 +7538 +7528 +7534 +7543 +7544 +7545 +7519 +7531 +7532 +7539 +7540 +7542 +7551 +7567 +7576 +7574 +7569 +7579 +7580 +7588 +7573 +7578 +7579 +7581 +7600 +7634 +7631 +7630 +7639 +7648 +7649 +7652 +7653 +7656 +7665 +7635 +7643 +7649 +7656 +7657 +7656 +7661 +7666 +7674 +7680 +7676 +7692 +7677 +7678 +7689 +7700 +7723 +7729 +7738 +7743 +7748 +7769 +7770 +7776 +7784 +7786 +7788 +7805 +7806 +7801 +7825 +7830 +7832 +7815 +7816 +7828 +7830 +7831 +7834 +7858 +7860 +7862 +7873 +7879 +7883 +7894 +7910 +7916 +7917 +7935 +7942 +7930 +7932 +7934 +7935 +7932 +7936 +7944 +7951 +7953 +7954 +7960 +7963 +7976 +7968 +7972 +7977 +7978 +7976 +7977 +7991 +8016 +8056 +8058 +8059 +8074 +8078 +8087 +8088 +8083 +8088 +8094 +8103 +8118 +8114 +8115 +8111 +8116 +8115 +8105 +8106 +8107 +8108 +8112 +8120 +8129 +8134 +8138 +8137 +8138 +8152 +8158 +8171 +8191 +8201 +8207 +8209 +8236 +8237 +8239 +8244 +8239 +8241 +8252 +8243 +8244 +8260 +8254 +8248 +8251 +8246 +8249 +8262 +8265 +8266 +8263 +8264 +8267 +8273 +8297 +8302 +8303 +8302 +8310 +8313 +8314 +8332 +8333 +8306 +8308 +8307 +8334 +8332 +8329 +8330 +8332 +8337 +8338 +8343 +8350 +8349 +8361 +8365 +8368 +8371 +8372 +8375 +8402 +8412 +8445 +8447 +8472 +8482 +8483 +8486 +8493 +8495 +8494 +8493 +8494 +8499 +8501 +8503 +8513 +8509 +8510 +8514 +8515 +8514 +8518 +8535 +8538 +8543 +8545 +8557 +8568 diff --git a/Advent-of-Code-2021/AOC-1/input-1.txt~ b/Advent-of-Code-2021/AOC-1/input-1.txt~ new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Advent-of-Code-2021/AOC-1/input-1.txt~ diff --git a/Advent-of-Code-2021/AOC-11/build.sh b/Advent-of-Code-2021/AOC-11/build.sh new file mode 100755 index 0000000..6be9241 --- /dev/null +++ b/Advent-of-Code-2021/AOC-11/build.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -xe + +gcc -o main -Wall -Wextra main.c + +./main diff --git a/Advent-of-Code-2021/AOC-11/example.txt b/Advent-of-Code-2021/AOC-11/example.txt new file mode 100644 index 0000000..03743f6 --- /dev/null +++ b/Advent-of-Code-2021/AOC-11/example.txt @@ -0,0 +1,10 @@ +5483143223 +2745854711 +5264556173 +6141336146 +6357385478 +4167524645 +2176841721 +6882881134 +4846848554 +5283751526 diff --git a/Advent-of-Code-2021/AOC-11/input.txt b/Advent-of-Code-2021/AOC-11/input.txt new file mode 100644 index 0000000..e7b9665 --- /dev/null +++ b/Advent-of-Code-2021/AOC-11/input.txt @@ -0,0 +1,10 @@ +4472562264 +8631517827 +7232144146 +2447163824 +1235272671 +5133527146 +6511372417 +3841841614 +8621368782 +3246336677 diff --git a/Advent-of-Code-2021/AOC-11/main b/Advent-of-Code-2021/AOC-11/main Binary files differnew file mode 100755 index 0000000..72ff31b --- /dev/null +++ b/Advent-of-Code-2021/AOC-11/main diff --git a/Advent-of-Code-2021/AOC-11/main.c b/Advent-of-Code-2021/AOC-11/main.c new file mode 100644 index 0000000..b72ec5f --- /dev/null +++ b/Advent-of-Code-2021/AOC-11/main.c @@ -0,0 +1,114 @@ +#include <stdio.h> +#include <string.h> + +#if 0 +#define FILE_PATH "example.txt" +#else +#define FILE_PATH "input.txt" +#endif + +#define WIDTH 10 +#define HEIGHT 10 + +int board[WIDTH][HEIGHT] = {0}; +size_t flashes = 0; + +void parse() +{ + FILE *fp = fopen(FILE_PATH, "r"); + if(!fp) { + fprintf(stderr,"ERROR: Could not open file: %s", FILE_PATH); + return; + } + + char ch; + int i = 0; + while((ch = fgetc(fp)) != EOF) + { + if(ch == '\n') continue; + board[i%WIDTH][i/HEIGHT] = ch - '0'; + i++; + } + + fclose(fp); + +} + +int step() +{ + for(int i = 0; i < HEIGHT; i++) + for(int j = 0; j < WIDTH; j++) + board[j][i] += 1; + + int new_board[WIDTH][HEIGHT] = {0}; + size_t old_flashes = 0 - 1; + while(old_flashes != flashes) + { + old_flashes = flashes; + memcpy(new_board, board, sizeof(board)); + + for(int i = 0; i < HEIGHT; i++) + for(int j = 0; j < WIDTH; j++) + if(board[j][i] > 9) + { + flashes++; + new_board[j][i] = 0; + + for(int y = -1; y <= 1; y++) + for(int x = -1; x <= 1; x++) + if(i+y < 0 || i+y >= HEIGHT || + j+x < 0 || j+x >= WIDTH || + (y == 0 && x == 0)) continue; + else if(new_board[j+x][i+y] != 0) + new_board[j+x][i+y]++; + } + + memcpy(board, new_board, sizeof(board)); + } + + int empty_board[WIDTH][HEIGHT] = {0}; + if(memcmp(board, empty_board, sizeof(board)) == 0) + return 1; + + return 0; +} + +void print_board() +{ + for(int i = 0; i < HEIGHT; i++) + { + for(int j = 0; j < WIDTH; j++) + { + printf("%d", board[j][i]); + } + puts(""); + } +} + +void part_1() +{ + parse(); + + for(int i = 0; i < 100; i++) + step(); + + printf("flashes: %ld\n", flashes); +} + +void part_2() +{ + parse(); + + for(int i = 0; i < 1000000; i++) + if(step()) { + printf("synced at step: %d\n", i + 1); + return; + } +} + +int main(void) +{ + part_1(); + part_2(); + return 0; +} diff --git a/Advent-of-Code-2021/AOC-13/build.sh b/Advent-of-Code-2021/AOC-13/build.sh new file mode 100755 index 0000000..6be9241 --- /dev/null +++ b/Advent-of-Code-2021/AOC-13/build.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -xe + +gcc -o main -Wall -Wextra main.c + +./main diff --git a/Advent-of-Code-2021/AOC-13/example.txt b/Advent-of-Code-2021/AOC-13/example.txt new file mode 100644 index 0000000..282114c --- /dev/null +++ b/Advent-of-Code-2021/AOC-13/example.txt @@ -0,0 +1,21 @@ +6,10 +0,14 +9,10 +0,3 +10,4 +4,11 +6,0 +6,12 +4,1 +0,13 +10,12 +3,4 +3,0 +8,4 +1,10 +2,14 +8,10 +9,0 + +fold along y=7 +fold along x=5 diff --git a/Advent-of-Code-2021/AOC-13/input.txt b/Advent-of-Code-2021/AOC-13/input.txt new file mode 100644 index 0000000..188121b --- /dev/null +++ b/Advent-of-Code-2021/AOC-13/input.txt @@ -0,0 +1,865 @@ +1118,85 +1064,690 +560,670 +68,446 +769,668 +88,219 +120,255 +925,879 +112,512 +1064,652 +1046,233 +902,417 +523,33 +1012,280 +1210,135 +410,142 +689,497 +698,211 +981,259 +465,610 +689,621 +1093,887 +114,728 +790,809 +139,59 +798,257 +390,457 +482,281 +701,190 +840,283 +320,723 +498,504 +256,397 +100,115 +401,92 +796,780 +239,729 +755,539 +736,870 +676,567 +484,560 +405,511 +187,387 +356,155 +42,659 +182,508 +256,374 +572,320 +738,207 +328,80 +70,528 +1111,752 +648,54 +33,308 +716,704 +701,798 +700,324 +10,260 +1076,401 +554,533 +592,885 +269,575 +492,528 +646,837 +1134,268 +1290,619 +442,248 +549,519 +908,647 +402,280 +1081,428 +768,575 +1277,525 +472,121 +985,635 +912,374 +512,499 +708,807 +1054,558 +305,856 +401,756 +8,53 +1044,256 +607,581 +156,840 +756,331 +771,609 +276,456 +1268,842 +1123,387 +155,526 +1125,380 +612,52 +864,772 +572,126 +1084,597 +666,397 +574,169 +33,481 +1098,280 +468,215 +370,3 +639,204 +1230,466 +512,684 +705,161 +738,126 +355,376 +1096,736 +1166,476 +1036,135 +912,782 +947,32 +636,50 +623,250 +1257,215 +416,672 +989,74 +1300,852 +776,659 +1196,838 +1064,304 +252,471 +994,410 +459,33 +567,361 +489,159 +1240,528 +58,506 +944,339 +788,0 +319,857 +644,215 +787,33 +1198,767 +798,843 +920,233 +760,411 +1300,626 +52,311 +812,558 +378,227 +226,437 +386,444 +169,291 +308,172 +698,618 +514,231 +761,235 +157,774 +798,684 +902,29 +428,37 +698,52 +405,383 +1104,256 +1058,784 +299,518 +617,332 +346,498 +1178,89 +1290,275 +1196,166 +293,425 +895,567 +1034,662 +596,56 +687,250 +534,255 +623,698 +1309,719 +92,347 +226,297 +736,253 +497,155 +736,528 +776,780 +223,42 +465,732 +900,53 +493,411 +909,838 +542,512 +385,659 +537,590 +1228,80 +420,462 +761,519 +879,852 +1277,693 +908,838 +890,324 +1092,383 +691,862 +602,378 +416,224 +296,598 +666,215 +234,347 +902,142 +1101,253 +581,362 +316,567 +28,255 +929,824 +117,77 +848,515 +701,704 +1136,233 +485,680 +1233,511 +788,357 +246,304 +500,505 +1144,63 +738,320 +964,620 +623,413 +26,495 +58,390 +82,590 +930,311 +239,578 +748,784 +873,518 +385,879 +311,242 +1036,666 +1230,641 +1032,224 +80,325 +1233,383 +1290,171 +31,413 +1076,493 +402,838 +731,690 +977,522 +92,36 +144,476 +520,365 +428,396 +1196,390 +100,149 +818,752 +142,637 +21,882 +295,61 +631,435 +731,204 +676,584 +68,448 +748,544 +560,224 +1,719 +683,152 +490,590 +909,373 +517,568 +967,690 +1015,450 +1092,175 +729,532 +676,248 +912,858 +1180,0 +174,233 +73,586 +403,292 +325,635 +308,474 +733,511 +38,787 +278,222 +562,36 +485,603 +296,822 +428,149 +433,494 +1240,120 +136,175 +1240,366 +1240,774 +485,214 +73,745 +668,364 +1071,119 +185,514 +882,268 +544,614 +540,838 +139,773 +1005,236 +156,280 +1290,584 +813,155 +209,826 +773,572 +715,852 +11,700 +562,350 +209,701 +293,33 +117,301 +1248,710 +343,690 +274,359 +1146,646 +930,666 +189,162 +161,383 +485,291 +912,558 +252,784 +1237,745 +35,32 +105,235 +760,483 +62,821 +977,372 +366,591 +221,848 +120,108 +991,857 +909,381 +355,518 +316,791 +445,583 +422,710 +510,508 +52,516 +349,236 +277,201 +276,662 +676,758 +502,455 +353,844 +415,316 +28,404 +498,558 +554,107 +1101,701 +935,873 +865,701 +1071,327 +497,409 +756,626 +1272,555 +1118,851 +1073,280 +385,463 +954,827 +1048,845 +402,59 +602,807 +577,511 +234,509 +642,880 +97,428 +705,226 +73,532 +1179,33 +74,87 +226,361 +256,484 +1154,280 +989,887 +982,696 +977,74 +566,51 +480,45 +398,72 +142,283 +848,851 +957,844 +390,233 +999,242 +366,339 +776,255 +1096,830 +845,162 +403,826 +1078,264 +274,666 +622,506 +70,366 +64,49 +579,690 +373,490 +738,350 +667,362 +134,591 +1064,808 +438,212 +53,215 +226,533 +359,416 +989,603 +1262,357 +1096,64 +701,544 +890,570 +358,296 +821,175 +851,33 +356,826 +1094,212 +1213,428 +596,390 +1066,814 +80,466 +273,824 +35,862 +877,235 +484,616 +103,42 +1181,810 +385,435 +768,736 +1289,539 +1173,568 +760,847 +826,726 +808,631 +714,388 +274,135 +900,752 +808,263 +810,57 +468,887 +38,824 +907,826 +1277,586 +33,362 +497,215 +912,820 +1054,397 +512,658 +64,497 +410,814 +689,301 +756,533 +1029,311 +470,891 +525,84 +1002,474 +540,248 +664,501 +912,72 +70,8 +353,162 +1155,368 +156,558 +808,487 +156,54 +1300,260 +192,67 +33,273 +338,266 +909,92 +117,814 +1158,36 +356,778 +1258,516 +1066,798 +957,162 +1228,768 +361,469 +157,215 +810,505 +687,413 +335,37 +1058,23 +920,498 +714,623 +1282,137 +1202,413 +1076,122 +251,327 +310,469 +1190,108 +687,385 +621,593 +403,567 +623,196 +882,793 +1228,590 +408,477 +296,72 +114,248 +808,256 +469,828 +825,456 +718,9 +1071,165 +301,550 +1169,882 +1041,459 +944,303 +560,710 +522,357 +338,215 +537,145 +687,698 +972,215 +328,814 +1265,404 +321,74 +909,597 +1242,448 +33,525 +120,786 +684,379 +164,248 +537,817 +1158,401 +329,259 +349,210 +1190,3 +550,847 +649,522 +276,214 +933,609 +1248,73 +542,158 +842,332 +842,108 +726,366 +1054,334 +1168,645 +252,871 +681,792 +602,29 +1141,291 +912,385 +462,379 +1174,495 +633,38 +20,310 +1193,814 +169,774 +643,252 +554,779 +1002,722 +1258,67 +298,378 +1054,547 +502,858 +1126,89 +333,74 +1014,520 +1081,690 +45,796 +1081,466 +146,469 +909,166 +902,752 +1250,32 +663,409 +131,861 +840,197 +174,45 +152,858 +186,679 +74,59 +164,590 +622,394 +964,396 +141,882 +1153,663 +584,8 +909,728 +321,7 +1222,135 +277,693 +252,423 +890,509 +162,287 +1071,266 +110,627 +305,38 +1275,862 +298,166 +838,569 +1054,484 +493,595 +110,491 +381,455 +572,687 +70,120 +773,817 +229,204 +566,135 +18,50 +114,390 +565,26 +902,466 +1135,674 +308,26 +1210,485 +502,493 +944,555 +256,560 +1153,774 +865,68 +28,137 +184,197 +962,809 +894,222 +634,567 +622,58 +808,183 +539,285 +1277,397 +522,537 +112,158 +1136,661 +114,646 +1200,280 +1263,89 +356,827 +87,640 +462,809 +21,539 +52,378 +771,285 +293,273 +246,735 +564,772 +714,390 +565,868 +401,597 +1034,438 +621,621 +1154,838 +92,99 +1300,186 +1237,532 +321,603 +664,837 +445,193 +1092,831 +234,401 +100,745 +1258,378 +1198,127 +550,411 +1034,456 +112,127 +11,194 +730,535 +872,614 +977,455 +1174,719 +937,190 +950,836 +237,280 +661,344 +246,204 +1193,301 +165,383 +164,764 +1009,102 +994,268 +373,190 +1174,175 +62,73 +907,567 +356,728 +120,3 +1252,56 +209,641 +113,226 +821,595 +738,277 +1176,533 +1009,498 +687,196 +1278,52 +1179,861 +502,519 +1076,547 +1169,12 +882,37 +244,814 +661,550 +925,659 +1171,59 +339,362 +1076,285 +1084,533 +1210,745 +808,519 +764,749 +689,273 +1092,511 +514,332 +398,173 +1014,72 +401,138 +1190,255 +1250,862 +622,388 +687,478 +333,372 +370,190 +694,385 +1124,556 +1056,749 +649,792 +154,729 +301,844 +329,635 +58,838 +940,190 +281,641 +515,387 +813,215 +841,262 +617,556 +1230,204 +930,379 +1012,291 +1218,795 +428,268 +21,486 +185,380 +1029,583 +315,586 +281,583 +100,268 +1088,859 +971,308 +88,395 +597,207 +621,273 +10,186 +370,704 +714,504 +427,770 +256,385 +1218,544 +485,829 +59,318 +744,135 +160,607 +972,716 +440,736 +291,862 +20,584 +840,891 +294,500 +920,457 +776,639 +679,435 +276,227 +1123,835 +216,491 +410,53 +646,841 +513,12 +32,282 +643,700 +1158,455 +1171,773 +216,212 +0,287 +146,425 +380,807 +1138,57 +932,227 +555,539 +21,42 +346,396 +688,282 +385,431 +398,273 +428,857 +132,313 +540,646 +52,827 +161,859 +1037,439 +641,446 +574,477 +281,311 +1198,158 +1200,715 +70,558 +139,387 +932,848 +744,311 +1002,172 +964,26 +169,120 +301,498 +642,364 +580,731 +909,354 +217,7 +1041,575 +1289,38 +1022,833 +1279,481 +1154,558 +1196,504 +104,607 +415,809 +1275,32 +398,334 +756,50 +182,773 +208,772 +1154,728 +1158,858 +730,59 +62,184 +957,344 +890,547 +1176,591 +73,362 +515,507 +1145,511 +1277,621 +62,9 +1277,413 +361,873 +786,0 +483,857 +534,780 +1252,838 +796,332 +1083,803 +662,840 +682,399 +798,499 +925,459 +1228,687 +895,316 +541,276 +208,324 +523,705 +907,292 +468,332 +1289,355 +667,700 +402,647 +416,387 +1054,560 +31,481 +920,396 +234,45 + +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 diff --git a/Advent-of-Code-2021/AOC-13/main b/Advent-of-Code-2021/AOC-13/main Binary files differnew file mode 100755 index 0000000..62869db --- /dev/null +++ b/Advent-of-Code-2021/AOC-13/main diff --git a/Advent-of-Code-2021/AOC-13/main.c b/Advent-of-Code-2021/AOC-13/main.c new file mode 100644 index 0000000..876dae7 --- /dev/null +++ b/Advent-of-Code-2021/AOC-13/main.c @@ -0,0 +1,169 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> + +#if 0 +#define PART_1 +#else +#define PART_2 +#endif + +#if 0 +#define FILE_PATH "example.txt" +#define RULES 2 +int WIDTH = 11; +int HEIGHT = 15; +#else +#define FILE_PATH "input.txt" +#define RULES 12 +int WIDTH = 1311; +int HEIGHT = 895; +#endif + +#define BOARD_SZ ((WIDTH)*(HEIGHT)) + +int *board = NULL; +int rules_val[RULES] = {0}; +int rules_axis[RULES] = {0}; // 0 is x; 1 is y + +void parse() +{ + FILE *fp = fopen(FILE_PATH, "r"); + if(!fp) { + fprintf(stderr, "Could not open file: %s", FILE_PATH); + return; + } + + board = malloc(BOARD_SZ*sizeof(int)); + + char line[256]; + char *tok; + int read_rules = -1; + while(fgets(line, sizeof(line), fp) != NULL) + { + if(line[0] == '\n') { + read_rules = 0; + } else if(read_rules < 0) { + tok = strtok(line, ","); + int x = atoi(tok); + tok = strtok(NULL, ","); + int y = atoi(tok); + + assert(strtok(NULL, ",") == NULL); + assert(x >= 0 && x < WIDTH); + assert(y >= 0 && y < HEIGHT); + board[y * WIDTH + x] = 1; + } else { + tok = strtok(line, "="); + rules_axis[read_rules] = (tok[11] == 'y'); + tok = strtok(NULL, "="); + rules_val[read_rules] = atoi(tok); + read_rules++; + assert(strtok(NULL, "=") == NULL); + } + } + + fclose(fp); +} + +void fold(int rules_i) +{ + int *board_cpy = malloc(BOARD_SZ*sizeof(int)); + + memcpy(board_cpy, board, BOARD_SZ*sizeof(int)); + free(board); + + int old_width = WIDTH; + if(rules_axis[rules_i] == 0) WIDTH = (WIDTH-1)/2; + else HEIGHT = (HEIGHT-1)/2; + + board = malloc(BOARD_SZ*sizeof(int)); + + for(int i = 0; i < HEIGHT; i++) + { + for(int j = 0; j < WIDTH; j++) + { + int index = i * WIDTH + j; + int bc_index = i * old_width + j; + int mirror; + + if(rules_axis[rules_i] == 0) { + mirror = i * old_width + (2*rules_val[rules_i] - j); + } else { + mirror = ((2*rules_val[rules_i] - i) + * old_width) + j; + } + + board[index] = + board_cpy[bc_index] + + board_cpy[mirror]; + } + } + + free(board_cpy); +} + +void print_board() +{ + for(int i = 0; i < HEIGHT; i++) + { + for(int j = 0; j < WIDTH; j++) + { + if(board[i * WIDTH + j] == 0) + putc('.', stdout); + else + putc('#', stdout); + } + putc('\n', stdout); + } +} + +void print_rules() +{ + for(int i = 0; i < RULES; i++) + { + char axis; + if(rules_axis[i] == 0) axis = 'x'; + else axis = 'y'; + printf("fold along %c=%d\n", axis, rules_val[i]); + } +} + +void part_1() +{ + parse(); + fold(0); + + int visible = 0; + for(int i = 0; i < BOARD_SZ; i++) + { + if(board[i] > 0) visible++; + } + + printf("%d dots are visible\n", visible); +} + +void part_2() +{ + parse(); + for(int i = 0; i < RULES; i++) + fold(i); + + print_board(); +} + +int main(void) +{ + +#ifdef PART_1 + part_1(); +#endif + +#ifdef PART_2 + part_2(); +#endif + + free(board); + return 0; +} diff --git a/Advent-of-Code-2021/AOC-14/aoc-14 b/Advent-of-Code-2021/AOC-14/aoc-14 Binary files differnew file mode 100755 index 0000000..630caae --- /dev/null +++ b/Advent-of-Code-2021/AOC-14/aoc-14 diff --git a/Advent-of-Code-2021/AOC-14/aoc-14.c b/Advent-of-Code-2021/AOC-14/aoc-14.c new file mode 100644 index 0000000..d23bfcb --- /dev/null +++ b/Advent-of-Code-2021/AOC-14/aoc-14.c @@ -0,0 +1,202 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> + +#if 0 +#define PFILE "sample.txt" +#else +#define PFILE "input.txt" +#endif + +#define T_CAP 100 +char template[T_CAP]; +size_t tmpl_sz = 0; + +#define R_CAP 100 +typedef struct { + char inp[2]; + char ch; +} rule_t; +rule_t rules[R_CAP]; +size_t rules_sz = 0; + +#define CAP 1000000 +typedef uint64_t lsize_t; +char product[CAP]; +lsize_t prod_sz = 0; + + +void Parse() +{ + + // some init + memset(template, '\0', T_CAP); + memset(product, '\0', CAP); + + char ch; + FILE *fp; + fp = fopen(PFILE, "r"); + + int mode = 0; // 0 - for template; 1 - for rules; 2 - intermid + int mode_s = 0; // 0 - has not encountered ' '; 1 - after ' ' + while((ch = fgetc(fp)) != EOF) + { + if(ch == '\n' && mode == 0) + { + mode = 2; + } + else if(ch == '\n' && mode == 2) + { + mode = 1; + } + else if(ch == '\n' && mode == 1) + { + memset(rules[rules_sz].inp, '\0', 2); + rules[rules_sz].ch = '\0'; + } + else if(ch != '\n' && mode == 0) + { + template[tmpl_sz] = ch; + tmpl_sz += 1; + } + else if(ch != '\n' && mode == 1) + { + switch(mode_s) + { + case 0: + if(rules[rules_sz].inp[0] == '\0') + { + rules[rules_sz].inp[0] = ch; + } + else + { + rules[rules_sz].inp[1] = ch; + mode_s = 1; + } + break; + case 1: + if(ch != ' ' && ch != '-' && ch != '>') + { + rules[rules_sz].ch = ch; + rules_sz += 1; + mode_s = 0; + } + } + } + } + + fclose(fp); +} + +void InsertAt(char ch, size_t pos) +{ + for(lsize_t i = prod_sz; i > pos; i--) + { + product[i] = product[i-1]; + } + product[pos] = ch; + + prod_sz += 1; +} + +void Part1() +{ + Parse(); + prod_sz = tmpl_sz; + memcpy(product, template, prod_sz); + + char elements[CAP]; memset(elements, '\0', CAP); + lsize_t positions[CAP]; + lsize_t inrt_sz = 0; + + printf("%s\n", product); + + for(int step = 0; step < 40; step++) + { + for(lsize_t i = 0; i < (prod_sz-1); i++) + { + for(int j = 0; j < rules_sz; j++) + { + if(product[i] == rules[j].inp[0] && + product[i+1] == rules[j].inp[1]) + { + elements[inrt_sz] = rules[j].ch; + positions[inrt_sz] = i + 1 + inrt_sz; //error potential + inrt_sz += 1; + break; + } + } + } + for(lsize_t i = 0; i < inrt_sz; i++) + { + InsertAt(elements[i], positions[i]); + } + inrt_sz = 0; + memset(elements, '\0', CAP); + } + + // Get count and subtract + lsize_t el_occurence[10]; + /* S - 0 */ + /* H - 1 */ + /* N - 2 */ + /* C - 3 */ + /* O - 4 */ + /* P - 5 */ + /* F - 6 */ + /* B - 7 */ + /* V - 8 */ + /* K - 9 */ + + for(lsize_t i = 0; i < prod_sz; i++) + { + switch(product[i]) + { + case 'S': el_occurence[0] += 1; break; + case 'H': el_occurence[1] += 1; break; + case 'N': el_occurence[2] += 1; break; + case 'C': el_occurence[3] += 1; break; + case 'O': el_occurence[4] += 1; break; + case 'P': el_occurence[5] += 1; break; + case 'F': el_occurence[6] += 1; break; + case 'B': el_occurence[7] += 1; break; + case 'V': el_occurence[8] += 1; break; + case 'K': el_occurence[9] += 1; break; + } + } + + //get biggest + lsize_t biggest = 0; + for(int i = 0; i < 10; i++) + { + int counter = 0; + for(int j = 0; j < 10; j++) + if(el_occurence[i] >= el_occurence[j]) counter += 1; + if(counter == 10) { biggest = el_occurence[i]; break; } + } + + //get smallest + lsize_t smallest = 0; + for(int i = 0; i < 10; i++) + { + int counter = 0; + for(int j = 0; j < 10; j++) + if(el_occurence[i] <= el_occurence[j]) counter += 1; + if(counter == 10) {smallest = el_occurence[i]; break; } + } + + lsize_t result = biggest - smallest; + printf("%llu-%llu=%llu", biggest, smallest, result); +} + +void Part2() +{ + +} + +int main(void) +{ + Part1(); + return 0; +} diff --git a/Advent-of-Code-2021/AOC-14/input.txt b/Advent-of-Code-2021/AOC-14/input.txt new file mode 100644 index 0000000..1380de1 --- /dev/null +++ b/Advent-of-Code-2021/AOC-14/input.txt @@ -0,0 +1,102 @@ +SHHNCOPHONHFBVNKCFFC + +HH -> K +PS -> P +BV -> H +HB -> H +CK -> F +FN -> B +PV -> S +KK -> F +OF -> C +SF -> B +KB -> S +HO -> O +NH -> N +ON -> V +VF -> K +VP -> K +PH -> K +FF -> V +OV -> N +BO -> K +PO -> S +CH -> N +FO -> V +FB -> H +FV -> N +FK -> S +VC -> V +CP -> K +CO -> K +SV -> N +PP -> B +BS -> P +VS -> C +HV -> H +NN -> F +NK -> C +PC -> V +HS -> S +FS -> S +OB -> S +VV -> N +VO -> P +KV -> F +SK -> O +BC -> P +BP -> F +NS -> P +SN -> S +NC -> N +FC -> V +CN -> S +OK -> B +SC -> N +HN -> B +HP -> B +KP -> B +CB -> K +KF -> C +OS -> B +BH -> O +PN -> K +VN -> O +KH -> F +BF -> H +HF -> K +HC -> P +NP -> H +KO -> K +CF -> H +BK -> O +OH -> P +SO -> F +BB -> F +VB -> K +SP -> O +SH -> O +PK -> O +HK -> P +CC -> V +NB -> O +NV -> F +OO -> F +VK -> V +FH -> H +SS -> C +NO -> P +CS -> H +BN -> V +FP -> N +OP -> N +PB -> P +OC -> O +SB -> V +VH -> O +KS -> B +PF -> N +KN -> H +NF -> N +CV -> K +KC -> B diff --git a/Advent-of-Code-2021/AOC-14/sample.txt b/Advent-of-Code-2021/AOC-14/sample.txt new file mode 100644 index 0000000..b5594dd --- /dev/null +++ b/Advent-of-Code-2021/AOC-14/sample.txt @@ -0,0 +1,18 @@ +NNCB + +CH -> B +HH -> N +CB -> H +NH -> C +HB -> C +HC -> B +HN -> C +NN -> C +BH -> H +NC -> B +NB -> B +BN -> B +BB -> N +BC -> B +CC -> N +CN -> C diff --git a/Advent-of-Code-2021/AOC-15/aoc-15 b/Advent-of-Code-2021/AOC-15/aoc-15 Binary files differnew file mode 100755 index 0000000..3fa17a1 --- /dev/null +++ b/Advent-of-Code-2021/AOC-15/aoc-15 diff --git a/Advent-of-Code-2021/AOC-15/aoc-15.c b/Advent-of-Code-2021/AOC-15/aoc-15.c new file mode 100644 index 0000000..c7e1157 --- /dev/null +++ b/Advent-of-Code-2021/AOC-15/aoc-15.c @@ -0,0 +1,128 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define min(a, b) (((a) < (b)) ? (a) : (b)) + +#if 0 + #define N 1 +#else + #define N 5 +#endif + + +// part 2 doesnt work with input for some reason bruh +#if 1 + #define FILE_P "sample.txt" + #define T_CAP 10 * N + #define T_CAP_S 10 +#else + #define FILE_P "input.txt" + #define T_CAP 100 * N + #define T_CAP_S 100 +#endif + +int table[T_CAP][T_CAP]; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if(fp == NULL) + { + fprintf(stderr, "ERROR: something with file idk fuck you"); + exit(EXIT_FAILURE); + } + + int i = 0; + int j = 0; + while((ch = fgetc(fp)) != EOF) + { + if(ch == '\n') { i += 1; j = 0; continue; } + + table[i][j] = (ch - '0'); + j += 1; + } + + fclose(fp); +} + +void FindRisk() +{ + // dont add to total risk + table[0][0] = 0; + + for(int i=1; i<T_CAP; i++) table[i][0] += table[i-1][0]; + for(int j=1; j<T_CAP; j++) table[0][j] += table[0][j-1]; + + for(int i=1; i<T_CAP; i++) + { + for(int j=1; j<T_CAP; j++) + { + table[i][j] += min(table[i][j-1], table[i-1][j]); + } + } + +} + +void Part1() +{ + ParseInput(FILE_P); + FindRisk(); + printf("PART1: %d\n", table[T_CAP-1][T_CAP-1]); +} + +void ReconstructMap() +{ + for(int j=0; j<T_CAP_S; j++) + for(int n=T_CAP_S; n<T_CAP; n+=T_CAP_S) + for(int i=0; i<T_CAP_S; i++) + { + if(table[i+n-T_CAP_S][j] != 9) + table[i+n][j] = table[i+n-T_CAP_S][j] + 1; + else + table[i+n][j] = 1; + } + + for(int i=0; i<T_CAP; i++) + for(int n=T_CAP_S; n<T_CAP; n+=T_CAP_S) + for(int j=0; j<T_CAP_S; j++) + { + if(table[i][j+n-T_CAP_S] != 9) + table[i][j+n] = table[i][j+n-T_CAP_S] + 1; + else + table[i][j+n] = 1; + } +} + +void Part2() +{ + ParseInput(FILE_P); + ReconstructMap(); + FindRisk(); + printf("PART2: %d\n", table[T_CAP-1][T_CAP-1]); +} + +void PrintTable() +{ + for(int i=0; i<T_CAP; i++) + { + for(int j=0; j<T_CAP; j++) + { + printf("%d", table[i][j]); + } + printf("\n"); + } +} + +int main(void) +{ + memset(table, 0, sizeof(table)); + // Part1(); + Part2(); + + return 0; +} + diff --git a/Advent-of-Code-2021/AOC-15/aoc-15.c~ b/Advent-of-Code-2021/AOC-15/aoc-15.c~ new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Advent-of-Code-2021/AOC-15/aoc-15.c~ diff --git a/Advent-of-Code-2021/AOC-15/input.txt b/Advent-of-Code-2021/AOC-15/input.txt new file mode 100644 index 0000000..d8f5dfd --- /dev/null +++ b/Advent-of-Code-2021/AOC-15/input.txt @@ -0,0 +1,100 @@ +4249856395422795894919869133487611581179923326874763428673979547991221931142777981153991369468629849 +5812974178739823463799939791688998895568796557798392761499941349143539572865883254186633218867928826 +3699989976298596286299499129934993241824395574879938998946914116375199242199151918863674914554714898 +5682435936794718871685718386458294198391116125679589438794914499278679393779734596558953699438589518 +7681197997388219696918569664119968498599547892968929425479817979816979144947916716989874825679487436 +9981166198272997899142698141878643123757515999788822988261499197559193945291512682763935126815448215 +8849481991861599951293183728419792414164347979985169641698899853377259811688489269959429131918919179 +3146684963669199195628973847379928251333566129941616877139631993381755512697185555441659879412994594 +3547126819874919985836685298322994247998729919239243539198191229787198622919819681997288193865811343 +9349351519955698988787949741387799819991699489867797184914918979814262987979129782223984139929928681 +8556723973779719572644889927179188961591428979299692841637999459259999966917347419979917999989799429 +3999593212698784221858498479516759888388689669747143292191959989949179914898181617598363288863529673 +5428799869888883819715648841341382669887652713779547744299157935892529712964887994849791591489974817 +4165839572399389794126943784626997119389378141921327523621283992924955951342126919499984987328936781 +5918974268979888998966997691965798988519797198467567586265175937858739845974399727152913189899879868 +9918963885878999715999979758376917418219222841971748992311279797791196671188181557777929939979528569 +8799414739499371349792499832971671794937933561999619313535199597778778121557962319178399272824346194 +8129974849671628977826913868589128781917962416787192199363828395129743811293383873718935942898484543 +3291978181898819892998112489871391737197991911931592663875989291645713999792932894185783865998135615 +9769786394195196445418935989967399989919987914119824796623857976492949168247992292316817898188699298 +9695549579996919793895372134169684298121551587731119812488691243992189122596899959128989294926989913 +9731949899392599399916551967299296355733976428888499681995484999191298894166112999923884965685649798 +1379132844766698587968789875949841895175974769991975485998386847244993897999111588556816596847214788 +9995799248928516994491995979579982981536188627577229466616615274772189816183363386951765979225171476 +8119319184142479165692338899796498149599699117488698945689444844778989694876998388519355148181719697 +3969928779117129139766611778112739189981889899228317887833728779584723699986312572133539799467285917 +2828571791973431936329179952568811618879743616915382919867751789598712817617446745199253856716911941 +7877882851638951395858496388153888963667598177681792531864174354491939941593119389999293999633917577 +1741348787717975984768578798922563489939392171468619989248936559712179995116534277937799235981547597 +8994795857858489999558911549196942878698886391795462739582595987979187765281397182149953478248998829 +8612529258832189244164522719918668148697754189678792826892293447659399729274986899475955657297984999 +7979418978468149867435687251779984869732288683757891423519948382875198942891979899776225467769271611 +3818925865589486991983914829611968896197719999391296298299521911997968172695633992575991389714563593 +9939187896519664586181929999697892324492792718919161519713861732615919297932929685698963679515326392 +9189845839678777775364697497289839263197942629799278637458319429822229529989343196991899576448897282 +9999639983298888593994869989699624152112558163996649649924665617939567974367965998835369235385845781 +8485297496991559289188422661599882518896282381858287969539917799964977429172882227811329528518187389 +9923859471976698253169673595135694645862699839964421741799449165978835991198979991891434697214818847 +9948337779794835971121969995653787569496217989663848398739231628499247383942859555527489595679787897 +9614621899899158259613995889586798538683918139138198111781714698794348571485366962113966939699643589 +1886264968913257167733217995794996991471499861875887994593877487186697874771821988536581746639569567 +9996998152929759225939499689998449399761985591467834853824558991322485728674388927966892986878819319 +9898162778195791515947756898474977179296647585999979756996981928598799139892651743929891711498489794 +2521299845948789489447298917175981779999984794295846999894374299918878915896995183978239599211199661 +3595238712479964219979978796399416285395878319927814389893184733214219892965998974989825195778431936 +2235456515733797949374988899892819815718692811711999741978953215792979895857589889485595198499933267 +1197979995691548749958849994592898117171521989543481689999898771166569678234761678582598848227891693 +6216285194657981924762962276999868669495239816738592141587889187963869774297156591399718859932485599 +4729519687582299378618117855237999797646997991843389649799259193169319238188911375949387726963679678 +9699419763993869239747599293979686119998329461424981594878199858799991786943919119924945895985515374 +5917996721981481869846954978898329942115828969756258675677679711875328179436699932532229987171169929 +7229157819969968259887444794288923399898267871298685198291217856595548347212555983111245182519289622 +9941195813129393544872257827938956788461327756591766941724841646918922553881862784891489959867389928 +8479286666256699729946931949971218817964289363968557999375893759943919891576159694877195239993489148 +5189737855542763417865693998141987771991218843271999857384919975699659994988779213888396912127939755 +5829249497186735715873851983779438136179792549877615899657346513899789927819449917872492988915513982 +6893461933919197988858287721313611812883946878115312372236989924698848988818298419696991695398125941 +6981819519985951199181939989475291951792185935616749128365399541588872686782591994295847959591392931 +7988629179489397799986811211539191291919253927863868887948841837793918643181962412676745991232121578 +5889916119249763577671931536771981885869515736589522848999798153991769949974999631378632167199887678 +9893498949812711525997272863949911589719196319429992823161587263989111998263931884594518988198746153 +6167489848782461731786755137947748897385171725523188729519395821564894154311747791864617427287926885 +1284879221869544119521638879871365523816995929979939483888749839719816469311148686844482791986117755 +4617558896994997356988295927288939978311852269226941898983267192735959576936969989579628535528783519 +5328888897937299985799899978919859582992981919818841999199494771499878669927759686618478946895944119 +6799938769339968858662394789696395769769575687756577828218986197652972952814799386756962996181892597 +9396911993551199899798629969782451326725698246878288812846813423295351841296547341338696917479175299 +8998397898488795919859127962748999922875998559197478977986192197254779199892998169999599176629148878 +1698547699914798869767429873945711593683922969939799919274119396933311939635974962783917832779918579 +8773297884249519189999647199932138888596519893944669261146627181688998288918962987398761891458879884 +5661719599479729158986561758999787569799247991581291493981747289118938848919798944839816176679395936 +9819441791329173937924877935925271972592729118224733234158273767899274195899119793821988798684414696 +1976289898791262299218117985854188291999988166561946723974852936794841371689495873895293179648555216 +9723987778468774982999879135869177783838973792981148981488979249865929898395999487197993391716979759 +1177899997181866344793594917459353978963997881815188848687916378799676376889949425869917561752649758 +9791868299666371298719945725279668482196145817963941526858953389928439799189979599987117288975594221 +9359479864494253699797539169919312739992899782984267865929872973278316996551116989646898578889798559 +2891458316689974817533795738749516416557382959989231868945595215936673184172899784699156791788186319 +3197871588419391799499768999958793419827795378639897913112989895282789729517678369821971988591168789 +3128895611274175995969789557139191499997198995898179681198268479688712943414819511197717969357964626 +8894829141789688146813983655599262175354512492811217287197518971727198974788999775881793393394664199 +6989187141894459991973787674231495975898898321231239587159329169888699482823813357919299199727591361 +5291418199993963928598629179855771924331332887583129988192175911928891699934755817621873135693191816 +9859979117149771714936925976542992919833772828551725982321627568959639165547556486133816386958767691 +7859228193989921397351284929914697967294416985799189145628697417412211943669121428893746928296129853 +9898681974164499972995857666974959138563814594959416796689799455999579812615141516926348999849199192 +3718388972799194318442969794235896693965351819955961988597649825892827718431384296684438269296581369 +6622814526191793264982158196814969278991591173839699792937584466991496599918911981477179793167467286 +9979379866996693519416698914822874331128813255572798589585921254251617789813794989743747235329888595 +1797898211694565884562549271126691989581781692389727679449696138934914999198975329972191479272399949 +8799526921898877188579896888615687919221936817161219171496896799791784217996429736635848912899357959 +3998179987191983936537841259615889646999196799579578519955782169872772733999838687699675879992385199 +4629983158488678918339598918897184289885199997966199238946856787429929894529981431432825472899789379 +2648419335213961853594831348897955886326266994947879975892927267713419578719291698994997922172724295 +4791456616384992968619169989914284879576442418663919488293715173289682167949877799818988158798898697 +8231746913997992473892883523293984991882222989389687618931693321291896977659253682566976938919319772 +8791786476374176864813358771936196161691499499725886199548984199739722733758439858858114991899439768 +7864649397847188893939876129989155438478439599981116718616269385899323813687798117158931299417619263 +1516286662577862992677589421596899929673339521868597254888585791795752635967517418681822599565577716 +6187189898988162537924787542999557639266889281629557986986981493311772812199877994518195163178939239 diff --git a/Advent-of-Code-2021/AOC-15/input.txt~ b/Advent-of-Code-2021/AOC-15/input.txt~ new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Advent-of-Code-2021/AOC-15/input.txt~ diff --git a/Advent-of-Code-2021/AOC-15/sample.txt b/Advent-of-Code-2021/AOC-15/sample.txt new file mode 100644 index 0000000..ab80887 --- /dev/null +++ b/Advent-of-Code-2021/AOC-15/sample.txt @@ -0,0 +1,10 @@ +1163751742 +1381373672 +2136511328 +3694931569 +7463417111 +1319128137 +1359912421 +3125421639 +1293138521 +2311944581 diff --git a/Advent-of-Code-2021/AOC-15/sample.txt~ b/Advent-of-Code-2021/AOC-15/sample.txt~ new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Advent-of-Code-2021/AOC-15/sample.txt~ diff --git a/Advent-of-Code-2021/AOC-2/aoc-2 b/Advent-of-Code-2021/AOC-2/aoc-2 Binary files differnew file mode 100755 index 0000000..c15492c --- /dev/null +++ b/Advent-of-Code-2021/AOC-2/aoc-2 diff --git a/Advent-of-Code-2021/AOC-2/aoc-2.c b/Advent-of-Code-2021/AOC-2/aoc-2.c new file mode 100644 index 0000000..6c212b1 --- /dev/null +++ b/Advent-of-Code-2021/AOC-2/aoc-2.c @@ -0,0 +1,104 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int pos = 0; +int depth = 0; +int aim = 0; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if (fp == NULL) + { + perror("Error while opening the file.\n"); + exit(EXIT_FAILURE); + } + + char command; + char char_x_val; + int current_type = 0; // 0 - command; 1 - skip; 2 - val + /* Part 1 + while((ch= fgetc(fp)) != EOF) + { + if(ch == ' ') + { + current_type = 2; + } + else if(ch == '\n') + { + int x = atoi(&char_x_val); + switch(command) + { + case 'f': + pos += x; + break; + case 'd': + depth += x; + break; + case 'u': + depth -= x; + } + + current_type = 0; + } + else if(current_type == 0) + { + command = ch; + current_type = 1; + } + else if(current_type == 2) + { + char_x_val = ch; + } + } + */ + + /* Part2 */ + while((ch= fgetc(fp)) != EOF) + { + if(ch == ' ') + { + current_type = 2; + } + else if(ch == '\n') + { + int x = atoi(&char_x_val); + switch(command) + { + case 'f': + pos += x; + depth += aim * x; + break; + case 'd': + aim += x; + break; + case 'u': + aim -= x; + } + + current_type = 0; + } + else if(current_type == 0) + { + command = ch; + current_type = 1; + } + else if(current_type == 2) + { + char_x_val = ch; + } + } + + fclose(fp); +} + +int main(void) +{ + ParseInput("input-2.txt"); + printf("pos: %d, depth: %d; product: %d", pos, depth, pos * depth); + return 0; +} diff --git a/Advent-of-Code-2021/AOC-2/aoc-2.c~ b/Advent-of-Code-2021/AOC-2/aoc-2.c~ new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Advent-of-Code-2021/AOC-2/aoc-2.c~ diff --git a/Advent-of-Code-2021/AOC-2/input-2.txt b/Advent-of-Code-2021/AOC-2/input-2.txt new file mode 100644 index 0000000..c6b3290 --- /dev/null +++ b/Advent-of-Code-2021/AOC-2/input-2.txt @@ -0,0 +1,1000 @@ +forward 3 +down 4 +forward 3 +up 4 +down 4 +down 6 +down 3 +down 1 +up 7 +down 7 +forward 4 +forward 7 +forward 3 +down 2 +forward 5 +down 7 +forward 5 +up 9 +down 6 +forward 8 +forward 8 +down 8 +forward 7 +down 9 +down 4 +down 6 +forward 1 +down 2 +down 7 +up 4 +forward 8 +down 5 +down 7 +down 1 +forward 5 +down 1 +up 1 +forward 5 +forward 1 +down 1 +forward 3 +up 4 +up 4 +up 8 +up 1 +forward 7 +down 3 +forward 3 +forward 3 +down 3 +down 6 +down 7 +forward 4 +down 2 +up 3 +forward 5 +forward 1 +down 3 +up 3 +up 4 +forward 2 +forward 6 +up 1 +down 9 +up 3 +forward 5 +forward 2 +up 9 +up 2 +down 5 +down 5 +forward 7 +forward 1 +down 7 +forward 9 +forward 8 +down 7 +forward 5 +forward 4 +down 5 +forward 7 +forward 3 +down 2 +forward 2 +forward 2 +down 1 +up 8 +down 2 +down 2 +forward 6 +up 9 +forward 6 +up 6 +forward 5 +forward 5 +down 2 +forward 5 +up 5 +forward 5 +up 4 +down 1 +up 5 +down 2 +forward 3 +down 1 +forward 2 +up 4 +down 6 +forward 1 +forward 6 +forward 6 +forward 8 +forward 8 +forward 3 +forward 5 +down 8 +up 8 +down 6 +down 8 +forward 8 +down 6 +forward 4 +down 4 +forward 7 +forward 9 +down 6 +up 6 +forward 6 +down 9 +up 7 +up 9 +down 1 +up 5 +forward 2 +forward 3 +up 6 +forward 8 +forward 7 +down 4 +up 8 +up 2 +down 2 +up 3 +down 2 +down 8 +forward 9 +up 9 +forward 7 +down 9 +forward 4 +forward 3 +forward 2 +down 5 +forward 3 +forward 1 +down 2 +forward 3 +down 7 +down 8 +forward 9 +down 9 +forward 2 +up 5 +up 2 +down 8 +down 1 +down 7 +forward 6 +down 2 +forward 9 +down 6 +down 9 +forward 9 +down 2 +up 5 +forward 2 +down 7 +down 6 +up 1 +forward 9 +up 7 +down 1 +forward 5 +down 5 +up 2 +forward 6 +forward 2 +up 9 +up 7 +down 2 +down 1 +forward 6 +down 2 +forward 9 +forward 8 +forward 2 +up 1 +down 7 +down 7 +forward 5 +forward 9 +down 5 +down 5 +down 5 +forward 4 +up 4 +down 7 +up 6 +forward 3 +up 5 +forward 3 +forward 6 +forward 8 +down 6 +forward 4 +forward 5 +up 8 +down 9 +down 3 +down 8 +forward 8 +forward 1 +down 7 +down 2 +forward 8 +forward 7 +up 2 +down 9 +forward 2 +down 6 +down 7 +up 2 +up 7 +down 6 +down 8 +down 2 +forward 8 +down 6 +up 1 +down 6 +down 5 +down 8 +down 1 +down 4 +down 1 +down 8 +up 3 +forward 1 +forward 5 +forward 2 +forward 2 +down 5 +down 2 +down 8 +up 7 +forward 2 +forward 1 +forward 4 +up 4 +down 5 +up 4 +down 8 +up 5 +down 6 +down 8 +down 8 +forward 8 +forward 5 +down 1 +down 2 +down 4 +forward 5 +up 3 +forward 3 +down 7 +forward 9 +down 9 +down 5 +forward 5 +down 9 +forward 9 +down 5 +up 4 +up 9 +forward 1 +forward 6 +forward 9 +forward 2 +up 5 +forward 9 +down 8 +up 2 +up 9 +forward 1 +down 7 +down 4 +down 4 +up 3 +forward 6 +down 1 +forward 6 +forward 3 +up 3 +forward 1 +down 1 +up 8 +up 3 +forward 9 +forward 1 +forward 8 +forward 8 +up 7 +forward 2 +forward 9 +down 9 +down 2 +down 5 +down 1 +forward 9 +forward 9 +up 4 +forward 6 +down 3 +forward 2 +forward 5 +up 4 +forward 2 +up 1 +up 4 +up 3 +up 6 +up 6 +down 2 +up 7 +down 1 +down 3 +forward 3 +up 5 +forward 4 +down 5 +forward 9 +down 2 +up 5 +forward 9 +down 3 +down 5 +forward 3 +forward 7 +forward 9 +up 2 +down 6 +up 6 +down 8 +forward 8 +down 1 +forward 3 +forward 4 +up 6 +up 3 +forward 6 +forward 5 +forward 2 +down 7 +down 1 +down 5 +forward 6 +down 4 +down 2 +forward 7 +up 9 +forward 3 +down 2 +up 3 +down 3 +down 1 +up 5 +down 4 +forward 1 +forward 2 +forward 2 +forward 6 +forward 2 +down 2 +down 8 +down 1 +down 2 +down 7 +up 7 +down 7 +forward 7 +forward 7 +down 8 +forward 1 +down 7 +down 7 +down 8 +up 9 +down 4 +up 6 +forward 7 +up 2 +down 8 +forward 2 +down 8 +forward 4 +down 4 +forward 4 +up 1 +down 2 +forward 6 +forward 7 +forward 8 +down 2 +forward 5 +forward 1 +up 9 +down 8 +down 2 +forward 1 +down 8 +forward 2 +up 2 +up 3 +up 7 +forward 3 +forward 3 +up 3 +up 5 +forward 8 +down 6 +forward 6 +down 2 +down 7 +forward 3 +forward 6 +down 5 +down 6 +up 4 +forward 8 +up 8 +down 9 +forward 7 +forward 1 +down 6 +up 1 +down 7 +forward 4 +forward 8 +down 2 +forward 8 +down 3 +down 5 +down 5 +forward 8 +down 3 +up 8 +down 9 +forward 2 +down 9 +forward 4 +up 8 +forward 4 +up 1 +forward 8 +forward 2 +forward 5 +down 2 +down 6 +up 2 +down 8 +forward 9 +forward 5 +forward 6 +forward 4 +down 4 +down 6 +up 1 +forward 3 +down 6 +forward 6 +forward 1 +forward 6 +forward 9 +up 6 +forward 5 +down 4 +forward 5 +down 8 +down 7 +forward 7 +up 5 +down 6 +forward 4 +forward 6 +forward 5 +up 4 +down 3 +forward 1 +down 1 +forward 6 +up 1 +up 1 +down 7 +forward 5 +forward 1 +down 2 +forward 2 +down 3 +down 6 +down 5 +down 4 +forward 2 +forward 1 +down 7 +forward 9 +up 6 +forward 9 +forward 2 +down 1 +forward 9 +forward 4 +down 1 +forward 3 +up 9 +down 1 +down 3 +down 6 +down 9 +forward 3 +down 8 +down 3 +forward 5 +forward 1 +forward 5 +forward 2 +up 4 +down 6 +up 7 +forward 7 +down 9 +forward 6 +down 4 +down 1 +up 8 +down 4 +forward 7 +forward 5 +down 5 +down 2 +down 1 +down 4 +up 5 +down 8 +forward 1 +forward 2 +down 9 +forward 7 +down 8 +forward 5 +forward 7 +forward 2 +down 6 +down 5 +down 6 +down 7 +forward 2 +up 9 +down 3 +forward 1 +up 6 +forward 4 +down 3 +up 7 +forward 9 +forward 7 +down 4 +up 1 +forward 6 +up 4 +down 1 +down 4 +down 2 +down 5 +down 4 +down 7 +forward 2 +down 8 +down 8 +forward 9 +forward 3 +down 2 +down 2 +forward 2 +down 9 +forward 8 +up 8 +down 3 +forward 4 +down 9 +up 2 +forward 6 +forward 2 +up 6 +up 7 +forward 1 +forward 2 +up 2 +down 8 +forward 9 +down 7 +forward 1 +down 6 +down 8 +forward 2 +down 8 +forward 6 +forward 7 +forward 8 +forward 1 +up 8 +down 5 +forward 8 +down 3 +down 6 +forward 6 +down 4 +down 6 +forward 8 +down 3 +down 4 +forward 6 +forward 1 +up 1 +up 3 +forward 7 +forward 2 +down 1 +down 7 +down 3 +down 4 +down 3 +forward 2 +forward 4 +down 6 +down 2 +forward 3 +down 9 +down 5 +down 6 +down 7 +down 5 +down 3 +forward 5 +forward 6 +down 3 +down 1 +up 3 +down 8 +down 7 +down 5 +up 9 +down 8 +down 4 +down 2 +forward 4 +forward 9 +forward 1 +forward 7 +down 3 +down 4 +up 9 +down 6 +forward 9 +down 4 +down 2 +down 5 +down 3 +forward 2 +forward 9 +forward 3 +down 5 +up 1 +down 9 +forward 9 +down 7 +forward 6 +down 6 +down 9 +down 7 +down 8 +down 2 +up 3 +forward 6 +forward 3 +up 4 +down 6 +down 8 +down 2 +down 1 +up 9 +down 1 +down 8 +forward 5 +forward 4 +forward 9 +forward 3 +forward 9 +down 5 +up 9 +down 6 +forward 4 +down 6 +forward 4 +forward 9 +down 7 +up 9 +up 2 +forward 5 +forward 6 +up 2 +forward 8 +down 6 +forward 8 +forward 1 +forward 2 +forward 6 +down 3 +up 2 +forward 7 +up 8 +forward 2 +forward 5 +forward 4 +up 6 +forward 9 +up 8 +down 3 +up 7 +up 2 +down 2 +up 4 +up 5 +forward 5 +down 9 +forward 2 +down 1 +down 6 +down 4 +down 1 +down 1 +forward 4 +forward 7 +down 4 +down 2 +forward 7 +down 4 +up 1 +up 8 +down 6 +down 8 +forward 6 +down 8 +up 2 +down 7 +forward 5 +forward 8 +down 9 +forward 1 +up 7 +down 5 +up 1 +up 6 +down 3 +down 4 +down 9 +down 6 +forward 1 +down 1 +forward 4 +down 4 +down 8 +up 1 +down 7 +forward 1 +down 6 +down 4 +down 5 +forward 6 +forward 8 +down 5 +down 5 +up 3 +forward 8 +down 4 +down 3 +up 1 +up 8 +forward 1 +down 6 +down 2 +down 6 +down 1 +forward 9 +down 1 +forward 6 +forward 9 +down 5 +up 4 +down 5 +down 1 +forward 2 +down 2 +forward 9 +down 3 +forward 7 +forward 8 +forward 5 +down 7 +down 6 +down 8 +forward 7 +up 7 +forward 6 +forward 3 +down 2 +forward 9 +forward 4 +down 6 +down 6 +up 9 +down 1 +forward 5 +forward 2 +forward 2 +forward 2 +down 8 +up 1 +down 4 +forward 3 +down 3 +up 4 +down 6 +forward 2 +forward 8 +forward 9 +forward 3 +down 4 +forward 2 +forward 5 +down 5 +up 8 +up 9 +up 3 +forward 9 +forward 3 +forward 3 +forward 8 +forward 2 +forward 7 +down 8 +down 6 +forward 6 +forward 8 +down 1 +forward 3 +down 7 +forward 5 +forward 3 +forward 3 +down 3 +down 5 +down 2 +down 6 +up 2 +up 7 +down 9 +forward 6 +down 9 +down 8 +up 8 +down 1 +forward 9 +down 8 +forward 7 +forward 6 +down 5 +down 7 +down 4 +forward 7 +down 8 +down 9 +down 4 +up 8 +forward 2 +up 6 +forward 6 +forward 3 +forward 6 +up 9 +forward 1 +down 3 +up 6 +down 8 +up 4 +up 5 +forward 8 +forward 5 +forward 3 +forward 3 +forward 4 +down 4 +forward 2 +up 2 +down 7 +down 5 +forward 7 +down 8 +forward 3 +up 5 +down 4 +down 1 +down 5 +forward 6 +forward 8 +forward 6 +down 2 +down 7 +forward 6 +forward 2 +forward 7 +down 5 +forward 2 +forward 7 +down 9 +down 9 +down 4 +down 7 +down 3 +forward 1 +up 8 +down 7 +forward 2 +forward 4 +up 2 +forward 2 +down 2 +up 2 +up 9 +forward 1 +down 5 +down 1 +forward 8 +up 3 +up 4 +down 3 +up 2 +down 8 +down 6 +down 4 +up 7 +forward 4 +down 7 +down 4 +up 3 +up 8 +down 1 +down 7 +forward 1 +down 2 +forward 6 +down 9 +forward 3 +down 9 +up 5 +up 1 +down 4 +forward 1 +down 4 +forward 4 +up 4 +forward 7 +down 9 +down 2 +down 8 +forward 2 +up 3 +forward 2 +down 7 +forward 8 +forward 6 +forward 1 +up 9 +forward 7 +up 4 +down 4 +down 3 +down 7 +forward 5 +forward 3 +forward 7 diff --git a/Advent-of-Code-2021/AOC-2/input-2.txt~ b/Advent-of-Code-2021/AOC-2/input-2.txt~ new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Advent-of-Code-2021/AOC-2/input-2.txt~ diff --git a/Advent-of-Code-2021/AOC-25/aoc-25 b/Advent-of-Code-2021/AOC-25/aoc-25 Binary files differnew file mode 100755 index 0000000..1528c81 --- /dev/null +++ b/Advent-of-Code-2021/AOC-25/aoc-25 diff --git a/Advent-of-Code-2021/AOC-25/aoc-25.c b/Advent-of-Code-2021/AOC-25/aoc-25.c new file mode 100644 index 0000000..089b141 --- /dev/null +++ b/Advent-of-Code-2021/AOC-25/aoc-25.c @@ -0,0 +1,154 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <math.h> +#include <stdint.h> + +#define XLEN 139 //10 +#define YLEN 137 //9 +#define LEN (XLEN * YLEN) + +typedef struct Sea_cuc_move { + int from_pos; + int to_pos; +} Sea_cuc_move; + +char map[LEN]; +char map_bak[LEN]; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if(fp == NULL) + { + fprintf(stderr, "ERROR: something with file idk what fuck you"); + exit(EXIT_FAILURE); + } + + int i = 0; + while((ch = fgetc(fp)) != EOF) + { + if(ch == '\n') continue; + + map[i] = ch; + i++; + } + + fclose(fp); +} + +void Move(char type, Sea_cuc_move pos) +{ + map[pos.from_pos] = '.'; + map[pos.to_pos] = type; +} + +void MoveEast() +{ + Sea_cuc_move positions_east[5000]; + int cucs_east = 0; + + for(int i=0; i<LEN; i++) + { + if(map[i] == '>') + { + int x = i % XLEN; + if(x == (XLEN-1)) + { + if(map[i - x] != '.') + continue; + + positions_east[cucs_east] = (Sea_cuc_move){i, i - x}; + cucs_east += 1; + } + else if(map[i+1] == '.') + { + positions_east[cucs_east] = (Sea_cuc_move){i, i + 1}; + cucs_east += 1; + } + + } + } + + assert(cucs_east < 5000); + + if(cucs_east != 0) + for(int i=0; i<cucs_east; i++) + Move('>', positions_east[i]); +} + +void MoveSouth() +{ + Sea_cuc_move positions_south[5000]; + int cucs_south = 0; + + for(int i=0; i<LEN; i++) + { + if(map[i] == 'v') + { + int y = floor(i / XLEN); + if(y == (YLEN-1)) + { + if(map[i%XLEN] != '.') + continue; + + positions_south[cucs_south] = (Sea_cuc_move){i, i%XLEN}; + cucs_south += 1; + } + else if (map[i+XLEN] == '.') + { + positions_south[cucs_south] = (Sea_cuc_move){i, i+XLEN}; + cucs_south +=1; + } + } + } + + assert(cucs_south < 5000); + + if(cucs_south != 0) + for(int i=0; i<cucs_south; i++) + Move('v', positions_south[i]); +} + +void NextStep() +{ + MoveEast(); + MoveSouth(); +} + +void PrintMap() +{ + for(int i=0; i<LEN; i++) + { + if((i % XLEN) == 0) + printf("\n"); + printf("%c", map[i]); + } + printf("\n\n"); +} + + +int main() +{ + ParseInput("input.txt"); + + for(u_int64_t i=0; i < 10000; i++) + { + memcpy(map_bak, map, sizeof(char) * LEN); + NextStep(); + + if(strcmp(map, map_bak) == 0) + { + printf("EQUAL after: %llu\n", i + 1); + exit(0); + } + } + + PrintMap(); + + return 0; +} diff --git a/Advent-of-Code-2021/AOC-25/aoc-25.c~ b/Advent-of-Code-2021/AOC-25/aoc-25.c~ new file mode 100644 index 0000000..4e13045 --- /dev/null +++ b/Advent-of-Code-2021/AOC-25/aoc-25.c~ @@ -0,0 +1,139 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <math.h> +#include <stdint.h> + +#define XLEN 139 //10 +#define YLEN 137 //9 +#define LEN (XLEN * YLEN) + +typedef struct Sea_cuc_move { + int from_pos; + int to_pos; +} Sea_cuc_move; + +char map[LEN]; +char map_bak[LEN]; + +void ParseInput(char *input) +{ + for(int i=0; i<LEN; i++) + { + if(input[i] != '\n') + map[i] = input[i]; + } +} + +void Move(char type, Sea_cuc_move pos) +{ + map[pos.from_pos] = '.'; + map[pos.to_pos] = type; +} + +void MoveEast() +{ + Sea_cuc_move positions_east[5000]; + int cucs_east = 0; + + for(int i=0; i<LEN; i++) + { + if(map[i] == '>') + { + int x = i % XLEN; + if(x == (XLEN-1)) + { + if(map[i - x] != '.') + continue; + + positions_east[cucs_east] = (Sea_cuc_move){i, i - x}; + cucs_east += 1; + } + else if(map[i+1] == '.') + { + positions_east[cucs_east] = (Sea_cuc_move){i, i + 1}; + cucs_east += 1; + } + + } + } + + assert(cucs_east < 5000); + + if(cucs_east != 0) + for(int i=0; i<cucs_east; i++) + Move('>', positions_east[i]); +} + +void MoveSouth() +{ + Sea_cuc_move positions_south[5000]; + int cucs_south = 0; + + for(int i=0; i<LEN; i++) + { + if(map[i] == 'v') + { + int y = floor(i / XLEN); + if(y == (YLEN-1)) + { + if(map[i%XLEN] != '.') + continue; + + positions_south[cucs_south] = (Sea_cuc_move){i, i%XLEN}; + cucs_south += 1; + } + else if (map[i+XLEN] == '.') + { + positions_south[cucs_south] = (Sea_cuc_move){i, i+XLEN}; + cucs_south +=1; + } + } + } + + assert(cucs_south < 5000); + + if(cucs_south != 0) + for(int i=0; i<cucs_south; i++) + Move('v', positions_south[i]); +} + +void NextStep() +{ + MoveEast(); + MoveSouth(); +} + +void PrintMap() +{ + for(int i=0; i<LEN; i++) + { + if((i % XLEN) == 0) + printf("\n"); + printf("%c", map[i]); + } + printf("\n\n"); +} + + +int main() +{ + char *input_str = ">.>.>.>>>vvvv>>v...v>>.vv.v>>>>>>.v>....>>.v.v.>>....>.v>v>..vvv.v..vv..v>..v.>.v>v...>..v>>v.v......>vv...>>..v>.v>.....v.>.v.......>.>>.v.>>....>>.v.>.vv..vv.v>..>...v..>...v.v...>v.>>.vv..>...>>..>...v>....>...>>.>..>...>.v.>..>v>.>>v>...>.>..>.v.>..v>>vv>v.v>>vv.v..>>v>.vv.vv>.vv>>vv......v.....v..vv.v>....v>.>v>.>.vv>..>..vvvv>.v...>>v..vvvvv>>.v....v.>..v>>>....v...>.vv>...>v>.v.vvvv.>>..>>..>.>>.>v.v.>v>>>.v>.v.>>>>.v...v.vv>.>v>.v>v.>>v.v>>...v.v.v...vv.>vv>v>>.vv.v..v>>.v>.>..>.v.v..>v.v>...v..vv>.>vv...>.v>..>.>>..v..v..v>..v.v...v>.>vv.v...>>>...v...v.vv>.....v.>vv>>.>>..>..v....vvvvv...v>.v.v.vv.vv...>...vv.v.>v..v>.>.v..v.v>v>...v...>.>.>>>..vv...>v>>.>>v.>..>.>v.v.v.vv.v.v>.>.>..v.v.>>..>..>..>v..>.>.v.>.v>>>v.v>v...>>vv.>>>>.vv...v>......v>v....vv..v>..>.v>..>.v>.>>..>.>v>v>v.v.>..>..>..v..>>...>.v>...v.v.vv>.>..>>.v..>>.v>v.v...>>v>v.>...>.v.>v........v..>>...>..>v.>v..v.vv..>v.>>vvv.>>>>>v>v.vv.>..>v>>>.vv.v>vv.v>...>>>...>..>..>.>v..v..vv>..>>.>>v>.v.......v.vv..v.v......v.v...>..>..>>>..v>...>.....vv..>>.>.vvvv>....>vv..>.>>v.........v.>>>>....>.>.>..v>...v.>...>.>>>..v.v>>.v>>v.vvvv.....>v.>.>>vv.v.v...>>.>.>v.v..>v..>v>>.>..>.>v.v..v>>.v>..>...v.v>vv>.vv>v.>v.v..>>.vvv>..>..>>v..v..>>.vv>..v.>.v.......>..vv..vv.>.>vv..>.>.>vvv.....vv>>....>.>>....v>vvv..>>v.vv>.>.>.v.vv.>....v>..>........v>v>.v....>v>>...vv.>..vv.>>.v..>.v>>.>>.v>.>.>vvv.vv..>..>.>>v..vv......>>v...vv.v.v.>>v......>>v.>..>.>vv>..>.v>>...v.>......v...>..>.>vvv..>v.....>v.>v..v......v..>...>>v>.v...>v>v.>>..>v.>.v.vv>..vv>.>.>.v>..>>....>v>.>.>>>>.......v>v.v>....>>.v..v........>>.>>vvv>..v.vv..>.>....>>vv>v..v>>..>..v>.>>.>.>v.>.vv.>...>.vvv>>......>.>>>v.v...v.v...v>v.>>.v.>.>vv.v.....v.>>>>...>.>..v..v>....>.v>.vv>....vv.>>..v>vv>..>.v>.>v.....v.v>.>.......v..>vv....>.vvv.v..>>v>...v.v..v.>v>v.vvvv>.>vv.vv.vv.>v....>v>..>.v.>>..>>.>>>>.......>>>..v..>>...>>>.>vv>v..>...v..v..vv.vv...v....>...v>..>.>.>.>vv..>.>.>..>..v.v.....>.>...>>vvv.v..>...>....v...v...v..>v.....v.>v.v..>.v>>..>.vv...>...v..v>v...v...>.v.v>vv..>...........v.>>.v>>.>vvv.v.>>>>..>v>v>>>.>>..>...v>v..>>..v.>...v.....>...>..>>>v..vv>...v.v.v.v>>>.v.vvvv.v..>>.v.>v>..vv...>>>.>...>>v>.....v>.v.......v>.>v...>.vvv>>..>v...>..v..v>>vv.v.>v>vv...v...v...>.>...>.v.>>v>..>>.>>>v.>.v.>>.>..v.>vv>v..>vv>...>..>v....v.>>v....>.v.>>.v.vv>vv>.v.>>v.v>..>..vv.v>.v>v>v>..>.>...>>..v>>>.v..>.v.>>.v.>>vvvv.>>v..vv..>v.>.>...vv>.v.v>v>v..>.>>.vv>...v>.....>>vv.>v.>.>..v...v..v.v.>>v.>....v..v>vv>v..>vvvv...>.>.....v.v.v>....vv.>.v.v>>>v....>..........v..>.v..v....v..>.v.>.vvv>vv>v.......>..>v......v>vv...>...>v>>>.>v.vv.v.v>>.v.v>.v.>.>.v.>v...v......vv....v.v.>vv.>.v>.v..v.v.v.>>......>.v.>>.>>.v...v.>>>v.....>>>..>.v..>>..>.v>>.>v>..>...>.v...>>..vv.>>>>>>>>....>>...v.vvv>>..>>.>..>>v.v.vvv.v...>.>>..v>>>v.v.....>.v>.>>>>...>>..v.>.v.........>v>..v..v>v>...v>v>...v....>..v>.>...v>vv>>>...v..>.vv.>v...>.>..........vvv.>vv.>.>vv>>>>vvv>>v.>.vv>v>v....v>.v>...v>>vv..>v...>>.v.>....>.v.v>.vv...vv....vv....>..v>.v..vvv...>>.vvv.>.vvv.>.>>..v..>>.v..>>.>v>v>>...>.v.vv.>.v>.>v.v.>.v...>...>>.>...>v.v.vv..>.>v.>vv>.v>...v>.>...v.>>..>v>>>>.>>.>>v..>.vv..>.>..>v.>.v>>>....>.>..vv.v>vv>.>...>>.v..>>...vv.v..vv.>v>..>v..>>..>.>>.v.vv.vv.>.>>v>.v>vv.>vv.>vv..>.v...>>.vv...v..v.>.v.>.....>v...>..>.....>.>>v.......v...v.v.>.>...v.>......>.>...>>.>.v>vv>..v>v>v>.>>v>...vv...>>>vv.>.vvvv..>.v.>>v>vv.>..>>..>v.>..v.v..>v..>>v..>...>.>.>..v...vv.>v.vv....>>v.v>....>...>.v..>v.v.v...>>>>.>>.vv.v...v>vvv.v>...>v....>..vvv.vvv.v.>>v...>>>.>..v....v>>>v....vv.v>.>..v..>.....>..>>..vvv>>vv...v..>.v>>...v>v.v.v.>v.v.v>>..vv..>.v..>.>..v....v....v>>.>..v>.>>..v>>>.>v..vv.v>vv..v.v>.v.v...v>>...>>vv>>vvv.>.v.>v..vv>>...vv.......v..>vvvv>>.>...>.v>>vv..>...v....v.....>..>>>v.>>>>>.v.vv>...>..>>>.>....>v>>....v..>..>v.>>.v>.vv....>...>.>..>..v...>>v...v....>v.....>>.>.>>>.>>.>..>>.>>>>>.>v.v>>vv>>.>>>.>vv...v>...v.>v>v>>.vv.>v.>v....v>.>v..>...>>>v....>..>...>.vv>>.>...>vvv...vv.v.>v......>.v>vv.v.vvv>>..v>>.v>.v..vvv.v.v.>>.>>v.>.v.>.>>v..v.vv>>.>..vv>>..v>vv>>>v..>..>...>..>v.>...>>>..v..v.>vv>.>.....v.v>.>>.v>v.>..>.v...v>..v>........>>.vv...>.v..>>v>v..v.>v>>>...>.>>..>.vv>v..>v>v....v..>...>....>....>..>...>..v>v...v..v....>.....>.v..v....v.v..vv......vv.>vvv>..vv>v..v>v.v>v>.>....v...>>>>>..>..>.v..v..v...>vv.>.v.>v..>..vv.v.>.v.>>>v.vvv....v>....v.v.v..v....v...v>v..v...>v.>v..>.v>..>>..>v>.vv.v..>.>>v>.>..>>>v.v...>.>....>..>..>v.......>v>v.>.>.vv.>..>v>>.>.............>.>v>..vv>.vv>..>>.>..>....v>>v....vv>....v>.>.v.v.v>....v.>.vvvv>vv.v>.>v>vv>>..v..>>...v>..>>..>>..v.v..v...>vv>>.>.>..>>...v.vv.....v..v..>...v.v..>>.....v>>...v>..vv..>>.v.>>>v.>...v.v.......vv.vv...>>...>>v>..>.>vvvv..>v....vv>.v>>v..vv.v>>vv.>v>.v..vv..>..v..v.>.>.vvv..vv..>..v>v.v.>.vvv>vv.>.......>>>vv>>...>v.v.>>vvv..>..v.>v..>vv>v.vv........v>.>....v.>.....>.>>v.vvvv..v.>..>..v.v...v.vv>>.v>..>.>>vv..>.v>>..>vvvv.v..>.v.>>....>.>..>>.v>...>vv...v.>>vv..v..>vv>.>.v>.vvv>>.>.v.v...>...>v.>.......v.>.v>.>.v.>.>.>.>.v>.vvvv.>v>.>>..>...vv...v>.v>>.>.v>.>vv...v..>..v.v>>v>.vv.......>...>v>v.v.v>>...>.>v>.v...>.>.>>..>vvv>>...v.v..>v..v>..v.>v.v.>.v.v.>v.v.v>.>...v..>..vv.vv.>.v>..v>v.v.v.v.>...v>v..>v.v>v>v>.>.....v.v.>..v..v.v.vv.>>>.vvvvvv.>......v>>>v.v>v....vvv>.>.>.>v..>..>v.>..v.....v>v.v.v.v...>.>..>.v>..v.v.vv..>.>.>..>>....v>>..>.>v....vv..v...>>v.>....>..v>.v.v.>.>......>v>v.v..>.>>.>v>...>...>vv........>vvvv.>v>>...v...v....>vv.vv.>v.>.vv>..v.>...>v...>vv>..vvv>.v...v.>..>v>>v...vv.vv....>>.>..>v>..>>...vv..v>.>.v..vv.>.v..v..>.v.>>..>>v.v..vv.v.v.v.v.>v.>>...>v......v..>.>.v.vv>>.>...>v.....>v.vv>.>.....>vv>.>...>vvv>..>>.>....>>.vv.v.>v>v.v....vv....>...>>...>...v>.>..v.>.vv.>vv>>vv.v......>.>..v....>.>.>v.>v>..vv..vvv......>v..v..>>>.>v>>>...v.>.v>vvvv.v.>>...v.>v.v>..v.>vvv.v...v>...v.v>v.>.>.>v..>v.>.>vv.>vv>>>.>>>>v>v..v>v..>..>.v>...v......vv>...>v..>.v>...v.v>...>.>>.v>...>...v..>>...>..>..>>..vv.v.>v.>>>..>>>>..>>.>..>.>>..v.v>.....v.v>v>>vv.vvvvvv....>v...v..v>v....>...vv>v....v>v...>>.v.vv.>>v.vv.>vvv.......>..v.v>>>..>..>>......>>......v......v..v....v...vv..>>.v.>......v.>>...v>..v>>v>vvvv..v...>>.v>.>.v...vv>>..v...>.v...v..vv>>..>..v>.v>vvv>v.>.vv.v..>.v..>>........>.>.>.>vv...>..v..>v.v>.vvv....>....v>..>>v>>vv>.>..>v....>>>.>.>>.vv.v....vv.v.>>.....v.v>...v>>>.vvvv.vv.>.v>v.vv.vv>>.vv..v.>>.vv>>vv>.v..v.>v.>....vv>....>v.....v.>..>..>v.>.>..v>>.v>.>>vvvvv.v>>..vv>.>.....>vv.v..vv.>>.>>...v..>....>.vv.>>...v.>v>....vv>>....v>...v.>..v>.....v..>.v.vvvv.v..v>>.v....>.v>.>>..vv.>v>..v>.......vvv..vvv>...>v>..>>...>.....>...v..v.>>>.v>.v..v>>>>..>..vvv>.v..>v...v>v.>.>.>.>.>.>>..v.>.v..vvv>v>.............v.>.v.v.v...v.v.>v...v.>.v>..>..vv>...v.>>....v..v..vv..>>.....>v..>.....v>.v..v.>.v>.v>vv.v.v>.>.>.>>.vv>v>.v>.>......v>v..v>v.v.>>v>.>v.v>v.v>>>v>..vvv>>.v.v>>>v....>.v.....>v>>....v..v>v...>v.....v.v.>..v>v>v>>>..>.>v...v..>v.v...vv..>....>v.>>>v..v.v>vvvvv>v>...v...>>..v.v.v>vvv>v.>v>.>v.v...>.....v..>>.v.>.vv.>v.v>>>v...v>>>.>...>vv..>.v>.v.v...v.>....>.vv.v..>>.>....v...>....>.>>>v..vvvv.>vv.vv.>>>>..v>v>..>v>.v.>...>..>.>.vv.>>.vv>.vvv.v.>v>v>....v.vv.>v.>...v>.>>.......>>.v.>v>.>vvvv>>vvv.v>>v.v.>.>.vvv>.>v....v...v.>v.vv...>>>vv..vv..vv...>..>>.v....vv>>>v..v.v......vv.vv..>..v.>.v.>v..>..vv.>...v.>vvvv>v.>vvv.>.>..vv.>.>.>...v..>..>v..>...v>.>v>.v.v>>..>..vv>.v....vvv>.>.>>.>>..>v>>.v>.v.>>..>>v.>>.v...v.v>>>v>..vv.>>..v>.....>vvv.>>..>.>>.>v.>vv.>.v.v...v....>>.>..v.>v..v>...>.v...v.>>.>v.v.v.>vv>...>............vv>>>v>v>...>v>>.vv.>v...>>.v.v....v>vv..>..v...>....>>>..vv>...v..v>>v...v.>v..>..v..>.>....v.>vv>..v>.>.vvv>..v>>.v.v>.>..v.>v..>....>.>>v>vv.....>...v...v....>>.vv....>.>>>>v.v.v..>>....v>.v..v>v...>>vvv.v>v..v>vv...>.v>.v>.>.v>...v.>.vv>..>....>..>>vvv.v....v.v>>>v.>>>>.>v.v.>>.>>...v..v.>...v.v>.>>..>....v..>....v.vv.>.v>v.>.vv..vv..>.v.>v>.>>>..>..v...>vv>vv>>v.>..v>>.vv.v.v..v>>.v.>.>...>.>..v.>.>......>.v.v>>.>.>>..v...v>.v.>>v..>>v.vvv.>......v.>v....v>v...>.....v..vv..>>v>.v..v...v.>.>>..v.v..v>..>.>vv.v>>>vv>..v.vv......v.v.>v.v..v..>..vv.v.v>>>....>..v.>v>...>.>.....v.>.v>>..>....vv>v>vvvv.v.>.>>...>.>.v.>v..>>v..v>.>..>.vv..vvv>v.>..>..v....>v..v.....v>>>..>.v..>vv...v.v....>vv>..v.>v>.>vv>v>v>>v>>>.v>vv.>..v>>v>v.v>.v..v.v>v>.v>.>.....vv>>>>...v..>vv>.v>>v.>.>....>...>...v>>.v.v.>...v.v>v..v>>...v>>>...>...v.>v.>>..>v.v>..>>>vvv..v>.>..v>>>>.>.v.>v.v....>....>...>.>.....>.v..v>.>v>.>>v.v>...v..>>>.vv...>..v..>>..v....>v....>v.>vv>v...v>.vv>.v>v>..v.v.vv..v...v..>>..>v>.vv.v.vv.>.v.....v...v.v...vv.v...v>..v.>....>.v>.>>vvv>.>.v>...>.vv>v...vv.v..>vvv...v.>..v.>.>>>.vv>v.vv.vv>v>v>>vv>v.>>vv..>..vv...>v.v>>..v...>>vv>>>>vv.>>v>v>.v>.v..v...>>..v>...v>>vv>.>.>.>>..>....>vv.v.vv.vv>.>v..v.>..v.>.vvv..>..v...v>>v>..v>>v...v..>>...>>vv>.v...v>.vvv......vv.>>.v...>>..>v>..v.v>..vvv>v.>>>v.v>.>...vv....>>>.v.>>>>v.v>vv>>....>>.>..v>vv>....v.>.>v...>.>v.>v>.v..>>..>v>v>..>..>v.>...>....vv>...v>.v..>v.v......v>>>........v.v>v..vvvvv>..>.vvvvv>>>.vv.vv>v...vv..>v>v.>.v>.>....v.>..v>..v..>>vv>>......>............>>>vv....v>v.>.>..>...>....vvv.v......v.>>>.....v.v.>...v.>v....v...v>..>>>..>..vv>>v.v>.>.vv.vv.>.v.>v>v>>.>>v..>......v..vvv.>>....v>v.>>vv>>..>..v>>>.>v.v>.....>v...v.v>..v>..>....v...>..vvv>...vv.>v.>...v>.v.v>....v...>>.v>>v...>>.>.v.v.v>v.vv>v.v.v..>>.v.>>.....>>>...vv.v>....>.>.>v.>v>.>>..>v.v.v>..>vvv....v....v>v.>...vv.>v>....vvv.....v>.vv..>..>>>v>v>v.>v.v>...v.>...vv.>....>>...>.v..vv>v>.vv.v....v>v>v>.>>.>>.>>vv...vv.vv>........v>v>.v.v>....v.vv.vv......>.>>v..>>>.>.>v...vv.....>>>.>.v.v...>.v.v..>.>.v.v.....>.vvv>>.v.>>.........vv.v..v>v>v>.v>>..vv.v....>>.vv.v>>.>>.>>..vv...v.v>v.>.v>>.vv..v...>...v...vvv>>.v...v.v>>>v...v..v...>>..v.>>v.vvv>...v.........v.vv>..v.v..>..>.>v>.>.>>..>v..>...v.v..v.vv>v.v...v..v>v>.>v.v>v....>....>v.v.>>..>>v>>.v..v>v.>>.>v.>..v....v>..>..>.v>..>v..v.....>.vv..>.......v>....vv..>v..>>v..>v....vv.vv.v.>v.>v.>...v.v...v..>..v..>>.vv.v.>.>...>>.>v>........>>v...>.>v...>..v.>>v.>...>..>..v>>vvv>.....>vv>....>......>>>vv>.>>..>>>..vv.v>vvv>v>vvv..v..v..>>.v>vv>......>>v.v>.>.>vv.>.vv..v..>.v>.....>v.>....>>v.vv.>>.v...vvv....v>>>..>..>.v.vv.v>v.....vv>..>.>.>>..v..>.>..v>.>....v>...>>>>........v..vv>v..v..v....v>>..v.vv...>.>.>..>.....>v>.v.v>v...>vv.>..vv..v>v>>v.>>.v..v>.vv>.v....v>v>..>...>..v..>..v..>>...>.>v>.>v>..>vvvv.v.v.>.v.v.>>...>vvv.vv..>>>.v>.>.v..>v..vvv>...>v>.>v.>>v>v>..>v........>v.vv.>>...v.v..vv.>...>..>..v..v...v.v.v.>.>vv..............>v....v.vv>>v..>...>.>>>..v>.v.vv....>.>>>>v>...>v.v.>v.v.v>.>...>>.....v....>.>...v..v..>..>>.>..v>>v.v..>.>vv>v.>..vv.vv..>v>.>..vvvv>vv.>.>>v.>.>>vv>vv>..>>v>.>...>>v>v..>>.>v..v.v>>.v>....>v>.v.>>>.v.v..>>.v>>.v...v.vv.v.>..v>..>...v..v..vv>.v....>.>>....v...v>>v.v>vv>....v..v>>.>v.v.vv>>vv>>.>>..>>vv>..v..v>.>......v..v.....>v...vvv.v...>.vv>...>.v..vv...v>....v>v..v.v>.v...vv...>.v..vv.v>.>v>>.v.>...v.>>v>..>.>..v.>vv.v...v>..>>...v>>vv..v.>.>v..>...v.....v>.>..v>>...v>>>.>..vvv.v>.>>.v>.v.v.>v>vv.vv>.v.v..........v>>..v...>..>>>>>.v.>>.vv....>.....vv>.>.>>>.v.>.>>..vv..v.v.>...>.>>...vvvv..v.>....v.vvv.v.>v....v>..>>vv.v.>>..>>.v>.>v.v...v..>.>.vv>.....v.>.vvvv>>vv.>.>.>v>..vv..>..>>v...v>...v.v..vv>.....>.>...>v.>..>...v>v....v.v..>>v...>...vvvv.>v..v>..vv.>...>>.v...>>..>..>v.>>>>>....>.v..vv>vv.v.>.>v>...>v.>>>v>v>>v.v.>v..>.vvv.vv>>.vv>...>>.v...>.>>>...>....v.......>.>.vv>v.v.>>..v>..v>vv>...>.v>vv...vv.v>...>.>>v.v>v.v.>.>..vv....>...vv.vv...>..>vvv...>v.vvv>.v.vvv...>.v>.v....>v>>>.v....vv....>..>vv>.>....>.>>vvv.>....>....>>...>v..>v>>v>>v.>v.>..>..v>>v....>......v.v>..>v..v..>.>..v..>.....v>...vv>.vvvv..>..>v..v>>.>..>.>.>..>>...v>>.v.v.>v.>...v..v.>v.vv.>vv.>..v.>v>.>.>.....v.....>.....>>>v.>.>>.v>.v>>.vv.>....vv...>v.v>.v>>..v.....vv>..v>>.>..>.v...v..v.....v>>>.vv>>..>..vv.>>....v..>....vv>>>..>vvv..vvv>v>.>v..>>.v.v>.v....v.>>..>....>v>.....>...>.>..vv>....v.v.>v..v.vv...>.vv.v>>>.>>..>v>...v..>.>v.>>.....vv.>v.>>.v>....v>>..........>.>v..v.>vvv.v.v>.v>.v>>.>.>>.vv.>>.v>v....v.v...v.v.v>v>.vv.>>.vvv>>.v>v.vv.>.>....v...v...>>>>>>>>v....vv>.>.>>>..vv.>....>>.....vv>......>.>>.......v.>>>>>.>>.>v.v......v..v>.v...>vv>..v.>v>vv>.>vv>...>...vv>>.>.v>..v....>vv.>.v.>>v.>>.>...v.vv..v..>.vvv.v>v.>.>.v>.>v.v.vvvvv>>.>>..v>....>.v.v......v....vv..v.vv..>vv>.v..vvv>>....>v>..v>...v.>.>vvv..v......>vv>..v.v.>>....>...v....>..vv.v.>>>v.v.>>..>.>vv>>..v>.vv..v>>v.vv>.v>.v.v.v>..>.>.vv.v>v>.>.>>.vv...v..>..v.....>v>>.>.>v>...>>..v>....>>..v>....v.>.v...>>vvv>...>>..v..v>vv.v>v.>....vv>v.>..v.v>v...>>.v.vv..v...v.v.>.v>.>..>.>vvv..>>v>v.>.>vv..v.>vv..v.....>v..>v...v.>v.>>.>>>.v.>vvvv..vvv..v>>.>...>>.>..>.>...>v...>...>v.vvv>......>v....>.>>.v.>.>>v....v.>.....vvv>v....>>v..v>v.>.>......v>.>>.>vvv..>>.vvv.>.v>..>v.v.>>.>.>..v.>..>v.>>.v.>>.>>>v.>..vv..v>v.......>v>..>..vv>v.>.>....>>....v...v...>vv..v.>.v>.>>....>>>v>>>..>..v..>...v>v>..>.v.>....v..v.v..>vv>>.v.vv.vv.>>.vv.v.v.>>>>....>.>...>>...v>.v>.vv....v>>>.v>v.>.vvv>..v...vvv>>.vv.v.v..v..>..v.>>....v.v>.>..v>..>>>>..v>..v.>.>>>v>vv>.v>.>>>..>>v>>.>.v..v....>..v>>v.....vvv.v>.vv..>...vv.>>.>.>.v..v>>v.v...>..>>...>v..v.>>.>v>v..>>...v>.>vv.v>.>.>>.v...v.>>v>>>.v>....v..>..>..vvvv>...vv.>...vv...>.v.>v>>>>v>..>>...>>v..v>>>v..>..>vv>.v..v.v.>.>>v.vvvv..v.>>.>v.vvv...vv.vv.>>.>....>..>vv>..>.v.....>.>v>>>..>>v..vv....>>.......>>>v.vvv>>.......>.>vvv>.v>>....vvv..>vvvv.>>v..>.....>..>.>.>.>v.>>.>.v....v>.>.>..>.>.>..>v.>...>....>>>v.....>>..v>>>.v>>..>.>v...v.>...>.>v>..>.vv>.>v>>.>.>>...vv>.>>.vvvv.v..v.....>>>vv...>>.v>v..v>v.....v.v.>..v.>..>.v.>v.v.v.>.vv>v..>>v>.vv>.vv......>v...v>..v>..>>.>v>.>.>v.>>.>v.v...>>.v..vv>>.>...>.>..v>.v....v..>...v..>>.v...v.vv>vvv.>..>.v>..v>>v>>v>v>>.>>.>.>.v>..v>.>vv.>v..>.v>>.....>...>>v.>v..v..v...>.>....v...>v..v.>>.v>....>.v....>.>.v.v..>.....v>..v...v>.v>v.v.>..v.>.vv...>vv.>v.>.>v.>>>.v>>v..>>>..v..>..v.>>..>....>v>v>vv..v>vv>.v....>..>>v.>>>..>>>>..>.v..v..>v..>.vv>.v>>>.v........vvv.>..v>>...v..v.>>>.>....>.>.v>v..>..v.>.>v..>v>.v>v.>v.>.vvv>v..>.>>>>.>>>....>...>..vv..vvv..>.v.v>.>vv>...v...vvv.>..v>v>.>.>...v.>.vv.vv.v.v>.....>.>v..>....v>.vv.>>...>vv..>..>>>.v.v.>>>>v..>v>v>v>vv.>...>>>v>.>v>.>..>vv...v.v>vv.>...>..>>..>.v>v...>..v>....vv>...>.>v.v.vv>v.>vv..>>.>.....v..>v....>>.>>.>vv.....v>.>.vv>.v.>.v>v.>..vv...v.v.>...v.vvv....v>vv...>...>.........>.>...v.v.>.v.vv.vv.>.>...>vvvv>v..>....>>>>.v.>>>v>>.>>vvv.....v.v>..v.>>..v..>vvv....vv>......v.>....v>v.>v.v...v...v>vv...v.>.>>..v.>v.>>v>.vv.>>v.v...v.....v>>v.v>>....>>.v>...vvvv.v.vv..v>vv>>>>>.v>>vv..vvvv..v>>v.>v.v>.v>>......>...>.vv..>>...>.v>v..>vv..>.v..v....>.v..>>v>v...>.v...>.v>>v..vvv.>v>..>...>v.>..v>.>v>>>>>.>.>vv..v...v>>>vv.>>v..>....v>>v.>.....v......vvv..v....>>v>....>..v....>>>>..>v..>..>.v>...>..v.v.>v>>v.v>>>...>...>v....v..>.>v>>>.vv..>..>.>..vv>.v>vv.>>..v.>>>>..v..>.v>>..>>.>....>....v..>..>>>v>.vvv.>v.>>>>.>>.v>v>>>..>......>>...v>vvv..>..>..>.v.vv>.>vvvv>vv.>v>vv.>.vv>vv>.>.>v..v>v.>....v..v.v>...v.>.vv...>..>..>..>.v.>...v.>....>.>..>..vv>.>>.>.v>..v...>>..>>..>.>..vv>.v>vv.>.....v.>.....v.>.>v..v...>..>>..v>>....v>....>v.v.v.>..v>.vv.v>.......v.>>..>...>>>.>...>..v.vv.>>>vvv.>....>.>.>>..vv....>>>..v..vvv..>>.....>>>v..v.v..>.vv.v.v.vv.v..v>.v.v...>.v..v>>...>.vvv>>..v...v..v.v..>>.vv>>v>v...>..v>.vv..vv.vvv.v.>v..v.>>>v.v>vv..v.>>v.>>v.>>v..>.v.>.....>>v..>v.>...>....>>vv>.v..vv>..>>>.>..>..>>>v>v>..v..v.>.>v..v.v.>..v...v>>...v>>.v>.>>.>v.>>v>>.>.>.>v.>.>vv...v.>>>>.vv...>>>..>.v..v.vv>>...>.....vv.>>vv.....v..>..>v.>..>>>vvvv...vv...>v....v..>.v...v>v...>>vv>v....vv.>..vv..>.>>vv.v.>>....v>v..v.v>v>..v>.v.>.>...>.>.>..vv.>>.>>>>.v..vv.....>>.v...vv..v.>.>>vv>v>..>..v.v....v..v>........>.>..>.........>..>v>.v.>>....>>>.>vv.v..>......v.>v>>...v.>.>.>.>v>..>..>...v>>.>>.v..>...>v.v.v.>v>..vv.>>>.vv.......>.v.>...>..>>..vv..>.v..>v..v>.v>.>.v>v.>>v..>..>>.......>v.....v.v....vv.v>......v.v>v...vvv...vvvv..>v.v..v.v...>v.>>>..>v>.........>v...>v..>..v.>vv>.v>v>>.vv.v>..v..v>.v.vv..>>vv..v.>>>v>..vv...v..v>vv......>>..v..>.>..v>..>v...>...v.v>...>...v>>>.v.>>.......>...v..v..>..v.....>..>>.....vv.....>..v>..vv>.>.vvv.vv>.....v.>.v.v.v.>>v....v.vv>v.v>..vv>.>.v>>>...>.>.>..>v....vv>.>..v.>.vv>>v>>v..v.........>.v...>..>.v.v.>v..vv...v....vv.v.>.v...vv.....>..>>>.>..v>..>.>>v.>...>..>....v>..v.>>>..>.v>vv>v>.>....vv.v....v>.vv>.v>>.>.>.v..v..v>...v.>...v..v......v.>>.>.>v..v>.vv.......v..v>v..>>>...>v...v...>v.vv.>>.>.>...>.v.v>>.>.>>v>>.>..vv.v...>>v...>>>.>....>>>.v>v>.v>.v..v.v>vvv.v..vvv.>...vvv.vvvvv>>.vv.>>>.v..v.>.....v>vvvv...v>...>...>v.v>.....vv>v>v.v>>.v..v.v...>v...>v>..vv>.>>..v...>>v>.>.vv..vv..vvv..v>....v.v>>.>...>v.vv...>>...vvvv.....vv>.....>..>.v.>.>.v.>>>v>v>.>>v...v>v>vvv>v>v>v.v>>.....>.v>vv.>>.>.v..>.>.....v.v>>......>.>..vv.>.>.v.v>.v>vv>>v.>>.>.vvv>v..v.vv>..v>v..v>>>>>.....>..>..v>v.v......v>.v...vv>v.>..v>.>.v>..vv..>>>....>>.>.>v...v.>>.>>..>v>.v..v.v>..v...>.vv>>>..v.>>.v..>>.>..v.>.>..v>>...>>...vvvvv>v..>>vvv..v.>v>......>>v>.v..v....>.>>....>>..>.>v...vv...>.v>>..>>.>....v....vv...>v..>...>>>..>v.......v..>>>v.>>....>>.v.>>v.v>.v...v...>..>v.vvv....v.>.v>..>vvv..>..>..>vv>..vv..>>..>.v.>>v.>.>>.v>....v.>...>v...>.>..>...>vv>...>....v..>.>..>>......>vv.v.v.>v.v.v>.>.v>.>vv.v..v>v>...>>..>....v...>v.>.v.>v.>v..>>.vvv.vvvvvv...v.vvv.vvvv.>>..vv>vv....vv.v.>>......>...v.>.>..v..>vv..vv>v>....vv.vv>.v....vv>.>>...v>>>..>..vv.v..v.vv.>vv>v.>v.v.>.>.v>v.v.........v>...>v.>>..v..vv>>>.v>.v.v.>.v>v>..>>..>..>>...>>..v>vv>..>>>v.....v..v...vv....v>.....>.v...vv...>...>..>....v.vv.>v..>v....>>..>v.>vvv>v..v>...>....v>v>>v.v..vv>>.v...v>....v.v..>...vvv.>...v..vvvvvvv.>v......vvv>v..v..v..>>v>v.v.vv....v>>..>>v.>.v.>...vv..>..>.v.v.>v>>>...>>>v..v.v.v..v>.v.>.>..>>...v..v>>>vv..>vv..v>vvv>.>.vv...v..>.vvv..>>>....vv>..v.>.........>v>...>.v..vvv..>v..>.......v..>v..v..v>.>.v>>>vv...>>..>...vv>>>..>>..>.vv..vv>...>...v>vv.v..v>>>>v..v.vv>..>>>..>..>.>....>..>..v.v>....>.>v..>v.>vvv..>..>..>v....>...>..>..>.>>.vvv.v.v...v.>...v>.>v.>>vvvv.v....>v.>.v..vvv>v.vvvv..v>vv.>v.>>.>.>>>>>v>.v>...vv>.vv.>vv>.v..>v.>>>>vv>.>>..>v.>.vvv.>>>.v>....vvv>.>..v.v..>.v>v.>..v.>.v>v..>..v>v>.>v..>v.>v...v.>v>v..vv.vvv...>v>v.>>.v..>.>...>v.v>>>v....>>.>>v.vvvvv.vvv.>...>..>v..>>.v.vv...v>..>>>v.....>.>..>>.........>..v.v>..v..>>..v>.>vv>.>v......>.>.>.vv.>v..v.v.>>...v.>>....>.>.v...>..v.v..v..>vv>.>v...v>v>..>>v..vvvvv>>v.v....>v.v.>....>.>.>...v...v...v>v....v>.v.v.>>>v>>...>.v...>>v>v.vvvv.>>>.>>>....>v>v..vvvv.v..>vvv.....>.>...v....v.vv>...v>v>>>>....v>>.>.....vv>>.v.>v.vv.>>>vv..v>>..v>...>..vv.v>v...>>.v....v.vvv>v....>v>.>vv>.vv>>..v...>....v.>>>>>..v.>v.>.v>>.v..vv>..v....>...v.>v.>>..>.vvv.....>>..v>.>...v>v>v.vv.v.>.........v>>v...>.>>v.v>.v>v.>vv.>.v.>.v..>>.>v....>v....vvvvv>.>vv>v.vvvv..>>>.>>v>.>.>v>v......v>>..>>...>>...>>vv.>.v.>...v>..v.>>>.....vv.>v.v>.>vv>...v>vv>.v>>.>..>...>vv..vv.v...vvvv..>v..>.v.>.v>..>v..>......vv...>v....>.vv>vv...>v.v..>..v>.........>>>>>........>......>.vv>....>>>.>>.>v.>..v.>>.v.>..v>v.v.vv.>..vv...>.>..>.v>.v..>>.v..>v.vv>>...>v>v.v..>v>.v.>..v.>...>.>>.v>.v.>....>v>..>>......vv.v..>vvvvv.>>v>vv>..v>.>v>.>v...>.vv"; + assert(strlen(input_str) == LEN); + ParseInput(input_str); + + for(u_int64_t i=0; i < 10000; i++) + { + memcpy(map_bak, map, sizeof(char) * LEN); + NextStep(); + + if(strcmp(map, map_bak) == 0) + { + printf("EQUAL after: %llu", i + 1); + exit(0); + } + } + + return 0; +} diff --git a/Advent-of-Code-2021/AOC-25/input.txt b/Advent-of-Code-2021/AOC-25/input.txt new file mode 100644 index 0000000..d12fc15 --- /dev/null +++ b/Advent-of-Code-2021/AOC-25/input.txt @@ -0,0 +1,137 @@ +>.>.>.>>>vvvv>>v...v>>.vv.v>>>>>>.v>....>>.v.v.>>....>.v>v>..vvv.v..vv..v>..v.>.v>v...>..v>>v.v......>vv...>>..v>.v>.....v.>.v.......>.>>.v +.>>....>>.v.>.vv..vv.v>..>...v..>...v.v...>v.>>.vv..>...>>..>...v>....>...>>.>..>...>.v.>..>v>.>>v>...>.>..>.v.>..v>>vv>v.v>>vv.v..>>v>.vv. +vv>.vv>>vv......v.....v..vv.v>....v>.>v>.>.vv>..>..vvvv>.v...>>v..vvvvv>>.v....v.>..v>>>....v...>.vv>...>v>.v.vvvv.>>..>>..>.>>.>v.v.>v>>>. +v>.v.>>>>.v...v.vv>.>v>.v>v.>>v.v>>...v.v.v...vv.>vv>v>>.vv.v..v>>.v>.>..>.v.v..>v.v>...v..vv>.>vv...>.v>..>.>>..v..v..v>..v.v...v>.>vv.v.. +.>>>...v...v.vv>.....v.>vv>>.>>..>..v....vvvvv...v>.v.v.vv.vv...>...vv.v.>v..v>.>.v..v.v>v>...v...>.>.>>>..vv...>v>>.>>v.>..>.>v.v.v.vv.v.v +>.>.>..v.v.>>..>..>..>v..>.>.v.>.v>>>v.v>v...>>vv.>>>>.vv...v>......v>v....vv..v>..>.v>..>.v>.>>..>.>v>v>v.v.>..>..>..v..>>...>.v>...v.v.vv +>.>..>>.v..>>.v>v.v...>>v>v.>...>.v.>v........v..>>...>..>v.>v..v.vv..>v.>>vvv.>>>>>v>v.vv.>..>v>>>.vv.v>vv.v>...>>>...>..>..>.>v..v..vv>.. +>>.>>v>.v.......v.vv..v.v......v.v...>..>..>>>..v>...>.....vv..>>.>.vvvv>....>vv..>.>>v.........v.>>>>....>.>.>..v>...v.>...>.>>>..v.v>>.v> +>v.vvvv.....>v.>.>>vv.v.v...>>.>.>v.v..>v..>v>>.>..>.>v.v..v>>.v>..>...v.v>vv>.vv>v.>v.v..>>.vvv>..>..>>v..v..>>.vv>..v.>.v.......>..vv..vv +.>.>vv..>.>.>vvv.....vv>>....>.>>....v>vvv..>>v.vv>.>.>.v.vv.>....v>..>........v>v>.v....>v>>...vv.>..vv.>>.v..>.v>>.>>.v>.>.>vvv.vv..>..>. +>>v..vv......>>v...vv.v.v.>>v......>>v.>..>.>vv>..>.v>>...v.>......v...>..>.>vvv..>v.....>v.>v..v......v..>...>>v>.v...>v>v.>>..>v.>.v.vv>. +.vv>.>.>.v>..>>....>v>.>.>>>>.......v>v.v>....>>.v..v........>>.>>vvv>..v.vv..>.>....>>vv>v..v>>..>..v>.>>.>.>v.>.vv.>...>.vvv>>......>.>>> +v.v...v.v...v>v.>>.v.>.>vv.v.....v.>>>>...>.>..v..v>....>.v>.vv>....vv.>>..v>vv>..>.v>.>v.....v.v>.>.......v..>vv....>.vvv.v..>>v>...v.v..v +.>v>v.vvvv>.>vv.vv.vv.>v....>v>..>.v.>>..>>.>>>>.......>>>..v..>>...>>>.>vv>v..>...v..v..vv.vv...v....>...v>..>.>.>.>vv..>.>.>..>..v.v..... +>.>...>>vvv.v..>...>....v...v...v..>v.....v.>v.v..>.v>>..>.vv...>...v..v>v...v...>.v.v>vv..>...........v.>>.v>>.>vvv.v.>>>>..>v>v>>>.>>..>. +..v>v..>>..v.>...v.....>...>..>>>v..vv>...v.v.v.v>>>.v.vvvv.v..>>.v.>v>..vv...>>>.>...>>v>.....v>.v.......v>.>v...>.vvv>>..>v...>..v..v>>vv +.v.>v>vv...v...v...>.>...>.v.>>v>..>>.>>>v.>.v.>>.>..v.>vv>v..>vv>...>..>v....v.>>v....>.v.>>.v.vv>vv>.v.>>v.v>..>..vv.v>.v>v>v>..>.>...>>. +.v>>>.v..>.v.>>.v.>>vvvv.>>v..vv..>v.>.>...vv>.v.v>v>v..>.>>.vv>...v>.....>>vv.>v.>.>..v...v..v.v.>>v.>....v..v>vv>v..>vvvv...>.>.....v.v.v +>....vv.>.v.v>>>v....>..........v..>.v..v....v..>.v.>.vvv>vv>v.......>..>v......v>vv...>...>v>>>.>v.vv.v.v>>.v.v>.v.>.>.v.>v...v......vv... +.v.v.>vv.>.v>.v..v.v.v.>>......>.v.>>.>>.v...v.>>>v.....>>>..>.v..>>..>.v>>.>v>..>...>.v...>>..vv.>>>>>>>>....>>...v.vvv>>..>>.>..>>v.v.vvv +.v...>.>>..v>>>v.v.....>.v>.>>>>...>>..v.>.v.........>v>..v..v>v>...v>v>...v....>..v>.>...v>vv>>>...v..>.vv.>v...>.>..........vvv.>vv.>.>vv +>>>>vvv>>v.>.vv>v>v....v>.v>...v>>vv..>v...>>.v.>....>.v.v>.vv...vv....vv....>..v>.v..vvv...>>.vvv.>.vvv.>.>>..v..>>.v..>>.>v>v>>...>.v.vv. +>.v>.>v.v.>.v...>...>>.>...>v.v.vv..>.>v.>vv>.v>...v>.>...v.>>..>v>>>>.>>.>>v..>.vv..>.>..>v.>.v>>>....>.>..vv.v>vv>.>...>>.v..>>...vv.v..v +v.>v>..>v..>>..>.>>.v.vv.vv.>.>>v>.v>vv.>vv.>vv..>.v...>>.vv...v..v.>.v.>.....>v...>..>.....>.>>v.......v...v.v.>.>...v.>......>.>...>>.>.v +>vv>..v>v>v>.>>v>...vv...>>>vv.>.vvvv..>.v.>>v>vv.>..>>..>v.>..v.v..>v..>>v..>...>.>.>..v...vv.>v.vv....>>v.v>....>...>.v..>v.v.v...>>>>.>> +.vv.v...v>vvv.v>...>v....>..vvv.vvv.v.>>v...>>>.>..v....v>>>v....vv.v>.>..v..>.....>..>>..vvv>>vv...v..>.v>>...v>v.v.v.>v.v.v>>..vv..>.v..> +.>..v....v....v>>.>..v>.>>..v>>>.>v..vv.v>vv..v.v>.v.v...v>>...>>vv>>vvv.>.v.>v..vv>>...vv.......v..>vvvv>>.>...>.v>>vv..>...v....v.....>.. +>>>v.>>>>>.v.vv>...>..>>>.>....>v>>....v..>..>v.>>.v>.vv....>...>.>..>..v...>>v...v....>v.....>>.>.>>>.>>.>..>>.>>>>>.>v.v>>vv>>.>>>.>vv... +v>...v.>v>v>>.vv.>v.>v....v>.>v..>...>>>v....>..>...>.vv>>.>...>vvv...vv.v.>v......>.v>vv.v.vvv>>..v>>.v>.v..vvv.v.v.>>.>>v.>.v.>.>>v..v.vv +>>.>..vv>>..v>vv>>>v..>..>...>..>v.>...>>>..v..v.>vv>.>.....v.v>.>>.v>v.>..>.v...v>..v>........>>.vv...>.v..>>v>v..v.>v>>>...>.>>..>.vv>v.. +>v>v....v..>...>....>....>..>...>..v>v...v..v....>.....>.v..v....v.v..vv......vv.>vvv>..vv>v..v>v.v>v>.>....v...>>>>>..>..>.v..v..v...>vv.> +.v.>v..>..vv.v.>.v.>>>v.vvv....v>....v.v.v..v....v...v>v..v...>v.>v..>.v>..>>..>v>.vv.v..>.>>v>.>..>>>v.v...>.>....>..>..>v.......>v>v.>.>. +vv.>..>v>>.>.............>.>v>..vv>.vv>..>>.>..>....v>>v....vv>....v>.>.v.v.v>....v.>.vvvv>vv.v>.>v>vv>>..v..>>...v>..>>..>>..v.v..v...>vv> +>.>.>..>>...v.vv.....v..v..>...v.v..>>.....v>>...v>..vv..>>.v.>>>v.>...v.v.......vv.vv...>>...>>v>..>.>vvvv..>v....vv>.v>>v..vv.v>>vv.>v>.v +..vv..>..v..v.>.>.vvv..vv..>..v>v.v.>.vvv>vv.>.......>>>vv>>...>v.v.>>vvv..>..v.>v..>vv>v.vv........v>.>....v.>.....>.>>v.vvvv..v.>..>..v.v +...v.vv>>.v>..>.>>vv..>.v>>..>vvvv.v..>.v.>>....>.>..>>.v>...>vv...v.>>vv..v..>vv>.>.v>.vvv>>.>.v.v...>...>v.>.......v.>.v>.>.v.>.>.>.>.v>. +vvvv.>v>.>>..>...vv...v>.v>>.>.v>.>vv...v..>..v.v>>v>.vv.......>...>v>v.v.v>>...>.>v>.v...>.>.>>..>vvv>>...v.v..>v..v>..v.>v.v.>.v.v.>v.v.v +>.>...v..>..vv.vv.>.v>..v>v.v.v.v.>...v>v..>v.v>v>v>.>.....v.v.>..v..v.v.vv.>>>.vvvvvv.>......v>>>v.v>v....vvv>.>.>.>v..>..>v.>..v.....v>v. +v.v.v...>.>..>.v>..v.v.vv..>.>.>..>>....v>>..>.>v....vv..v...>>v.>....>..v>.v.v.>.>......>v>v.v..>.>>.>v>...>...>vv........>vvvv.>v>>...v.. +.v....>vv.vv.>v.>.vv>..v.>...>v...>vv>..vvv>.v...v.>..>v>>v...vv.vv....>>.>..>v>..>>...vv..v>.>.v..vv.>.v..v..>.v.>>..>>v.v..vv.v.v.v.v.>v. +>>...>v......v..>.>.v.vv>>.>...>v.....>v.vv>.>.....>vv>.>...>vvv>..>>.>....>>.vv.v.>v>v.v....vv....>...>>...>...v>.>..v.>.vv.>vv>>vv.v..... +.>.>..v....>.>.>v.>v>..vv..vvv......>v..v..>>>.>v>>>...v.>.v>vvvv.v.>>...v.>v.v>..v.>vvv.v...v>...v.v>v.>.>.>v..>v.>.>vv.>vv>>>.>>>>v>v..v> +v..>..>.v>...v......vv>...>v..>.v>...v.v>...>.>>.v>...>...v..>>...>..>..>>..vv.v.>v.>>>..>>>>..>>.>..>.>>..v.v>.....v.v>v>>vv.vvvvvv....>v. +..v..v>v....>...vv>v....v>v...>>.v.vv.>>v.vv.>vvv.......>..v.v>>>..>..>>......>>......v......v..v....v...vv..>>.v.>......v.>>...v>..v>>v>vv +vv..v...>>.v>.>.v...vv>>..v...>.v...v..vv>>..>..v>.v>vvv>v.>.vv.v..>.v..>>........>.>.>.>vv...>..v..>v.v>.vvv....>....v>..>>v>>vv>.>..>v... +.>>>.>.>>.vv.v....vv.v.>>.....v.v>...v>>>.vvvv.vv.>.v>v.vv.vv>>.vv..v.>>.vv>>vv>.v..v.>v.>....vv>....>v.....v.>..>..>v.>.>..v>>.v>.>>vvvvv. +v>>..vv>.>.....>vv.v..vv.>>.>>...v..>....>.vv.>>...v.>v>....vv>>....v>...v.>..v>.....v..>.v.vvvv.v..v>>.v....>.v>.>>..vv.>v>..v>.......vvv. +.vvv>...>v>..>>...>.....>...v..v.>>>.v>.v..v>>>>..>..vvv>.v..>v...v>v.>.>.>.>.>.>>..v.>.v..vvv>v>.............v.>.v.v.v...v.v.>v...v.>.v>.. +>..vv>...v.>>....v..v..vv..>>.....>v..>.....v>.v..v.>.v>.v>vv.v.v>.>.>.>>.vv>v>.v>.>......v>v..v>v.v.>>v>.>v.v>v.v>>>v>..vvv>>.v.v>>>v....> +.v.....>v>>....v..v>v...>v.....v.v.>..v>v>v>>>..>.>v...v..>v.v...vv..>....>v.>>>v..v.v>vvvvv>v>...v...>>..v.v.v>vvv>v.>v>.>v.v...>.....v..> +>.v.>.vv.>v.v>>>v...v>>>.>...>vv..>.v>.v.v...v.>....>.vv.v..>>.>....v...>....>.>>>v..vvvv.>vv.vv.>>>>..v>v>..>v>.v.>...>..>.>.vv.>>.vv>.vvv +.v.>v>v>....v.vv.>v.>...v>.>>.......>>.v.>v>.>vvvv>>vvv.v>>v.v.>.>.vvv>.>v....v...v.>v.vv...>>>vv..vv..vv...>..>>.v....vv>>>v..v.v......vv. +vv..>..v.>.v.>v..>..vv.>...v.>vvvv>v.>vvv.>.>..vv.>.>.>...v..>..>v..>...v>.>v>.v.v>>..>..vv>.v....vvv>.>.>>.>>..>v>>.v>.v.>>..>>v.>>.v...v. +v>>>v>..vv.>>..v>.....>vvv.>>..>.>>.>v.>vv.>.v.v...v....>>.>..v.>v..v>...>.v...v.>>.>v.v.v.>vv>...>............vv>>>v>v>...>v>>.vv.>v...>>. +v.v....v>vv..>..v...>....>>>..vv>...v..v>>v...v.>v..>..v..>.>....v.>vv>..v>.>.vvv>..v>>.v.v>.>..v.>v..>....>.>>v>vv.....>...v...v....>>.vv. +...>.>>>>v.v.v..>>....v>.v..v>v...>>vvv.v>v..v>vv...>.v>.v>.>.v>...v.>.vv>..>....>..>>vvv.v....v.v>>>v.>>>>.>v.v.>>.>>...v..v.>...v.v>.>>.. +>....v..>....v.vv.>.v>v.>.vv..vv..>.v.>v>.>>>..>..v...>vv>vv>>v.>..v>>.vv.v.v..v>>.v.>.>...>.>..v.>.>......>.v.v>>.>.>>..v...v>.v.>>v..>>v. +vvv.>......v.>v....v>v...>.....v..vv..>>v>.v..v...v.>.>>..v.v..v>..>.>vv.v>>>vv>..v.vv......v.v.>v.v..v..>..vv.v.v>>>....>..v.>v>...>.>.... +.v.>.v>>..>....vv>v>vvvv.v.>.>>...>.>.v.>v..>>v..v>.>..>.vv..vvv>v.>..>..v....>v..v.....v>>>..>.v..>vv...v.v....>vv>..v.>v>.>vv>v>v>>v>>>.v +>vv.>..v>>v>v.v>.v..v.v>v>.v>.>.....vv>>>>...v..>vv>.v>>v.>.>....>...>...v>>.v.v.>...v.v>v..v>>...v>>>...>...v.>v.>>..>v.v>..>>>vvv..v>.>.. +v>>>>.>.v.>v.v....>....>...>.>.....>.v..v>.>v>.>>v.v>...v..>>>.vv...>..v..>>..v....>v....>v.>vv>v...v>.vv>.v>v>..v.v.vv..v...v..>>..>v>.vv. +v.vv.>.v.....v...v.v...vv.v...v>..v.>....>.v>.>>vvv>.>.v>...>.vv>v...vv.v..>vvv...v.>..v.>.>>>.vv>v.vv.vv>v>v>>vv>v.>>vv..>..vv...>v.v>>..v +...>>vv>>>>vv.>>v>v>.v>.v..v...>>..v>...v>>vv>.>.>.>>..>....>vv.v.vv.vv>.>v..v.>..v.>.vvv..>..v...v>>v>..v>>v...v..>>...>>vv>.v...v>.vvv... +...vv.>>.v...>>..>v>..v.v>..vvv>v.>>>v.v>.>...vv....>>>.v.>>>>v.v>vv>>....>>.>..v>vv>....v.>.>v...>.>v.>v>.v..>>..>v>v>..>..>v.>...>....vv> +...v>.v..>v.v......v>>>........v.v>v..vvvvv>..>.vvvvv>>>.vv.vv>v...vv..>v>v.>.v>.>....v.>..v>..v..>>vv>>......>............>>>vv....v>v.>.> +..>...>....vvv.v......v.>>>.....v.v.>...v.>v....v...v>..>>>..>..vv>>v.v>.>.vv.vv.>.v.>v>v>>.>>v..>......v..vvv.>>....v>v.>>vv>>..>..v>>>.>v +.v>.....>v...v.v>..v>..>....v...>..vvv>...vv.>v.>...v>.v.v>....v...>>.v>>v...>>.>.v.v.v>v.vv>v.v.v..>>.v.>>.....>>>...vv.v>....>.>.>v.>v>.> +>..>v.v.v>..>vvv....v....v>v.>...vv.>v>....vvv.....v>.vv..>..>>>v>v>v.>v.v>...v.>...vv.>....>>...>.v..vv>v>.vv.v....v>v>v>.>>.>>.>>vv...vv. +vv>........v>v>.v.v>....v.vv.vv......>.>>v..>>>.>.>v...vv.....>>>.>.v.v...>.v.v..>.>.v.v.....>.vvv>>.v.>>.........vv.v..v>v>v>.v>>..vv.v... +.>>.vv.v>>.>>.>>..vv...v.v>v.>.v>>.vv..v...>...v...vvv>>.v...v.v>>>v...v..v...>>..v.>>v.vvv>...v.........v.vv>..v.v..>..>.>v>.>.>>..>v..>.. +.v.v..v.vv>v.v...v..v>v>.>v.v>v....>....>v.v.>>..>>v>>.v..v>v.>>.>v.>..v....v>..>..>.v>..>v..v.....>.vv..>.......v>....vv..>v..>>v..>v....v +v.vv.v.>v.>v.>...v.v...v..>..v..>>.vv.v.>.>...>>.>v>........>>v...>.>v...>..v.>>v.>...>..>..v>>vvv>.....>vv>....>......>>>vv>.>>..>>>..vv.v +>vvv>v>vvv..v..v..>>.v>vv>......>>v.v>.>.>vv.>.vv..v..>.v>.....>v.>....>>v.vv.>>.v...vvv....v>>>..>..>.v.vv.v>v.....vv>..>.>.>>..v..>.>..v> +.>....v>...>>>>........v..vv>v..v..v....v>>..v.vv...>.>.>..>.....>v>.v.v>v...>vv.>..vv..v>v>>v.>>.v..v>.vv>.v....v>v>..>...>..v..>..v..>>.. +.>.>v>.>v>..>vvvv.v.v.>.v.v.>>...>vvv.vv..>>>.v>.>.v..>v..vvv>...>v>.>v.>>v>v>..>v........>v.vv.>>...v.v..vv.>...>..>..v..v...v.v.v.>.>vv.. +............>v....v.vv>>v..>...>.>>>..v>.v.vv....>.>>>>v>...>v.v.>v.v.v>.>...>>.....v....>.>...v..v..>..>>.>..v>>v.v..>.>vv>v.>..vv.vv..>v> +.>..vvvv>vv.>.>>v.>.>>vv>vv>..>>v>.>...>>v>v..>>.>v..v.v>>.v>....>v>.v.>>>.v.v..>>.v>>.v...v.vv.v.>..v>..>...v..v..vv>.v....>.>>....v...v>> +v.v>vv>....v..v>>.>v.v.vv>>vv>>.>>..>>vv>..v..v>.>......v..v.....>v...vvv.v...>.vv>...>.v..vv...v>....v>v..v.v>.v...vv...>.v..vv.v>.>v>>.v. +>...v.>>v>..>.>..v.>vv.v...v>..>>...v>>vv..v.>.>v..>...v.....v>.>..v>>...v>>>.>..vvv.v>.>>.v>.v.v.>v>vv.vv>.v.v..........v>>..v...>..>>>>>. +v.>>.vv....>.....vv>.>.>>>.v.>.>>..vv..v.v.>...>.>>...vvvv..v.>....v.vvv.v.>v....v>..>>vv.v.>>..>>.v>.>v.v...v..>.>.vv>.....v.>.vvvv>>vv.>. +>.>v>..vv..>..>>v...v>...v.v..vv>.....>.>...>v.>..>...v>v....v.v..>>v...>...vvvv.>v..v>..vv.>...>>.v...>>..>..>v.>>>>>....>.v..vv>vv.v.>.>v +>...>v.>>>v>v>>v.v.>v..>.vvv.vv>>.vv>...>>.v...>.>>>...>....v.......>.>.vv>v.v.>>..v>..v>vv>...>.v>vv...vv.v>...>.>>v.v>v.v.>.>..vv....>... +vv.vv...>..>vvv...>v.vvv>.v.vvv...>.v>.v....>v>>>.v....vv....>..>vv>.>....>.>>vvv.>....>....>>...>v..>v>>v>>v.>v.>..>..v>>v....>......v.v>. +.>v..v..>.>..v..>.....v>...vv>.vvvv..>..>v..v>>.>..>.>.>..>>...v>>.v.v.>v.>...v..v.>v.vv.>vv.>..v.>v>.>.>.....v.....>.....>>>v.>.>>.v>.v>>. +vv.>....vv...>v.v>.v>>..v.....vv>..v>>.>..>.v...v..v.....v>>>.vv>>..>..vv.>>....v..>....vv>>>..>vvv..vvv>v>.>v..>>.v.v>.v....v.>>..>....>v> +.....>...>.>..vv>....v.v.>v..v.vv...>.vv.v>>>.>>..>v>...v..>.>v.>>.....vv.>v.>>.v>....v>>..........>.>v..v.>vvv.v.v>.v>.v>>.>.>>.vv.>>.v>v. +...v.v...v.v.v>v>.vv.>>.vvv>>.v>v.vv.>.>....v...v...>>>>>>>>v....vv>.>.>>>..vv.>....>>.....vv>......>.>>.......v.>>>>>.>>.>v.v......v..v>.v +...>vv>..v.>v>vv>.>vv>...>...vv>>.>.v>..v....>vv.>.v.>>v.>>.>...v.vv..v..>.vvv.v>v.>.>.v>.>v.v.vvvvv>>.>>..v>....>.v.v......v....vv..v.vv.. +>vv>.v..vvv>>....>v>..v>...v.>.>vvv..v......>vv>..v.v.>>....>...v....>..vv.v.>>>v.v.>>..>.>vv>>..v>.vv..v>>v.vv>.v>.v.v.v>..>.>.vv.v>v>.>.> +>.vv...v..>..v.....>v>>.>.>v>...>>..v>....>>..v>....v.>.v...>>vvv>...>>..v..v>vv.v>v.>....vv>v.>..v.v>v...>>.v.vv..v...v.v.>.v>.>..>.>vvv.. +>>v>v.>.>vv..v.>vv..v.....>v..>v...v.>v.>>.>>>.v.>vvvv..vvv..v>>.>...>>.>..>.>...>v...>...>v.vvv>......>v....>.>>.v.>.>>v....v.>.....vvv>v. +...>>v..v>v.>.>......v>.>>.>vvv..>>.vvv.>.v>..>v.v.>>.>.>..v.>..>v.>>.v.>>.>>>v.>..vv..v>v.......>v>..>..vv>v.>.>....>>....v...v...>vv..v.> +.v>.>>....>>>v>>>..>..v..>...v>v>..>.v.>....v..v.v..>vv>>.v.vv.vv.>>.vv.v.v.>>>>....>.>...>>...v>.v>.vv....v>>>.v>v.>.vvv>..v...vvv>>.vv.v. +v..v..>..v.>>....v.v>.>..v>..>>>>..v>..v.>.>>>v>vv>.v>.>>>..>>v>>.>.v..v....>..v>>v.....vvv.v>.vv..>...vv.>>.>.>.v..v>>v.v...>..>>...>v..v. +>>.>v>v..>>...v>.>vv.v>.>.>>.v...v.>>v>>>.v>....v..>..>..vvvv>...vv.>...vv...>.v.>v>>>>v>..>>...>>v..v>>>v..>..>vv>.v..v.v.>.>>v.vvvv..v.>> +.>v.vvv...vv.vv.>>.>....>..>vv>..>.v.....>.>v>>>..>>v..vv....>>.......>>>v.vvv>>.......>.>vvv>.v>>....vvv..>vvvv.>>v..>.....>..>.>.>.>v.>>. +>.v....v>.>.>..>.>.>..>v.>...>....>>>v.....>>..v>>>.v>>..>.>v...v.>...>.>v>..>.vv>.>v>>.>.>>...vv>.>>.vvvv.v..v.....>>>vv...>>.v>v..v>v.... +.v.v.>..v.>..>.v.>v.v.v.>.vv>v..>>v>.vv>.vv......>v...v>..v>..>>.>v>.>.>v.>>.>v.v...>>.v..vv>>.>...>.>..v>.v....v..>...v..>>.v...v.vv>vvv.> +..>.v>..v>>v>>v>v>>.>>.>.>.v>..v>.>vv.>v..>.v>>.....>...>>v.>v..v..v...>.>....v...>v..v.>>.v>....>.v....>.>.v.v..>.....v>..v...v>.v>v.v.>.. +v.>.vv...>vv.>v.>.>v.>>>.v>>v..>>>..v..>..v.>>..>....>v>v>vv..v>vv>.v....>..>>v.>>>..>>>>..>.v..v..>v..>.vv>.v>>>.v........vvv.>..v>>...v.. +v.>>>.>....>.>.v>v..>..v.>.>v..>v>.v>v.>v.>.vvv>v..>.>>>>.>>>....>...>..vv..vvv..>.v.v>.>vv>...v...vvv.>..v>v>.>.>...v.>.vv.vv.v.v>.....>.> +v..>....v>.vv.>>...>vv..>..>>>.v.v.>>>>v..>v>v>v>vv.>...>>>v>.>v>.>..>vv...v.v>vv.>...>..>>..>.v>v...>..v>....vv>...>.>v.v.vv>v.>vv..>>.>.. +...v..>v....>>.>>.>vv.....v>.>.vv>.v.>.v>v.>..vv...v.v.>...v.vvv....v>vv...>...>.........>.>...v.v.>.v.vv.vv.>.>...>vvvv>v..>....>>>>.v.>>> +v>>.>>vvv.....v.v>..v.>>..v..>vvv....vv>......v.>....v>v.>v.v...v...v>vv...v.>.>>..v.>v.>>v>.vv.>>v.v...v.....v>>v.v>>....>>.v>...vvvv.v.vv +..v>vv>>>>>.v>>vv..vvvv..v>>v.>v.v>.v>>......>...>.vv..>>...>.v>v..>vv..>.v..v....>.v..>>v>v...>.v...>.v>>v..vvv.>v>..>...>v.>..v>.>v>>>>>. +>.>vv..v...v>>>vv.>>v..>....v>>v.>.....v......vvv..v....>>v>....>..v....>>>>..>v..>..>.v>...>..v.v.>v>>v.v>>>...>...>v....v..>.>v>>>.vv..>. +.>.>..vv>.v>vv.>>..v.>>>>..v..>.v>>..>>.>....>....v..>..>>>v>.vvv.>v.>>>>.>>.v>v>>>..>......>>...v>vvv..>..>..>.v.vv>.>vvvv>vv.>v>vv.>.vv>v +v>.>.>v..v>v.>....v..v.v>...v.>.vv...>..>..>..>.v.>...v.>....>.>..>..vv>.>>.>.v>..v...>>..>>..>.>..vv>.v>vv.>.....v.>.....v.>.>v..v...>..>> +..v>>....v>....>v.v.v.>..v>.vv.v>.......v.>>..>...>>>.>...>..v.vv.>>>vvv.>....>.>.>>..vv....>>>..v..vvv..>>.....>>>v..v.v..>.vv.v.v.vv.v..v +>.v.v...>.v..v>>...>.vvv>>..v...v..v.v..>>.vv>>v>v...>..v>.vv..vv.vvv.v.>v..v.>>>v.v>vv..v.>>v.>>v.>>v..>.v.>.....>>v..>v.>...>....>>vv>.v. +.vv>..>>>.>..>..>>>v>v>..v..v.>.>v..v.v.>..v...v>>...v>>.v>.>>.>v.>>v>>.>.>.>v.>.>vv...v.>>>>.vv...>>>..>.v..v.vv>>...>.....vv.>>vv.....v.. +>..>v.>..>>>vvvv...vv...>v....v..>.v...v>v...>>vv>v....vv.>..vv..>.>>vv.v.>>....v>v..v.v>v>..v>.v.>.>...>.>.>..vv.>>.>>>>.v..vv.....>>.v... +vv..v.>.>>vv>v>..>..v.v....v..v>........>.>..>.........>..>v>.v.>>....>>>.>vv.v..>......v.>v>>...v.>.>.>.>v>..>..>...v>>.>>.v..>...>v.v.v.> +v>..vv.>>>.vv.......>.v.>...>..>>..vv..>.v..>v..v>.v>.>.v>v.>>v..>..>>.......>v.....v.v....vv.v>......v.v>v...vvv...vvvv..>v.v..v.v...>v.>> +>..>v>.........>v...>v..>..v.>vv>.v>v>>.vv.v>..v..v>.v.vv..>>vv..v.>>>v>..vv...v..v>vv......>>..v..>.>..v>..>v...>...v.v>...>...v>>>.v.>>.. +.....>...v..v..>..v.....>..>>.....vv.....>..v>..vv>.>.vvv.vv>.....v.>.v.v.v.>>v....v.vv>v.v>..vv>.>.v>>>...>.>.>..>v....vv>.>..v.>.vv>>v>>v +..v.........>.v...>..>.v.v.>v..vv...v....vv.v.>.v...vv.....>..>>>.>..v>..>.>>v.>...>..>....v>..v.>>>..>.v>vv>v>.>....vv.v....v>.vv>.v>>.>.> +.v..v..v>...v.>...v..v......v.>>.>.>v..v>.vv.......v..v>v..>>>...>v...v...>v.vv.>>.>.>...>.v.v>>.>.>>v>>.>..vv.v...>>v...>>>.>....>>>.v>v>. +v>.v..v.v>vvv.v..vvv.>...vvv.vvvvv>>.vv.>>>.v..v.>.....v>vvvv...v>...>...>v.v>.....vv>v>v.v>>.v..v.v...>v...>v>..vv>.>>..v...>>v>.>.vv..vv. +.vvv..v>....v.v>>.>...>v.vv...>>...vvvv.....vv>.....>..>.v.>.>.v.>>>v>v>.>>v...v>v>vvv>v>v>v.v>>.....>.v>vv.>>.>.v..>.>.....v.v>>......>.>. +.vv.>.>.v.v>.v>vv>>v.>>.>.vvv>v..v.vv>..v>v..v>>>>>.....>..>..v>v.v......v>.v...vv>v.>..v>.>.v>..vv..>>>....>>.>.>v...v.>>.>>..>v>.v..v.v>. +.v...>.vv>>>..v.>>.v..>>.>..v.>.>..v>>...>>...vvvvv>v..>>vvv..v.>v>......>>v>.v..v....>.>>....>>..>.>v...vv...>.v>>..>>.>....v....vv...>v.. +>...>>>..>v.......v..>>>v.>>....>>.v.>>v.v>.v...v...>..>v.vvv....v.>.v>..>vvv..>..>..>vv>..vv..>>..>.v.>>v.>.>>.v>....v.>...>v...>.>..>...> +vv>...>....v..>.>..>>......>vv.v.v.>v.v.v>.>.v>.>vv.v..v>v>...>>..>....v...>v.>.v.>v.>v..>>.vvv.vvvvvv...v.vvv.vvvv.>>..vv>vv....vv.v.>>... +...>...v.>.>..v..>vv..vv>v>....vv.vv>.v....vv>.>>...v>>>..>..vv.v..v.vv.>vv>v.>v.v.>.>.v>v.v.........v>...>v.>>..v..vv>>>.v>.v.v.>.v>v>..>> +..>..>>...>>..v>vv>..>>>v.....v..v...vv....v>.....>.v...vv...>...>..>....v.vv.>v..>v....>>..>v.>vvv>v..v>...>....v>v>>v.v..vv>>.v...v>....v +.v..>...vvv.>...v..vvvvvvv.>v......vvv>v..v..v..>>v>v.v.vv....v>>..>>v.>.v.>...vv..>..>.v.v.>v>>>...>>>v..v.v.v..v>.v.>.>..>>...v..v>>>vv.. +>vv..v>vvv>.>.vv...v..>.vvv..>>>....vv>..v.>.........>v>...>.v..vvv..>v..>.......v..>v..v..v>.>.v>>>vv...>>..>...vv>>>..>>..>.vv..vv>...>.. +.v>vv.v..v>>>>v..v.vv>..>>>..>..>.>....>..>..v.v>....>.>v..>v.>vvv..>..>..>v....>...>..>..>.>>.vvv.v.v...v.>...v>.>v.>>vvvv.v....>v.>.v..vv +v>v.vvvv..v>vv.>v.>>.>.>>>>>v>.v>...vv>.vv.>vv>.v..>v.>>>>vv>.>>..>v.>.vvv.>>>.v>....vvv>.>..v.v..>.v>v.>..v.>.v>v..>..v>v>.>v..>v.>v...v.> +v>v..vv.vvv...>v>v.>>.v..>.>...>v.v>>>v....>>.>>v.vvvvv.vvv.>...>..>v..>>.v.vv...v>..>>>v.....>.>..>>.........>..v.v>..v..>>..v>.>vv>.>v... +...>.>.>.vv.>v..v.v.>>...v.>>....>.>.v...>..v.v..v..>vv>.>v...v>v>..>>v..vvvvv>>v.v....>v.v.>....>.>.>...v...v...v>v....v>.v.v.>>>v>>...>.v +...>>v>v.vvvv.>>>.>>>....>v>v..vvvv.v..>vvv.....>.>...v....v.vv>...v>v>>>>....v>>.>.....vv>>.v.>v.vv.>>>vv..v>>..v>...>..vv.v>v...>>.v....v +.vvv>v....>v>.>vv>.vv>>..v...>....v.>>>>>..v.>v.>.v>>.v..vv>..v....>...v.>v.>>..>.vvv.....>>..v>.>...v>v>v.vv.v.>.........v>>v...>.>>v.v>.v +>v.>vv.>.v.>.v..>>.>v....>v....vvvvv>.>vv>v.vvvv..>>>.>>v>.>.>v>v......v>>..>>...>>...>>vv.>.v.>...v>..v.>>>.....vv.>v.v>.>vv>...v>vv>.v>>. +>..>...>vv..vv.v...vvvv..>v..>.v.>.v>..>v..>......vv...>v....>.vv>vv...>v.v..>..v>.........>>>>>........>......>.vv>....>>>.>>.>v.>..v.>>.v +.>..v>v.v.vv.>..vv...>.>..>.v>.v..>>.v..>v.vv>>...>v>v.v..>v>.v.>..v.>...>.>>.v>.v.>....>v>..>>......vv.v..>vvvvv.>>v>vv>..v>.>v>.>v...>.vv diff --git a/Advent-of-Code-2021/AOC-25/input.txt~ b/Advent-of-Code-2021/AOC-25/input.txt~ new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Advent-of-Code-2021/AOC-25/input.txt~ diff --git a/Advent-of-Code-2021/AOC-25/sample.txt b/Advent-of-Code-2021/AOC-25/sample.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Advent-of-Code-2021/AOC-25/sample.txt diff --git a/Advent-of-Code-2021/AOC-3/aoc-3 b/Advent-of-Code-2021/AOC-3/aoc-3 Binary files differnew file mode 100755 index 0000000..d163e8c --- /dev/null +++ b/Advent-of-Code-2021/AOC-3/aoc-3 diff --git a/Advent-of-Code-2021/AOC-3/aoc-3.c b/Advent-of-Code-2021/AOC-3/aoc-3.c new file mode 100644 index 0000000..51cab24 --- /dev/null +++ b/Advent-of-Code-2021/AOC-3/aoc-3.c @@ -0,0 +1,86 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <stdint.h> + +#define N 5 +#define INP_COUNT 12 + +int table[N]; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if(fp == NULL) + { + fprintf(stderr, "ERROR: something with file idk what fuck you"); + exit(EXIT_FAILURE); + } + + int i = 0; + while((ch = fgetc(fp)) != EOF) + { + if(ch == '\n') { i = 0; continue; } + + if(ch == '1') + table[i] += 1; + + i += 1; + } + + fclose(fp); +} + +void PrintTable() +{ + for(int i=0; i<N; i++) + { + printf("bitplace %d: %d\n", i+1, table[i]); + } +} + +int PartOne() +{ + int gamma_val = 0; + for(int i=0; i<N; i++) + { + assert(table[i] != (INP_COUNT/2)); + + if(table[i] > (INP_COUNT/2)) + { + gamma_val = gamma_val | (1 << (N-1-i)); + } + } + + int epsilon_val = gamma_val; + for(int i=0; i<N; i++) + { + epsilon_val = epsilon_val ^ (1 << i); + } + + int result = gamma_val * epsilon_val; + return result; +} + +int PartTwo() +{ + + + int result = 0; + return result; +} + +int main(void) +{ + memset(table, 0, sizeof(int)*N); + ParseInput("sample.txt"); + + PrintTable(); + printf("Part 1-RESULT: %d\n", PartOne()); + + return 0; +} diff --git a/Advent-of-Code-2021/AOC-3/aoc-3.c~ b/Advent-of-Code-2021/AOC-3/aoc-3.c~ new file mode 100644 index 0000000..936402f --- /dev/null +++ b/Advent-of-Code-2021/AOC-3/aoc-3.c~ @@ -0,0 +1,84 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <stdint.h> + +#define N 5 +#define INP_COUNT 12 + +int table[N]; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if(fp == NULL) + { + fprintf(stderr, "ERROR: something with file idk what fuck you"); + exit(EXIT_FAILURE); + } + + int i = 0; + while((ch = fgetc(fp)) != EOF) + { + if(ch == '\n') { i = 0; continue; } + + if(ch == '1') + table[i] += 1; + + i += 1; + } +} + +void PrintTable() +{ + for(int i=0; i<N; i++) + { + printf("bitplace %d: %d\n", i+1, table[i]); + } +} + +int PartOne() +{ + int gamma_val = 0; + for(int i=0; i<N; i++) + { + assert(table[i] != (INP_COUNT/2)); + + if(table[i] > (INP_COUNT/2)) + { + gamma_val = gamma_val | (1 << (N-1-i)); + } + } + + int epsilon_val = gamma_val; + for(int i=0; i<N; i++) + { + epsilon_val = epsilon_val ^ (1 << i); + } + + int result = gamma_val * epsilon_val; + return result; +} + +int PartTwo() +{ + + + int result = 0; + return result; +} + +int main(void) +{ + memset(table, 0, sizeof(int)*N); + ParseInput("sample.txt"); + + PrintTable(); + printf("Part 1-RESULT: %d\n", PartOne()); + + return 0; +} diff --git a/Advent-of-Code-2021/AOC-3/input.txt b/Advent-of-Code-2021/AOC-3/input.txt new file mode 100644 index 0000000..e324b50 --- /dev/null +++ b/Advent-of-Code-2021/AOC-3/input.txt @@ -0,0 +1,1000 @@ +011110111110 +110111000111 +001000001010 +000101111101 +101011011110 +010010010111 +111101001100 +111101011100 +110011101101 +001111010011 +110000000110 +111000010001 +011011011000 +000111110100 +111100101010 +001011001100 +011100000101 +100011110110 +111001011101 +110101011010 +110101101111 +011011101001 +111001010110 +011000101000 +100101111100 +011101110010 +010000110000 +111010110100 +000001000011 +110111000000 +101010010110 +100000001011 +001111110001 +001111000011 +001101001010 +100011001111 +001011001101 +010001010000 +000000000000 +011001011011 +000101100101 +010101101101 +000110011001 +100100110001 +010110011011 +110101100101 +010101101011 +011100000000 +011001101000 +001000100110 +101001010011 +111111101101 +100010111001 +000011011100 +010001111100 +011011111100 +000100010001 +101111100110 +000000111101 +111010110001 +000100110101 +111010100100 +111111001011 +001000010010 +100100000110 +010111010110 +111111010110 +000011011011 +001111001000 +000000010101 +011011100111 +110010111110 +110001011111 +011101100110 +010011111100 +010101100011 +000110010110 +100110001111 +010111100000 +001110110000 +101010010010 +010011011001 +100000100110 +010100011010 +100110001010 +111110001001 +101001000000 +100010110000 +101100001000 +000000110101 +100001010011 +011101100001 +000100111001 +011110100001 +001111000111 +001011001111 +110111000101 +011001010101 +101100111000 +011111110010 +000000100001 +100101011111 +110110011100 +011001011101 +000101010001 +100100001000 +110100001111 +101100010010 +010000011001 +010111011111 +001001101101 +101110101001 +101111011101 +100011010010 +101001100010 +110010111101 +100100010001 +100010011000 +100010110110 +100110101101 +101110010011 +111111011001 +100110100111 +011111011100 +011011001010 +101000011110 +010110011110 +101000111010 +110100001101 +111011010001 +011111100010 +101111000010 +111011111011 +001000011010 +010000001101 +001101110101 +000110010011 +011001110110 +110010010001 +010001010011 +110111100100 +011100110011 +011000010111 +100011101110 +101100110110 +101000100111 +100000000111 +011011011010 +011111011000 +010001111101 +000010111100 +101100100001 +011011111111 +010111001110 +110100111101 +011101111010 +100010001001 +101110011111 +000000000101 +110100100000 +010100011100 +101100111011 +110011110101 +000101110111 +001111100011 +001110001001 +101001001111 +010000011101 +100101111101 +001101000111 +000100100110 +010110111110 +111110110011 +101010101011 +101010011011 +100011010101 +101110010100 +110110001100 +111001010010 +011000111000 +110011001101 +111100100000 +100111110011 +110011010000 +100000101111 +110110101001 +001010000010 +000010100100 +101111101001 +011111001001 +111001111011 +001100001110 +111011011101 +110101001111 +010100001101 +000000001111 +001111001111 +100101101001 +011101101101 +101100101100 +110100101001 +100111001001 +111111001001 +101011000011 +010101110000 +010110100100 +101011000100 +100010001111 +111001101010 +111010010010 +000011000100 +110000111101 +110011110111 +101111011000 +100110110110 +000011111010 +011011110111 +011010010001 +110010111000 +100101000101 +110111011101 +110010011110 +010101010100 +110010011000 +101001101100 +100111011101 +001001100101 +011001010001 +001101000000 +011110111010 +001010011001 +011010101101 +101001001010 +001101101010 +100110111011 +000000101111 +111100000110 +100000100000 +011100010101 +111000110010 +111010001010 +111000011010 +000111001101 +001111000000 +011110000111 +101001010110 +011001001010 +001010001001 +111001001101 +111111000001 +001001111110 +101000111110 +001111010110 +010000011111 +010101010001 +011001010010 +111010000011 +110000111100 +110101000000 +000111011110 +101100101011 +001110101011 +000110100111 +010100000001 +101111000001 +000110101100 +111110010000 +010000110101 +000010000010 +111111111101 +011101001010 +001111100101 +100101010111 +100011010100 +110111110010 +100110110011 +011100101011 +000001010011 +010110101001 +000111110101 +101111001001 +100010101110 +111010010011 +100101000111 +111101110110 +100101110011 +001000110000 +010111100001 +100100011100 +000100111011 +101110111111 +100110010001 +100100111000 +011010111010 +111011101101 +110010110100 +101110101110 +110001101101 +110000011011 +101000000010 +010100000111 +000110100101 +011000101100 +111001111110 +101010100001 +101111111001 +100010010100 +111001111000 +100000011010 +111000101110 +010000000101 +111111000111 +100001011110 +100110111001 +101100101001 +000011111101 +111101110001 +101010010011 +101000110111 +000000111111 +110001000111 +010110000010 +011010101011 +000100110000 +101010111101 +000100101101 +001000001100 +010000000111 +100100100011 +010010111101 +000011001010 +010100111110 +011110110101 +110001000110 +010001100011 +100111010100 +100000101010 +110101110001 +111010000111 +011000000011 +001101011000 +100110101110 +101110101010 +001101101001 +111011101111 +011010001110 +111100001100 +111111001000 +111000110100 +111101100011 +010010101011 +111101100101 +111111000011 +110100000011 +110000010101 +001111111000 +100100101111 +100101111000 +011111110001 +000110001000 +001101110110 +110010011010 +110010101110 +011010011010 +000011000101 +101101100000 +100111111000 +001100000010 +101101101010 +100100111001 +111100101100 +101100110010 +010010111110 +101001100101 +100001111001 +100010000101 +110111010011 +100000010011 +111100000011 +110000000010 +101101001100 +011001001000 +101011110001 +011111011010 +110001010111 +110001101100 +011001000011 +111101000011 +110100100110 +010111111001 +011011111101 +100100110011 +011111000100 +100010011110 +000010011011 +111101100111 +111001111010 +001111111100 +111011001111 +111011110100 +000001101111 +110010110110 +101000101101 +111000011100 +001001101010 +010110100001 +000101110110 +110101101101 +000001001010 +001011010011 +010011001001 +100101111010 +000100011011 +000100010010 +101110110001 +100000011001 +011000010000 +101111001010 +101111100111 +001000000110 +100110011100 +001010101011 +111001001100 +101110101011 +100100011001 +010011101001 +110000001100 +101010100000 +011101010010 +001010001110 +001111101110 +101101011100 +011000100001 +111100011101 +010011110000 +111010001011 +011101000111 +001100000100 +101110010110 +111101010111 +011010100001 +011110000101 +011100001100 +100100010011 +000100110111 +100101111110 +010100011011 +111110100000 +011010011111 +011100010011 +010111101000 +000000010111 +100001110001 +111100011100 +001010110100 +100111000000 +001110101000 +011010000001 +110101110110 +010010110101 +011110100000 +010101001001 +011111111100 +011100110010 +100101011010 +011011000101 +101000110011 +000000100101 +110111101001 +010101100110 +101101111011 +011100100110 +101110011101 +010000001001 +000010100111 +000000110110 +101111101110 +111100010011 +001110101001 +000000011000 +110011100011 +100001101010 +010010101111 +110111100011 +011001110001 +101000100001 +011111001101 +110101011101 +000010110100 +101110101111 +111011000111 +101101001001 +100110000111 +001110110100 +001001100010 +010110001001 +100010001010 +111100000101 +101111101000 +100001100110 +111001010001 +110101111100 +000010100011 +010001010010 +011111101110 +101110011010 +110111101011 +110101000110 +101001111000 +000110010010 +110010011100 +101101010100 +000011001100 +010100100000 +001010001111 +100111111110 +100111011001 +001011100010 +101010101110 +011011001111 +010011111001 +101101000110 +100001111011 +000100001000 +111111010100 +111001111101 +001100101100 +000010111000 +000110110011 +011101110011 +111100000001 +100000100101 +100011001110 +101000101100 +101010010000 +110110110000 +010101011010 +001101100101 +010010101010 +111000100100 +110000001101 +100001000000 +010000100011 +110001010001 +010010111001 +011100000110 +100111100010 +110110110110 +100001000001 +100010101010 +001111100110 +101101101110 +110010010111 +111100101011 +101011110010 +111001011110 +010101000010 +101011001010 +001111110111 +111100100101 +111001110010 +010110001101 +110000110100 +110010110000 +101110101101 +001010000001 +101111000101 +001110100001 +010011101111 +001100000111 +101100110001 +110011111011 +011110001010 +010111111101 +000001111011 +000001001001 +001101000100 +111110011011 +010000011011 +110011000110 +001010000111 +111100011110 +000110111010 +001011101110 +001010000101 +011101010111 +110000101111 +010010010011 +110100110110 +100011000011 +001111100001 +000110000000 +000110111110 +011001100001 +010111111010 +010101010111 +000010011000 +010011000010 +100000011100 +000111101101 +001001010000 +111000000011 +010110001010 +101000001000 +010000001000 +011001101110 +110001110110 +100010011011 +011011001000 +001100101111 +011010111100 +010100110011 +000111000011 +111101010011 +000111011011 +011110000110 +101100000001 +011111100000 +111010101110 +110001101010 +100101000100 +101011101001 +110010101111 +010010011011 +100110111101 +010000111010 +010100011000 +110111010101 +001000011100 +010011000110 +101010001000 +110010100011 +001101011010 +000011110000 +100101001101 +011001011111 +100011100111 +100001101000 +001100011100 +110001010000 +101001110111 +000001110010 +010011100111 +110011110011 +101110111100 +010110010101 +101101101101 +011001000010 +001110010010 +111111001101 +010000100111 +111101110011 +011101101000 +000111101100 +110101011100 +101001101101 +101001100011 +001101111011 +000111111001 +010000000010 +100011110000 +111111011110 +011000110010 +110001110010 +010010100110 +100000111101 +010001001110 +110001111111 +110111000100 +111010011100 +001100101001 +111001111100 +001100101010 +000000010010 +010111101011 +101100001111 +110101001100 +100101110010 +011101111110 +111100101110 +010010000100 +111010100010 +001000101011 +001000110111 +100011001001 +111101111010 +110101010111 +001101100010 +000110011100 +010111101111 +111110000010 +000100101011 +010000100110 +111000010100 +111110011111 +010001001100 +000000001000 +011001110101 +101110100000 +011100100001 +110001100101 +111101011001 +101000101001 +000011010100 +001000001111 +100101110100 +001101110011 +001000100111 +101011011100 +000100000010 +001111011001 +001001110101 +001101011110 +001111011010 +001111001011 +100010100011 +000000010011 +100100010100 +111001000011 +110110111110 +001110011101 +011011010111 +011100001111 +101110100101 +111101010110 +111100100111 +101111101100 +111000000001 +101011011101 +101011010101 +100111000001 +111100110001 +111111100001 +110001110101 +011010111011 +011100101000 +111101011010 +101010010100 +111001011011 +000100100010 +111110000111 +110110001000 +011100111001 +100100100100 +010000100010 +111010001000 +010001011010 +100010111110 +001001001111 +100001101101 +000001111000 +001100110110 +000101101010 +011000001001 +111011101010 +100110001101 +110001010011 +001000000111 +110111001101 +111010110111 +100010101101 +100101101011 +001111100010 +111011101001 +000001110001 +011110001000 +001111100100 +001001010010 +110011100001 +110011100100 +111110111110 +111011011001 +111111111011 +110011000111 +011111000110 +110001011101 +010101111000 +111100101101 +010001101001 +110001101001 +111101000010 +101110000111 +000011101101 +001110000010 +011110011101 +100011001101 +100010111011 +010001101011 +011101110110 +000010011001 +100100010101 +011100101101 +010010100010 +101110100011 +100001111110 +001011000000 +000000000010 +111000111110 +100010010101 +111101100010 +100101000110 +111001100100 +101111001111 +101110110111 +010001000100 +101101110010 +111001101101 +111101101111 +000100000100 +101011011011 +111000110001 +101010100101 +110100000001 +000111010110 +001000010100 +111110010111 +011101000110 +100111110010 +010010000011 +101011100100 +101000100110 +110101100001 +001110000000 +111101100100 +011101010011 +111100101000 +100000010101 +010011010011 +011000001100 +011111001111 +110100001011 +100000001111 +001011001010 +010001110110 +101000110001 +110001000101 +010100111001 +100000010010 +101010111100 +001110011001 +110000100011 +010010000111 +101111110000 +010101010010 +011010001001 +111010011111 +000101100010 +000101110011 +100011111100 +000100000111 +101101100011 +000101111010 +000011010001 +111000011101 +100110000110 +110100100011 +010111000010 +100011001011 +010011100000 +010111100101 +100011100000 +011000010010 +010111010010 +011010010110 +111001111001 +101100011100 +110111111000 +001001011000 +000000011100 +011000011010 +011110000001 +110110000100 +010010100111 +100000100111 +011111110110 +001010110000 +110011000011 +001010110011 +011110101011 +101011111001 +010101011000 +001100101011 +000111100011 +110010001111 +001011101000 +010101011111 +001101000010 +010011101000 +111111110110 +101011111111 +110000001010 +011011100110 +110001111000 +100001110000 +100011000101 +111001000101 +101101101000 +010000011110 +100100111110 +101010110010 +000000101101 +011100111011 +101110101000 +000011000001 +100010110010 +000101101101 +110110100001 +001001011111 +101111110010 +010011110101 +101000110100 +000001101000 +111110000000 +011000111100 +010010010010 +011110001111 +110100111000 +010011100011 +000100100100 +010000110001 +000000001011 +011110111000 +010000000011 +110010010100 +111110111001 +011111111001 +010000101000 +110101100011 +100110001001 +011011000111 +100110101010 +011011011111 +011001011001 +110110100101 +011101000010 +001000100100 +000100110100 +110000111010 +000100100101 +100000111110 +010110110101 +110100100001 +110101100111 +101000100000 +101110001001 +011000111110 +110010101010 +011100110000 +001101000011 +110101101110 +111000001010 +110101000001 +100111101001 +011010111001 +010011110011 +101000011011 +111001010111 +010000000001 +100111001010 +010101100111 +011100101100 +101011110111 +100111100110 +100111100000 +110010111100 +100011010011 +110011110000 +111100010010 +001000101010 +101110110110 +010111101101 +011110010000 +000101000101 +111110111000 +111010100001 +011101011101 +111110000011 +010011101010 +010111000111 +100010011001 +000010000000 +000000100100 +110110110101 +100010100100 +101000000101 +111111100000 +101101101111 +010100101110 +111111100101 +101000010101 +001011111000 +001110110011 +010101100000 +001010101010 +111001100101 +100110000011 +010101011011 +101001110100 +100011100001 +100110101000 diff --git a/Advent-of-Code-2021/AOC-3/input.txt~ b/Advent-of-Code-2021/AOC-3/input.txt~ new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Advent-of-Code-2021/AOC-3/input.txt~ diff --git a/Advent-of-Code-2021/AOC-3/sample.txt b/Advent-of-Code-2021/AOC-3/sample.txt new file mode 100644 index 0000000..a6366a8 --- /dev/null +++ b/Advent-of-Code-2021/AOC-3/sample.txt @@ -0,0 +1,12 @@ +00100 +11110 +10110 +10111 +10101 +01111 +00111 +11100 +10000 +11001 +00010 +01010 diff --git a/Advent-of-Code-2021/AOC-3/sample.txt~ b/Advent-of-Code-2021/AOC-3/sample.txt~ new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Advent-of-Code-2021/AOC-3/sample.txt~ diff --git a/Advent-of-Code-2021/AOC-5/build.sh b/Advent-of-Code-2021/AOC-5/build.sh new file mode 100755 index 0000000..6be9241 --- /dev/null +++ b/Advent-of-Code-2021/AOC-5/build.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -xe + +gcc -o main -Wall -Wextra main.c + +./main diff --git a/Advent-of-Code-2021/AOC-5/example.txt b/Advent-of-Code-2021/AOC-5/example.txt new file mode 100644 index 0000000..b258f68 --- /dev/null +++ b/Advent-of-Code-2021/AOC-5/example.txt @@ -0,0 +1,10 @@ +0,9 -> 5,9 +8,0 -> 0,8 +9,4 -> 3,4 +2,2 -> 2,1 +7,0 -> 7,4 +6,4 -> 2,0 +0,9 -> 2,9 +3,4 -> 1,4 +0,0 -> 8,8 +5,5 -> 8,2 diff --git a/Advent-of-Code-2021/AOC-5/input.txt b/Advent-of-Code-2021/AOC-5/input.txt new file mode 100644 index 0000000..04c5152 --- /dev/null +++ b/Advent-of-Code-2021/AOC-5/input.txt @@ -0,0 +1,500 @@ +60,28 -> 893,861 +934,945 -> 222,233 +125,246 -> 125,306 +490,255 -> 490,847 +457,868 -> 364,961 +610,46 -> 610,826 +338,711 -> 982,67 +199,581 -> 295,581 +578,489 -> 522,545 +180,516 -> 180,904 +354,363 -> 145,363 +757,471 -> 692,471 +896,71 -> 896,185 +967,744 -> 967,486 +166,19 -> 483,19 +469,22 -> 529,22 +774,311 -> 807,311 +617,308 -> 203,308 +694,405 -> 694,43 +378,176 -> 378,488 +989,189 -> 215,189 +375,96 -> 612,96 +505,467 -> 505,246 +77,832 -> 77,473 +686,879 -> 684,879 +360,593 -> 151,384 +387,322 -> 626,322 +66,784 -> 66,109 +100,411 -> 635,946 +722,14 -> 722,784 +724,751 -> 764,751 +788,844 -> 32,88 +905,799 -> 905,713 +282,502 -> 238,502 +685,259 -> 685,768 +116,578 -> 477,217 +115,78 -> 115,458 +329,569 -> 66,306 +817,815 -> 817,466 +781,909 -> 872,909 +62,44 -> 964,946 +755,307 -> 593,307 +436,56 -> 436,869 +596,815 -> 49,268 +465,986 -> 926,525 +885,254 -> 39,254 +947,433 -> 764,433 +719,787 -> 200,787 +380,461 -> 243,461 +675,434 -> 675,582 +106,548 -> 272,714 +703,143 -> 703,111 +238,745 -> 60,745 +646,235 -> 646,742 +243,439 -> 243,964 +347,763 -> 321,789 +322,294 -> 738,294 +134,361 -> 946,361 +223,30 -> 498,305 +78,721 -> 288,721 +792,875 -> 572,875 +548,380 -> 637,291 +85,417 -> 85,296 +766,81 -> 766,131 +340,218 -> 340,271 +56,962 -> 974,44 +415,940 -> 386,940 +960,60 -> 46,974 +719,527 -> 743,527 +971,986 -> 313,986 +415,316 -> 415,57 +612,556 -> 612,648 +421,776 -> 570,776 +478,533 -> 478,831 +758,304 -> 112,950 +258,950 -> 79,950 +329,349 -> 216,349 +527,38 -> 755,38 +517,239 -> 207,239 +497,944 -> 898,944 +418,642 -> 418,557 +828,750 -> 456,750 +632,916 -> 15,299 +955,973 -> 970,958 +474,524 -> 949,49 +842,690 -> 842,116 +203,267 -> 916,980 +128,562 -> 936,562 +682,963 -> 193,963 +704,822 -> 44,162 +371,309 -> 421,359 +379,240 -> 510,240 +547,177 -> 547,20 +784,968 -> 784,613 +75,138 -> 75,724 +725,48 -> 32,741 +141,674 -> 545,674 +193,922 -> 193,845 +916,831 -> 916,401 +912,232 -> 923,232 +127,911 -> 911,127 +140,381 -> 140,913 +472,243 -> 472,134 +311,548 -> 311,741 +415,590 -> 415,409 +20,984 -> 983,21 +572,575 -> 572,756 +804,188 -> 20,972 +485,104 -> 962,104 +31,966 -> 986,11 +584,473 -> 338,473 +974,962 -> 34,22 +176,279 -> 921,279 +305,863 -> 305,981 +137,889 -> 137,47 +888,259 -> 888,125 +794,774 -> 794,455 +193,118 -> 966,118 +429,302 -> 547,184 +59,49 -> 984,974 +978,56 -> 232,802 +23,142 -> 456,142 +532,574 -> 532,265 +936,263 -> 933,263 +773,856 -> 230,313 +182,809 -> 913,809 +364,958 -> 901,958 +724,290 -> 64,950 +312,967 -> 312,166 +208,286 -> 566,286 +828,907 -> 828,729 +79,692 -> 753,18 +235,601 -> 811,601 +735,206 -> 301,206 +246,112 -> 246,423 +712,439 -> 712,108 +570,179 -> 751,179 +766,22 -> 816,22 +51,686 -> 27,686 +50,954 -> 50,31 +762,413 -> 762,601 +223,812 -> 670,812 +391,882 -> 712,882 +842,332 -> 922,332 +540,88 -> 540,124 +75,312 -> 161,312 +979,984 -> 10,15 +479,856 -> 823,856 +690,491 -> 298,883 +481,401 -> 481,279 +870,942 -> 276,348 +39,935 -> 937,37 +706,275 -> 706,948 +530,892 -> 535,897 +743,223 -> 929,223 +682,917 -> 490,917 +616,268 -> 456,268 +484,72 -> 429,72 +61,365 -> 430,365 +382,741 -> 910,741 +710,406 -> 330,406 +795,770 -> 55,770 +117,416 -> 352,651 +593,151 -> 20,724 +238,556 -> 584,556 +680,583 -> 680,504 +678,440 -> 212,440 +508,222 -> 508,844 +435,873 -> 93,873 +129,607 -> 468,268 +280,147 -> 94,147 +238,872 -> 971,139 +881,339 -> 664,339 +289,960 -> 289,664 +70,762 -> 973,762 +429,24 -> 429,202 +907,785 -> 907,190 +598,548 -> 598,63 +324,220 -> 281,220 +754,980 -> 79,980 +568,508 -> 583,508 +364,712 -> 503,712 +655,963 -> 898,963 +253,359 -> 46,566 +989,989 -> 14,14 +329,924 -> 380,924 +248,826 -> 675,826 +417,428 -> 417,320 +13,12 -> 984,983 +916,53 -> 916,896 +247,285 -> 377,155 +937,588 -> 710,588 +473,270 -> 466,277 +567,74 -> 567,388 +371,470 -> 228,470 +640,96 -> 766,96 +725,499 -> 372,499 +184,561 -> 184,236 +654,446 -> 933,446 +156,153 -> 978,975 +811,228 -> 922,339 +84,861 -> 878,67 +622,329 -> 622,425 +415,186 -> 450,221 +109,488 -> 653,488 +982,16 -> 33,965 +100,885 -> 829,156 +342,914 -> 342,636 +177,323 -> 728,874 +81,414 -> 406,739 +889,79 -> 889,698 +504,450 -> 148,806 +961,33 -> 51,943 +656,21 -> 100,21 +32,60 -> 32,562 +499,174 -> 499,301 +162,740 -> 162,906 +190,183 -> 811,804 +93,960 -> 13,960 +787,681 -> 866,681 +254,332 -> 254,79 +595,873 -> 595,496 +151,737 -> 151,390 +974,429 -> 990,429 +295,784 -> 295,513 +378,942 -> 378,283 +152,838 -> 796,838 +624,630 -> 881,887 +90,420 -> 412,420 +868,69 -> 46,891 +75,890 -> 452,513 +133,460 -> 133,985 +970,145 -> 549,145 +149,462 -> 916,462 +92,845 -> 92,268 +580,99 -> 250,99 +618,708 -> 618,652 +690,948 -> 690,38 +808,594 -> 944,730 +100,359 -> 312,359 +546,392 -> 41,897 +593,413 -> 593,892 +602,484 -> 602,144 +90,863 -> 90,170 +888,987 -> 888,162 +229,932 -> 960,201 +919,654 -> 70,654 +13,684 -> 13,348 +743,477 -> 166,477 +901,113 -> 936,113 +167,567 -> 540,567 +566,729 -> 566,660 +102,660 -> 615,660 +273,241 -> 273,413 +512,241 -> 512,643 +869,695 -> 614,440 +356,583 -> 356,408 +61,345 -> 61,233 +973,33 -> 88,918 +977,130 -> 771,130 +422,382 -> 899,382 +536,517 -> 914,139 +563,755 -> 312,755 +770,581 -> 770,940 +103,186 -> 313,186 +681,490 -> 77,490 +676,351 -> 913,588 +292,700 -> 862,700 +445,175 -> 188,175 +62,490 -> 173,601 +530,455 -> 63,455 +145,85 -> 832,772 +273,414 -> 273,240 +25,888 -> 25,684 +599,393 -> 599,232 +198,296 -> 584,682 +217,886 -> 614,886 +464,598 -> 362,496 +874,106 -> 874,227 +248,511 -> 940,511 +501,861 -> 21,381 +385,232 -> 341,232 +258,449 -> 337,449 +94,46 -> 910,862 +946,825 -> 946,341 +93,836 -> 93,781 +170,903 -> 616,457 +717,333 -> 717,238 +404,243 -> 516,243 +611,579 -> 217,973 +76,851 -> 76,255 +181,780 -> 661,780 +316,188 -> 333,188 +799,92 -> 779,92 +955,374 -> 869,374 +872,792 -> 280,200 +337,239 -> 438,239 +424,706 -> 273,857 +501,239 -> 684,239 +198,671 -> 882,671 +790,775 -> 802,775 +708,624 -> 361,277 +547,731 -> 547,621 +264,449 -> 293,449 +496,870 -> 496,396 +988,959 -> 988,285 +19,51 -> 926,958 +472,537 -> 127,882 +188,488 -> 478,198 +949,376 -> 797,224 +448,609 -> 348,609 +838,285 -> 838,865 +796,142 -> 70,868 +848,91 -> 972,91 +722,964 -> 722,409 +313,156 -> 313,725 +925,251 -> 925,687 +803,815 -> 113,125 +505,517 -> 505,337 +935,920 -> 235,920 +674,274 -> 63,885 +458,981 -> 626,981 +928,950 -> 836,950 +163,453 -> 695,985 +57,374 -> 398,374 +937,327 -> 937,811 +975,932 -> 265,222 +490,583 -> 490,482 +170,183 -> 196,183 +738,978 -> 738,812 +914,170 -> 914,202 +202,885 -> 499,885 +270,887 -> 150,887 +447,783 -> 831,399 +66,136 -> 77,136 +536,703 -> 662,829 +297,821 -> 297,792 +640,572 -> 321,572 +244,833 -> 865,212 +454,672 -> 454,726 +133,812 -> 303,642 +280,589 -> 184,589 +977,572 -> 977,42 +62,247 -> 215,247 +427,503 -> 809,885 +671,85 -> 671,770 +296,990 -> 296,558 +103,19 -> 971,887 +263,712 -> 263,329 +954,897 -> 954,41 +278,536 -> 278,346 +270,620 -> 983,620 +229,863 -> 91,863 +935,413 -> 394,413 +709,668 -> 77,668 +310,853 -> 310,286 +534,694 -> 511,717 +349,726 -> 349,439 +113,196 -> 970,196 +836,340 -> 709,340 +38,485 -> 38,14 +38,278 -> 569,278 +862,90 -> 281,671 +677,124 -> 405,124 +399,568 -> 536,705 +611,839 -> 188,416 +570,925 -> 570,251 +804,368 -> 284,888 +262,842 -> 388,842 +751,800 -> 751,504 +762,882 -> 201,321 +411,421 -> 807,421 +654,406 -> 265,795 +863,558 -> 625,320 +451,673 -> 451,354 +359,239 -> 566,239 +259,211 -> 955,907 +253,506 -> 542,217 +547,794 -> 373,620 +132,263 -> 581,712 +168,237 -> 168,142 +834,296 -> 152,978 +156,14 -> 955,14 +927,22 -> 285,664 +384,291 -> 362,269 +91,561 -> 91,19 +472,953 -> 472,576 +700,666 -> 723,689 +447,815 -> 566,815 +698,411 -> 698,762 +427,606 -> 119,298 +531,401 -> 669,263 +681,21 -> 681,111 +168,360 -> 168,447 +74,67 -> 717,67 +287,88 -> 345,88 +234,80 -> 234,848 +583,251 -> 33,251 +200,522 -> 366,356 +815,936 -> 27,148 +139,302 -> 139,768 +473,69 -> 473,664 +42,813 -> 42,918 +881,188 -> 881,345 +457,920 -> 301,764 +894,662 -> 779,662 +750,411 -> 750,368 +986,167 -> 246,167 +914,418 -> 742,590 +710,110 -> 63,757 +353,493 -> 353,473 +211,700 -> 181,700 +492,604 -> 25,604 +212,174 -> 362,174 +801,434 -> 752,385 +956,861 -> 469,374 +197,318 -> 257,378 +604,594 -> 604,809 +716,447 -> 306,857 +974,974 -> 24,24 +925,467 -> 925,311 +357,381 -> 769,381 +714,395 -> 372,395 +360,718 -> 728,718 +161,186 -> 730,755 +407,316 -> 407,61 +466,214 -> 333,347 +190,955 -> 190,678 +969,48 -> 72,945 +296,153 -> 833,153 +930,400 -> 637,400 +606,953 -> 541,953 +978,179 -> 21,179 +112,49 -> 112,793 +346,881 -> 151,881 +737,404 -> 737,693 +98,271 -> 98,144 +469,830 -> 46,830 +246,651 -> 246,243 +47,129 -> 880,962 +449,609 -> 980,78 +603,307 -> 603,896 +121,339 -> 22,240 +97,726 -> 274,726 +527,668 -> 786,409 +649,162 -> 321,162 +253,10 -> 253,690 +43,748 -> 590,748 +245,424 -> 245,495 +509,595 -> 261,843 +924,758 -> 683,758 +693,516 -> 684,507 +654,201 -> 654,840 +321,543 -> 315,549 +840,309 -> 764,233 +865,183 -> 177,871 +700,135 -> 14,821 +178,178 -> 971,971 +88,649 -> 88,899 +327,37 -> 327,58 +252,687 -> 482,457 +12,771 -> 754,29 +309,695 -> 630,695 +146,671 -> 146,695 +226,697 -> 798,697 +239,736 -> 239,945 +483,756 -> 483,965 +306,475 -> 800,969 +580,927 -> 580,102 +867,83 -> 830,83 +635,359 -> 761,233 +733,851 -> 180,298 +478,76 -> 401,76 +552,581 -> 552,525 +842,724 -> 847,724 +652,76 -> 385,76 +695,894 -> 245,894 +301,487 -> 301,665 +412,555 -> 412,80 +591,311 -> 289,311 +961,933 -> 69,41 +78,266 -> 14,202 +255,696 -> 766,696 +715,246 -> 508,246 +756,567 -> 188,567 +866,377 -> 652,591 +267,226 -> 204,163 +506,104 -> 506,587 +270,434 -> 270,395 +879,127 -> 879,859 +65,669 -> 65,747 +486,745 -> 612,745 +276,246 -> 276,41 +41,840 -> 226,655 +207,495 -> 94,495 +142,970 -> 285,970 +73,239 -> 83,239 +787,409 -> 527,409 +678,565 -> 678,582 +314,185 -> 67,185 diff --git a/Advent-of-Code-2021/AOC-5/main b/Advent-of-Code-2021/AOC-5/main Binary files differnew file mode 100755 index 0000000..c4629f0 --- /dev/null +++ b/Advent-of-Code-2021/AOC-5/main diff --git a/Advent-of-Code-2021/AOC-5/main.c b/Advent-of-Code-2021/AOC-5/main.c new file mode 100644 index 0000000..ea39e06 --- /dev/null +++ b/Advent-of-Code-2021/AOC-5/main.c @@ -0,0 +1,138 @@ +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> +#include <string.h> + +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) + +#if 0 +#define PART_1 +#else +#define PART_2 +#endif + +#if 0 +#define FILE_PATH "example.txt" +#define WIDTH 10 +#define HEIGHT 10 +#else +#define FILE_PATH "input.txt" +#define WIDTH 10000 +#define HEIGHT 10000 +#endif + +int board[WIDTH][HEIGHT] = {0}; + +void draw_line(int x1, int y1, int x2, int y2) +{ + if(x1 == x2) + { + for(int y = MIN(y1, y2); y <= MAX(y1, y2); y++) + board[x1][y]++; + + } + else if(y1 == y2) + { + for(int x = MIN(x1, x2); x <= MAX(x1, x2); x++) + board[x][y1]++; + } +#ifdef PART_2 + else + { + int direction_x = (x1 < x2) ? 1 : -1; + int direction_y = (y1 < y2) ? 1 : -1; + + int y = y1; + int x = x1; + while(!((y == y2) && (x == x2))) + { + board[x][y]++; + x+=direction_x; + y+=direction_y; + } + } +#endif +} + +void parse() +{ + FILE *fp = fopen(FILE_PATH, "r"); + if(!fp) { + fprintf(stderr, "ERROR: Could not open file: %s", FILE_PATH); + exit(EXIT_FAILURE); + } + + char *vec1, *vec2; + char line[256]; + while(fgets(line, sizeof(line), fp) != NULL) + { + vec1 = strtok(line, " -> "); + vec2 = strtok(NULL, " -> "); + + int x1, y1, x2, y2; + x1 = atoi(strtok(vec1, ",")); + y1 = atoi(strtok(NULL, ",")); + x2 = atoi(strtok(vec2, ",")); + y2 = atoi(strtok(NULL, ",")); + + draw_line(x1, y1, x2, y2); + } +} + +void print_board() +{ + for(int i = 0; i < HEIGHT; i++) + { + for(int j = 0; j < WIDTH; j++) + { + if(board[j][i] == 0) + putc('.', stdout); + else if(board[j][i] == 1) + putc('#', stdout); + else + putc('@', stdout); + } + putc('\n', stdout); + } +} + +void part_1() +{ + parse(); + + int count = 0; + for(int i = 0; i < HEIGHT; i++) + for(int j = 0; j < WIDTH; j++) + if(board[j][i] >= 2) count++; + + printf("Count is %d\n", count); +} + +void part_2() +{ + parse(); + + int count = 0; + for(int i = 0; i < HEIGHT; i++) + for(int j = 0; j < WIDTH; j++) + if(board[j][i] >= 2) count++; + + // print_board(); + + printf("Count is %d\n", count); +} + +int main(void) +{ + +#ifdef PART_1 + part_1(); +#endif + +#ifdef PART_2 + part_2(); +#endif + + return 0; +} diff --git a/Advent-of-Code-2021/AOC-6/aoc-6 b/Advent-of-Code-2021/AOC-6/aoc-6 Binary files differnew file mode 100755 index 0000000..9fe1541 --- /dev/null +++ b/Advent-of-Code-2021/AOC-6/aoc-6 diff --git a/Advent-of-Code-2021/AOC-6/aoc-6.c b/Advent-of-Code-2021/AOC-6/aoc-6.c new file mode 100644 index 0000000..42cd75b --- /dev/null +++ b/Advent-of-Code-2021/AOC-6/aoc-6.c @@ -0,0 +1,78 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <stdint.h> + +#define N 9 +#define MAXDAYS 256 + +u_int64_t table[N]; +u_int64_t temp_table[N]; + +void PrintTable() +{ + for(int i=0; i<N; i++) + { + printf("%llu: %llu\n", i, table[i]); + } +} + +void NextDay() +{ + memset(temp_table, 0, sizeof(u_int64_t)*N); + + for(int i=1; i<N; i++) + { + temp_table[i-1] = table[i]; + } + + temp_table[6] += table[0]; + temp_table[8] += table[0]; + + memcpy(table, temp_table, sizeof(u_int64_t)*N); +} + +u_int64_t TableSize() +{ + u_int64_t size = 0; + for(int i=0; i<N; i++) + { + size += table[i]; + } + + return size; +} + +void ParseInput(char *input) +{ + for(int i=0; i<strlen(input); i++) + { + if(input[i] != ',') + table[atoi(&(input[i]))] += 1; + } +} + +int main(void) +{ + memset(table, 0, sizeof(u_int64_t)*N); + + ParseInput("2,1,2,1,5,1,5,1,2,2,1,1,5,1,4,4,4,3,1,2,2,3,4,1,1,5,1,1,4,2,5,5,5,1,1,4,5,4,1,1,4,2,1,4,1,2,2,5,1,1,5,1,1,3,4,4,1,2,3,1,5,5,4,1,4,1,2,1,5,1,1,1,3,4,1,1,5,1,5,1,1,5,1,1,4,3,2,4,1,4,1,5,3,3,1,5,1,3,1,1,4,1,4,5,2,3,1,1,1,1,3,1,2,1,5,1,1,5,1,1,1,1,4,1,4,3,1,5,1,1,5,4,4,2,1,4,5,1,1,3,3,1,1,4,2,5,5,2,4,1,4,5,4,5,3,1,4,1,5,2,4,5,3,1,3,2,4,5,4,4,1,5,1,5,1,2,2,1,4,1,1,4,2,2,2,4,1,1,5,3,1,1,5,4,4,1,5,1,3,1,3,2,2,1,1,4,1,4,1,2,2,1,1,3,5,1,2,1,3,1,4,5,1,3,4,1,1,1,1,4,3,3,4,5,1,1,1,1,1,2,4,5,3,4,2,1,1,1,3,3,1,4,1,1,4,2,1,5,1,1,2,3,4,2,5,1,1,1,5,1,1,4,1,2,4,1,1,2,4,3,4,2,3,1,1,2,1,5,4,2,3,5,1,2,3,1,2,2,1,4"); + // ParseInput("3,4,3,1,2"); + + PrintTable(); + printf("Size: %llu\n", TableSize()); + printf("----------------------------\n"); + + for(int i=0; i < MAXDAYS; i++) + { + NextDay(); + } + + PrintTable(); + printf("Size: %llu\n", TableSize()); + printf("Day: %llu\n", MAXDAYS); + + return 0; + +} diff --git a/Advent-of-Code-2021/AOC-6/aoc-6.c~ b/Advent-of-Code-2021/AOC-6/aoc-6.c~ new file mode 100644 index 0000000..5b51725 --- /dev/null +++ b/Advent-of-Code-2021/AOC-6/aoc-6.c~ @@ -0,0 +1,65 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#define N 9 +#define MAXDAYS 80 + +int table[N]; + +void PrintTable() +{ + for(int i=0; i<N; i++) + { + printf("%d: %d\n", i, table[i]); + } +} + +void NextDay() +{ + int temp_table[N]; + memset(temp_table, 0, sizeof(int)*N); + + for(int i=1; i<N; i++) + { + temp_table[i-1] = table[i]; + } + + temp_table[6] += table[0]; + temp_table[8] += table[0]; + + memcpy(table, temp_table, sizeof(int)*N); +} + +int TableSize() +{ + int size = 0; + for(int i=0; i<N; i++) + { + size += table[i]; + } + + return size; +} + +int main(void) +{ + memset(table, 0, sizeof(int)*N); + + table[1] = 1; + table[2] = 1; + table[3] = 2; + table[4] = 1; + + for(int i=0; i < MAXDAYS; i++) + { + NextDay(); + } + + PrintTable(); + printf("Size: %d\n", TableSize()); + printf("Day: %d\n", MAXDAYS); + + return 0; +} diff --git a/Advent-of-Code-2021/AOC-7/aoc-7 b/Advent-of-Code-2021/AOC-7/aoc-7 Binary files differnew file mode 100755 index 0000000..b19d5ab --- /dev/null +++ b/Advent-of-Code-2021/AOC-7/aoc-7 diff --git a/Advent-of-Code-2021/AOC-7/aoc-7.c b/Advent-of-Code-2021/AOC-7/aoc-7.c new file mode 100644 index 0000000..165c671 --- /dev/null +++ b/Advent-of-Code-2021/AOC-7/aoc-7.c @@ -0,0 +1,124 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define CAP 3000 + +#if 0 +#define PFILE "sample.txt" +#else +#define PFILE "input.txt" +#endif + +int vals[CAP]; +size_t vals_sz = 0; + +void Parse() +{ + // Parse + char ch; + FILE *fp; + fp = fopen(PFILE, "r"); + + char int_buf[6]; + memset(int_buf, '\0', sizeof(int_buf)); + int n = 0; + while((ch = fgetc(fp)) != EOF) + { + if(ch != ',') + { + int_buf[n] = ch; + n += 1; + continue; + } + + vals[vals_sz] = atoi(int_buf); + vals_sz += 1; + memset(int_buf, '\0', sizeof(int_buf)); + n = 0; + } + +} + +void Part1() +{ + Parse(); + size_t fuel_arr[CAP]; + size_t fuel = 0; + + for(int i = 0; i < CAP; i++) + { + int target = i; + for(int j = 0; j < vals_sz; j++) + fuel += abs(target - vals[j]); + + fuel_arr[i] = fuel; + fuel = 0; + } + + // Find the smallest in the fuel array + for(size_t i = 0; i < CAP; i++) + { + size_t counter = 0; + for(int j = 0; j < CAP; j++) + { + if(fuel_arr[i] <= fuel_arr[j]) + counter += 1; + } + + if(counter == CAP) + { + printf("%d\n", fuel_arr[i]); + break; + } + } +} + +size_t CountFuel(int target) +{ + // somehow works idk + size_t sum = 0; + for(size_t i = 1; i <= target; i++) + sum += i; + return sum; +} + +void Part2() +{ + Parse(); + size_t fuel_arr[CAP]; + size_t fuel = 0; + + for(int i = 0; i < CAP; i++) + { + size_t target = i; + for(int j = 0; j < vals_sz; j++) + fuel += CountFuel(abs(target - vals[j])); + + fuel_arr[i] = fuel; + fuel = 0; + } + + // Find the smallest in the fuel array + for(size_t i = 0; i < CAP; i++) + { + size_t counter = 0; + for(size_t j = 0; j < CAP; j++) + { + if(fuel_arr[i] <= fuel_arr[j]) + counter += 1; + } + + if(counter == CAP) + { + printf("%d: %d\n", i, fuel_arr[i]); + break; + } + } +} + +int main() +{ + Part2(); + return 0; +} diff --git a/Advent-of-Code-2021/AOC-7/input.txt b/Advent-of-Code-2021/AOC-7/input.txt new file mode 100644 index 0000000..989430d --- /dev/null +++ b/Advent-of-Code-2021/AOC-7/input.txt @@ -0,0 +1 @@ +1101,1,29,67,1102,0,1,65,1008,65,35,66,1005,66,28,1,67,65,20,4,0,1001,65,1,65,1106,0,8,99,35,67,101,99,105,32,110,39,101,115,116,32,112,97,115,32,117,110,101,32,105,110,116,99,111,100,101,32,112,114,111,103,114,97,109,10,1247,39,529,198,497,33,1618,2,28,653,764,312,163,62,263,4,243,1277,8,432,324,564,44,56,745,0,534,558,1026,313,482,410,411,63,461,261,561,62,428,42,1806,251,1186,553,241,795,127,1004,94,183,382,194,890,1025,1153,1064,155,278,203,666,1098,678,228,12,530,226,680,476,74,122,136,64,515,630,137,187,146,249,77,879,1174,257,9,353,1496,239,131,21,330,922,110,5,804,2,1195,756,195,399,1306,1495,1088,687,102,901,222,3,717,853,1242,573,406,645,1211,193,319,35,302,677,704,42,69,228,247,420,401,1006,124,662,355,746,483,211,1484,146,104,314,154,170,932,215,1600,1250,20,134,1038,724,728,157,261,1373,1113,449,339,415,1165,172,956,466,327,1342,27,1031,1233,547,636,100,440,510,154,28,949,222,867,11,297,218,814,169,358,1088,1071,630,1360,1106,249,13,312,7,56,1667,948,69,767,279,1032,82,139,636,592,684,294,952,83,252,158,450,1250,78,548,1052,1,1231,888,253,533,637,694,955,448,1351,1569,1060,65,269,450,102,962,408,259,61,20,437,14,1676,16,533,90,1727,623,286,48,395,169,271,140,652,139,1497,356,98,60,362,964,880,934,544,140,322,428,80,215,192,300,431,126,46,109,780,209,776,203,443,60,889,21,882,22,127,476,694,174,226,1041,364,282,541,429,755,770,931,967,1346,1240,647,150,199,137,181,1177,571,150,1104,56,517,286,1204,346,619,1269,307,425,228,254,328,570,956,1567,810,356,196,77,31,429,1178,6,502,310,443,1221,119,571,583,18,256,460,694,650,799,200,121,119,125,894,1263,610,892,635,93,320,252,371,1416,150,664,154,344,381,610,819,591,536,1312,1521,148,1232,70,50,328,226,752,1685,729,449,31,963,402,62,1365,928,619,538,950,202,19,271,292,59,55,345,189,302,29,217,486,1576,62,1364,122,1667,388,62,182,1278,13,459,729,821,293,78,5,111,135,868,94,196,14,342,185,271,1055,350,363,235,137,142,31,30,466,922,436,1174,81,114,244,770,54,288,579,4,1287,36,321,849,751,1081,342,359,829,1147,1092,125,269,1652,493,22,456,193,49,70,288,4,954,1718,84,154,24,171,220,1033,66,289,395,1732,1553,616,411,899,1398,402,219,621,343,293,422,494,80,732,1210,449,72,236,307,541,10,620,1361,605,351,1304,475,215,989,153,8,1229,113,216,3,170,998,308,964,1755,223,1694,1937,60,41,1120,491,1270,766,501,326,236,632,163,880,963,1213,1030,444,229,425,239,834,59,66,580,488,303,475,457,1182,150,1273,53,22,53,224,536,945,824,56,694,187,586,555,1464,188,538,286,120,260,38,70,13,678,916,542,235,1138,34,259,12,280,178,45,213,1,580,268,114,1076,536,185,825,374,282,186,3,356,393,385,597,53,187,288,10,194,447,949,521,84,124,16,221,153,800,969,241,40,76,565,7,238,252,13,276,461,30,1034,129,204,657,793,630,1068,97,537,226,155,363,531,458,123,442,1155,371,196,1764,1049,73,258,853,2,653,923,189,472,1119,582,974,948,447,161,1737,765,93,369,48,293,762,58,2,1282,242,67,1310,129,468,425,116,471,768,291,878,1138,569,427,725,515,67,526,766,213,1307,288,1589,1304,3,287,1050,14,7,428,1684,479,355,72,1233,21,1449,284,11,27,315,274,181,215,486,247,946,59,158,432,231,178,1722,13,189,439,13,72,211,239,841,175,893,234,328,154,134,13,653,31,40,303,110,172,113,515,69,1009,1413,450,172,168,92,385,1555,216,1487,72,173,339,496,779,1696,153,49,342,1225,141,873,402,777,269,767,361,108,536,1432,343,23,380,716,1609,958,1512,743,246,315,220,1634,16,405,61,1150,350,620,1,13,749,9,738,1391,334,148,1142,220,662,1612,878,65,164,235,95,499,929,399,1675,886,86,452,238,487,354,103,7,372,428,971,419,41,56,613,126,819,354,170,1025,1183,2,1201,813,339,272,400,13,221,1021,182,192,1239,52,508,266,42,504,1281,779,1629,46,65,541,1004,115,384,922,89,372,56,211,419,420,149,316,670,1271,253,845,260,25,624,402,54,270,1366,831,170,47,11,235,106,757,854,1343,548,32,29,283,200,11,443,12,372,239,165,440,1099,104,686,335,656,1182,994,1126,14,503,508,766,634,744,660,102,56,449,227,96,357,23,83,653,519,144,9,59,892,253,984,777,178,629,82, diff --git a/Advent-of-Code-2021/AOC-7/sample.txt b/Advent-of-Code-2021/AOC-7/sample.txt new file mode 100644 index 0000000..2cbe7b6 --- /dev/null +++ b/Advent-of-Code-2021/AOC-7/sample.txt @@ -0,0 +1 @@ +16,1,2,0,4,2,7,1,2,14, |