From aec1c07260257ba7c28eff53f422ddb7daaf316a Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 31 Jul 2022 11:46:17 +0300 Subject: Big Bang --- Advent-of-Code-2021/AOC-1/aoc-1 | Bin 0 -> 16640 bytes Advent-of-Code-2021/AOC-1/aoc-1.c | 81 ++ Advent-of-Code-2021/AOC-1/aoc-1.c~ | 1 + Advent-of-Code-2021/AOC-1/input-1.txt | 2000 ++++++++++++++++++++++++++++++++ Advent-of-Code-2021/AOC-1/input-1.txt~ | 0 Advent-of-Code-2021/AOC-11/build.sh | 7 + Advent-of-Code-2021/AOC-11/example.txt | 10 + Advent-of-Code-2021/AOC-11/input.txt | 10 + Advent-of-Code-2021/AOC-11/main | Bin 0 -> 21136 bytes Advent-of-Code-2021/AOC-11/main.c | 114 ++ Advent-of-Code-2021/AOC-13/build.sh | 7 + Advent-of-Code-2021/AOC-13/example.txt | 21 + Advent-of-Code-2021/AOC-13/input.txt | 865 ++++++++++++++ Advent-of-Code-2021/AOC-13/main | Bin 0 -> 21624 bytes Advent-of-Code-2021/AOC-13/main.c | 169 +++ Advent-of-Code-2021/AOC-14/aoc-14 | Bin 0 -> 21216 bytes Advent-of-Code-2021/AOC-14/aoc-14.c | 202 ++++ Advent-of-Code-2021/AOC-14/input.txt | 102 ++ Advent-of-Code-2021/AOC-14/sample.txt | 18 + Advent-of-Code-2021/AOC-15/aoc-15 | Bin 0 -> 16712 bytes Advent-of-Code-2021/AOC-15/aoc-15.c | 128 ++ Advent-of-Code-2021/AOC-15/aoc-15.c~ | 0 Advent-of-Code-2021/AOC-15/input.txt | 100 ++ Advent-of-Code-2021/AOC-15/input.txt~ | 0 Advent-of-Code-2021/AOC-15/sample.txt | 10 + Advent-of-Code-2021/AOC-15/sample.txt~ | 0 Advent-of-Code-2021/AOC-2/aoc-2 | Bin 0 -> 16568 bytes Advent-of-Code-2021/AOC-2/aoc-2.c | 104 ++ Advent-of-Code-2021/AOC-2/aoc-2.c~ | 0 Advent-of-Code-2021/AOC-2/input-2.txt | 1000 ++++++++++++++++ Advent-of-Code-2021/AOC-2/input-2.txt~ | 0 Advent-of-Code-2021/AOC-25/aoc-25 | Bin 0 -> 16896 bytes Advent-of-Code-2021/AOC-25/aoc-25.c | 154 +++ Advent-of-Code-2021/AOC-25/aoc-25.c~ | 139 +++ Advent-of-Code-2021/AOC-25/input.txt | 137 +++ Advent-of-Code-2021/AOC-25/input.txt~ | 0 Advent-of-Code-2021/AOC-25/sample.txt | 0 Advent-of-Code-2021/AOC-3/aoc-3 | Bin 0 -> 16648 bytes Advent-of-Code-2021/AOC-3/aoc-3.c | 86 ++ Advent-of-Code-2021/AOC-3/aoc-3.c~ | 84 ++ Advent-of-Code-2021/AOC-3/input.txt | 1000 ++++++++++++++++ Advent-of-Code-2021/AOC-3/input.txt~ | 0 Advent-of-Code-2021/AOC-3/sample.txt | 12 + Advent-of-Code-2021/AOC-3/sample.txt~ | 0 Advent-of-Code-2021/AOC-5/build.sh | 7 + Advent-of-Code-2021/AOC-5/example.txt | 10 + Advent-of-Code-2021/AOC-5/input.txt | 500 ++++++++ Advent-of-Code-2021/AOC-5/main | Bin 0 -> 21208 bytes Advent-of-Code-2021/AOC-5/main.c | 138 +++ Advent-of-Code-2021/AOC-6/aoc-6 | Bin 0 -> 16480 bytes Advent-of-Code-2021/AOC-6/aoc-6.c | 78 ++ Advent-of-Code-2021/AOC-6/aoc-6.c~ | 65 ++ Advent-of-Code-2021/AOC-7/aoc-7 | Bin 0 -> 20984 bytes Advent-of-Code-2021/AOC-7/aoc-7.c | 124 ++ Advent-of-Code-2021/AOC-7/input.txt | 1 + Advent-of-Code-2021/AOC-7/sample.txt | 1 + 56 files changed, 7485 insertions(+) create mode 100755 Advent-of-Code-2021/AOC-1/aoc-1 create mode 100644 Advent-of-Code-2021/AOC-1/aoc-1.c create mode 100644 Advent-of-Code-2021/AOC-1/aoc-1.c~ create mode 100644 Advent-of-Code-2021/AOC-1/input-1.txt create mode 100644 Advent-of-Code-2021/AOC-1/input-1.txt~ create mode 100755 Advent-of-Code-2021/AOC-11/build.sh create mode 100644 Advent-of-Code-2021/AOC-11/example.txt create mode 100644 Advent-of-Code-2021/AOC-11/input.txt create mode 100755 Advent-of-Code-2021/AOC-11/main create mode 100644 Advent-of-Code-2021/AOC-11/main.c create mode 100755 Advent-of-Code-2021/AOC-13/build.sh create mode 100644 Advent-of-Code-2021/AOC-13/example.txt create mode 100644 Advent-of-Code-2021/AOC-13/input.txt create mode 100755 Advent-of-Code-2021/AOC-13/main create mode 100644 Advent-of-Code-2021/AOC-13/main.c create mode 100755 Advent-of-Code-2021/AOC-14/aoc-14 create mode 100644 Advent-of-Code-2021/AOC-14/aoc-14.c create mode 100644 Advent-of-Code-2021/AOC-14/input.txt create mode 100644 Advent-of-Code-2021/AOC-14/sample.txt create mode 100755 Advent-of-Code-2021/AOC-15/aoc-15 create mode 100644 Advent-of-Code-2021/AOC-15/aoc-15.c create mode 100644 Advent-of-Code-2021/AOC-15/aoc-15.c~ create mode 100644 Advent-of-Code-2021/AOC-15/input.txt create mode 100644 Advent-of-Code-2021/AOC-15/input.txt~ create mode 100644 Advent-of-Code-2021/AOC-15/sample.txt create mode 100644 Advent-of-Code-2021/AOC-15/sample.txt~ create mode 100755 Advent-of-Code-2021/AOC-2/aoc-2 create mode 100644 Advent-of-Code-2021/AOC-2/aoc-2.c create mode 100644 Advent-of-Code-2021/AOC-2/aoc-2.c~ create mode 100644 Advent-of-Code-2021/AOC-2/input-2.txt create mode 100644 Advent-of-Code-2021/AOC-2/input-2.txt~ create mode 100755 Advent-of-Code-2021/AOC-25/aoc-25 create mode 100644 Advent-of-Code-2021/AOC-25/aoc-25.c create mode 100644 Advent-of-Code-2021/AOC-25/aoc-25.c~ create mode 100644 Advent-of-Code-2021/AOC-25/input.txt create mode 100644 Advent-of-Code-2021/AOC-25/input.txt~ create mode 100644 Advent-of-Code-2021/AOC-25/sample.txt create mode 100755 Advent-of-Code-2021/AOC-3/aoc-3 create mode 100644 Advent-of-Code-2021/AOC-3/aoc-3.c create mode 100644 Advent-of-Code-2021/AOC-3/aoc-3.c~ create mode 100644 Advent-of-Code-2021/AOC-3/input.txt create mode 100644 Advent-of-Code-2021/AOC-3/input.txt~ create mode 100644 Advent-of-Code-2021/AOC-3/sample.txt create mode 100644 Advent-of-Code-2021/AOC-3/sample.txt~ create mode 100755 Advent-of-Code-2021/AOC-5/build.sh create mode 100644 Advent-of-Code-2021/AOC-5/example.txt create mode 100644 Advent-of-Code-2021/AOC-5/input.txt create mode 100755 Advent-of-Code-2021/AOC-5/main create mode 100644 Advent-of-Code-2021/AOC-5/main.c create mode 100755 Advent-of-Code-2021/AOC-6/aoc-6 create mode 100644 Advent-of-Code-2021/AOC-6/aoc-6.c create mode 100644 Advent-of-Code-2021/AOC-6/aoc-6.c~ create mode 100755 Advent-of-Code-2021/AOC-7/aoc-7 create mode 100644 Advent-of-Code-2021/AOC-7/aoc-7.c create mode 100644 Advent-of-Code-2021/AOC-7/input.txt create mode 100644 Advent-of-Code-2021/AOC-7/sample.txt (limited to 'Advent-of-Code-2021') diff --git a/Advent-of-Code-2021/AOC-1/aoc-1 b/Advent-of-Code-2021/AOC-1/aoc-1 new file mode 100755 index 0000000..eb5fe13 Binary files /dev/null and b/Advent-of-Code-2021/AOC-1/aoc-1 differ 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 +#include +#include + +#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 numbers[(i-1)]) + bigger += 1; + } + + printf("Answer: %d", bigger); + */ + + // Part Two + int bigger = 0; + for(int i = 3; 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 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 new file mode 100755 index 0000000..72ff31b Binary files /dev/null and b/Advent-of-Code-2021/AOC-11/main differ 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 +#include + +#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 new file mode 100755 index 0000000..62869db Binary files /dev/null and b/Advent-of-Code-2021/AOC-13/main differ 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 +#include +#include +#include + +#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 new file mode 100755 index 0000000..630caae Binary files /dev/null and b/Advent-of-Code-2021/AOC-14/aoc-14 differ 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 +#include +#include +#include + +#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 new file mode 100755 index 0000000..3fa17a1 Binary files /dev/null and b/Advent-of-Code-2021/AOC-15/aoc-15 differ 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 +#include +#include + +#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 +#include +#include + +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 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 diff --git a/Advent-of-Code-2021/AOC-25/aoc-25 b/Advent-of-Code-2021/AOC-25/aoc-25 new file mode 100755 index 0000000..1528c81 Binary files /dev/null and b/Advent-of-Code-2021/AOC-25/aoc-25 differ 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 +#include +#include +#include +#include +#include + +#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') + { + 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', positions_east[i]); +} + +void MoveSouth() +{ + Sea_cuc_move positions_south[5000]; + int cucs_south = 0; + + for(int i=0; i +#include +#include +#include +#include +#include + +#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') + { + 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', positions_east[i]); +} + +void MoveSouth() +{ + Sea_cuc_move positions_south[5000]; + int cucs_south = 0; + + for(int i=0; i.>.>.>>>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 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 diff --git a/Advent-of-Code-2021/AOC-3/aoc-3 b/Advent-of-Code-2021/AOC-3/aoc-3 new file mode 100755 index 0000000..d163e8c Binary files /dev/null and b/Advent-of-Code-2021/AOC-3/aoc-3 differ 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 +#include +#include +#include +#include + +#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 (INP_COUNT/2)) + { + gamma_val = gamma_val | (1 << (N-1-i)); + } + } + + int epsilon_val = gamma_val; + for(int i=0; i +#include +#include +#include +#include + +#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 (INP_COUNT/2)) + { + gamma_val = gamma_val | (1 << (N-1-i)); + } + } + + int epsilon_val = gamma_val; + for(int i=0; i 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 new file mode 100755 index 0000000..c4629f0 Binary files /dev/null and b/Advent-of-Code-2021/AOC-5/main differ 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 +#include +#include +#include + +#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 new file mode 100755 index 0000000..9fe1541 Binary files /dev/null and b/Advent-of-Code-2021/AOC-6/aoc-6 differ 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 +#include +#include +#include +#include + +#define N 9 +#define MAXDAYS 256 + +u_int64_t table[N]; +u_int64_t temp_table[N]; + +void PrintTable() +{ + for(int i=0; i +#include +#include +#include + +#define N 9 +#define MAXDAYS 80 + +int table[N]; + +void PrintTable() +{ + for(int i=0; i +#include +#include + +#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, -- cgit v1.2.3