advent2021

Advent of Code 2021 Solutions
git clone git://bsandro.tech/advent2021
Log | Files | Refs

commit d195f90ecad9292e26c8bf2249b52606ad06b87e
Author: bsandro <[email protected]>
Date:   Wed,  1 Dec 2021 15:37:43 +0000

Day 01, puzzle 1.

Diffstat:
Aday01/Makefile | 23+++++++++++++++++++++++
Aday01/input.txt | 2000+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aday01/main.c | 39+++++++++++++++++++++++++++++++++++++++
3 files changed, 2062 insertions(+), 0 deletions(-)

diff --git a/day01/Makefile b/day01/Makefile @@ -0,0 +1,23 @@ +NAME!=basename ${PWD} +CC=cc +SRC!=ls *.c +DEPS!=find . -type f -name "*.h" -maxdepth 1 +OBJ:=${SRC:.c=.o} + +CFLAGS=-O0 -std=c99 -g -Werror -Wall -Wextra -I. + +all: ${NAME} + +.PHONY: clean run + +clean: + @rm -f ${OBJ} ${NAME} + +$(OBJ): ${SRC} ${DEPS} + @${CC} ${CFLAGS} -c $< -o $@ + +${NAME}: ${OBJ} + @${CC} ${OBJ} -o $@ ${LDFLAGS} + +run: ${NAME} + @./${NAME} input.txt diff --git a/day01/input.txt b/day01/input.txt @@ -0,0 +1,2000 @@ +118 +121 +123 +125 +134 +132 +137 +135 +136 +137 +138 +139 +163 +170 +171 +159 +161 +162 +156 +155 +151 +168 +172 +166 +159 +180 +187 +172 +161 +162 +161 +183 +182 +185 +175 +173 +174 +177 +192 +191 +190 +219 +225 +226 +216 +226 +230 +234 +236 +244 +235 +245 +266 +299 +300 +281 +291 +309 +303 +333 +332 +309 +312 +313 +314 +315 +339 +351 +353 +352 +338 +343 +337 +346 +338 +335 +332 +329 +345 +347 +332 +339 +354 +373 +376 +397 +400 +401 +433 +434 +440 +434 +438 +443 +448 +452 +456 +450 +459 +463 +464 +488 +492 +488 +506 +507 +516 +523 +524 +522 +546 +551 +553 +554 +553 +562 +559 +567 +569 +556 +557 +577 +581 +582 +591 +593 +594 +595 +598 +602 +611 +623 +604 +613 +603 +607 +612 +616 +612 +613 +612 +598 +607 +622 +619 +636 +638 +639 +637 +659 +657 +677 +678 +679 +655 +651 +655 +654 +662 +666 +672 +673 +676 +683 +684 +693 +688 +691 +698 +702 +704 +706 +707 +710 +709 +725 +731 +729 +767 +779 +780 +807 +806 +808 +815 +812 +811 +819 +820 +821 +822 +826 +812 +810 +820 +817 +803 +808 +826 +831 +837 +842 +839 +840 +827 +838 +840 +841 +842 +848 +841 +838 +839 +838 +839 +841 +821 +812 +813 +796 +817 +820 +845 +854 +857 +858 +866 +869 +870 +881 +882 +888 +889 +891 +886 +891 +901 +930 +940 +944 +943 +958 +952 +916 +903 +905 +907 +910 +915 +907 +906 +907 +919 +921 +923 +925 +924 +929 +931 +936 +937 +935 +953 +962 +968 +980 +981 +1003 +1005 +1006 +1011 +1013 +1014 +1015 +1016 +1015 +995 +1002 +1018 +1020 +1031 +1043 +1038 +1039 +1040 +1041 +1043 +1037 +1041 +1050 +1052 +1048 +1049 +1050 +1053 +1057 +1064 +1067 +1068 +1078 +1086 +1098 +1103 +1119 +1138 +1114 +1115 +1129 +1130 +1143 +1138 +1141 +1150 +1153 +1146 +1155 +1157 +1145 +1146 +1147 +1145 +1144 +1158 +1163 +1167 +1171 +1174 +1176 +1188 +1207 +1205 +1208 +1212 +1216 +1222 +1231 +1233 +1249 +1253 +1269 +1231 +1235 +1242 +1241 +1246 +1247 +1263 +1266 +1259 +1260 +1279 +1280 +1281 +1285 +1284 +1285 +1296 +1300 +1302 +1319 +1312 +1313 +1325 +1342 +1344 +1361 +1349 +1363 +1367 +1366 +1346 +1347 +1369 +1385 +1386 +1397 +1401 +1402 +1396 +1397 +1400 +1395 +1400 +1411 +1419 +1427 +1446 +1445 +1459 +1460 +1464 +1472 +1482 +1474 +1475 +1476 +1481 +1484 +1487 +1494 +1497 +1494 +1495 +1498 +1501 +1511 +1521 +1528 +1533 +1535 +1544 +1518 +1521 +1509 +1533 +1537 +1540 +1545 +1546 +1544 +1564 +1553 +1576 +1577 +1563 +1560 +1564 +1569 +1570 +1571 +1573 +1576 +1573 +1596 +1597 +1593 +1597 +1596 +1592 +1597 +1578 +1555 +1576 +1584 +1585 +1584 +1594 +1598 +1608 +1613 +1614 +1606 +1608 +1621 +1648 +1614 +1615 +1606 +1609 +1610 +1625 +1638 +1640 +1617 +1655 +1661 +1644 +1648 +1649 +1653 +1675 +1674 +1681 +1679 +1682 +1683 +1695 +1696 +1699 +1700 +1701 +1704 +1709 +1729 +1732 +1739 +1742 +1746 +1748 +1746 +1753 +1744 +1752 +1749 +1750 +1758 +1762 +1767 +1771 +1772 +1761 +1763 +1784 +1804 +1809 +1792 +1787 +1806 +1809 +1815 +1817 +1828 +1821 +1824 +1823 +1824 +1841 +1840 +1833 +1840 +1842 +1863 +1862 +1865 +1866 +1868 +1878 +1887 +1897 +1905 +1906 +1913 +1908 +1915 +1930 +1928 +1922 +1925 +1927 +1928 +1939 +1938 +1946 +1947 +1954 +1955 +1959 +1961 +1951 +1945 +1949 +1954 +1959 +1961 +1962 +1964 +1960 +1956 +1958 +1975 +1990 +1994 +2002 +2004 +2011 +2010 +2020 +2042 +2043 +2046 +2047 +2044 +2048 +2065 +2074 +2075 +2086 +2088 +2094 +2098 +2092 +2083 +2082 +2084 +2094 +2097 +2099 +2098 +2101 +2104 +2112 +2118 +2105 +2108 +2109 +2104 +2105 +2103 +2114 +2144 +2138 +2139 +2142 +2114 +2120 +2139 +2147 +2153 +2190 +2191 +2197 +2193 +2206 +2216 +2225 +2230 +2232 +2258 +2264 +2236 +2264 +2289 +2306 +2307 +2315 +2319 +2322 +2277 +2279 +2271 +2279 +2285 +2290 +2297 +2316 +2317 +2320 +2329 +2330 +2323 +2326 +2327 +2331 +2336 +2341 +2348 +2352 +2386 +2396 +2401 +2400 +2401 +2418 +2419 +2429 +2432 +2430 +2428 +2406 +2401 +2434 +2435 +2443 +2463 +2478 +2479 +2481 +2482 +2486 +2490 +2491 +2492 +2496 +2497 +2499 +2507 +2525 +2522 +2523 +2522 +2521 +2526 +2531 +2530 +2525 +2526 +2537 +2533 +2534 +2542 +2544 +2531 +2539 +2546 +2550 +2551 +2553 +2554 +2552 +2562 +2566 +2551 +2583 +2587 +2601 +2605 +2604 +2610 +2628 +2639 +2641 +2654 +2657 +2676 +2672 +2686 +2694 +2677 +2693 +2694 +2707 +2696 +2710 +2753 +2752 +2722 +2723 +2724 +2741 +2746 +2753 +2763 +2764 +2805 +2806 +2810 +2811 +2823 +2854 +2855 +2852 +2872 +2873 +2867 +2876 +2881 +2885 +2899 +2900 +2901 +2903 +2918 +2912 +2924 +2915 +2920 +2932 +2942 +2943 +2934 +2953 +2960 +2956 +2957 +2959 +2982 +2991 +3016 +3018 +3047 +3032 +3048 +3051 +3056 +3063 +3064 +3063 +3065 +3066 +3070 +3075 +3069 +3075 +3073 +3074 +3083 +3086 +3097 +3093 +3082 +3077 +3098 +3105 +3128 +3144 +3148 +3174 +3173 +3172 +3171 +3169 +3176 +3180 +3166 +3165 +3182 +3183 +3206 +3207 +3208 +3211 +3215 +3214 +3220 +3233 +3234 +3248 +3249 +3252 +3253 +3254 +3256 +3258 +3266 +3265 +3266 +3274 +3291 +3275 +3291 +3294 +3299 +3292 +3293 +3306 +3292 +3291 +3290 +3291 +3295 +3296 +3288 +3294 +3305 +3308 +3315 +3319 +3327 +3332 +3334 +3332 +3342 +3346 +3347 +3348 +3360 +3370 +3371 +3373 +3379 +3387 +3386 +3389 +3393 +3398 +3405 +3406 +3413 +3417 +3431 +3433 +3434 +3438 +3442 +3443 +3445 +3446 +3447 +3448 +3454 +3439 +3450 +3451 +3453 +3452 +3455 +3462 +3466 +3475 +3479 +3476 +3479 +3480 +3484 +3486 +3489 +3491 +3505 +3506 +3510 +3513 +3530 +3532 +3537 +3540 +3542 +3553 +3558 +3570 +3569 +3570 +3569 +3570 +3565 +3559 +3561 +3556 +3557 +3575 +3585 +3590 +3592 +3593 +3602 +3619 +3623 +3624 +3669 +3671 +3672 +3683 +3686 +3699 +3708 +3709 +3714 +3713 +3718 +3719 +3742 +3729 +3730 +3731 +3729 +3727 +3741 +3742 +3741 +3742 +3734 +3740 +3744 +3734 +3737 +3738 +3739 +3759 +3760 +3761 +3750 +3751 +3753 +3745 +3744 +3731 +3733 +3725 +3750 +3757 +3767 +3768 +3774 +3777 +3791 +3815 +3816 +3817 +3819 +3820 +3825 +3835 +3836 +3858 +3861 +3860 +3844 +3846 +3847 +3877 +3906 +3910 +3912 +3940 +3941 +3975 +3980 +3983 +3987 +4016 +4028 +4047 +4066 +4061 +4058 +4061 +4066 +4088 +4089 +4092 +4098 +4105 +4110 +4111 +4103 +4108 +4082 +4087 +4086 +4087 +4082 +4083 +4084 +4104 +4110 +4111 +4119 +4128 +4133 +4113 +4129 +4128 +4129 +4121 +4123 +4126 +4132 +4133 +4143 +4149 +4148 +4147 +4145 +4142 +4143 +4146 +4138 +4139 +4141 +4147 +4148 +4160 +4156 +4162 +4173 +4179 +4181 +4190 +4191 +4190 +4191 +4192 +4193 +4194 +4208 +4211 +4215 +4226 +4223 +4227 +4230 +4250 +4248 +4267 +4260 +4274 +4275 +4278 +4291 +4298 +4304 +4314 +4315 +4317 +4319 +4325 +4326 +4327 +4349 +4345 +4356 +4360 +4365 +4366 +4370 +4385 +4384 +4386 +4399 +4423 +4397 +4410 +4409 +4388 +4393 +4397 +4402 +4403 +4418 +4413 +4418 +4417 +4418 +4422 +4411 +4374 +4403 +4412 +4427 +4445 +4449 +4453 +4458 +4459 +4465 +4447 +4448 +4450 +4460 +4464 +4465 +4467 +4472 +4486 +4484 +4482 +4507 +4512 +4525 +4524 +4525 +4527 +4522 +4521 +4524 +4550 +4551 +4552 +4550 +4554 +4555 +4586 +4578 +4582 +4594 +4588 +4592 +4595 +4598 +4599 +4614 +4615 +4623 +4632 +4633 +4655 +4661 +4662 +4690 +4689 +4690 +4694 +4704 +4705 +4694 +4697 +4702 +4703 +4704 +4703 +4709 +4714 +4722 +4728 +4741 +4761 +4767 +4768 +4770 +4775 +4778 +4770 +4788 +4789 +4802 +4805 +4808 +4811 +4819 +4812 +4813 +4821 +4838 +4839 +4843 +4817 +4821 +4824 +4820 +4843 +4845 +4849 +4852 +4872 +4873 +4870 +4885 +4902 +4920 +4921 +4923 +4936 +4930 +4932 +4933 +4931 +4949 +4974 +4976 +4977 +4978 +4990 +4991 +5001 +5002 +5001 +5027 +5026 +5021 +5054 +5055 +5056 +5059 +5064 +5065 +5074 +5081 +5093 +5095 +5100 +5113 +5125 +5126 +5137 +5142 +5123 +5118 +5117 +5118 +5125 +5135 +5142 +5154 +5165 +5158 +5146 +5148 +5149 +5163 +5176 +5177 +5169 +5171 +5168 +5186 +5191 +5196 +5197 +5224 +5226 +5224 +5215 +5213 +5214 +5198 +5201 +5202 +5213 +5214 +5216 +5251 +5255 +5259 +5262 +5259 +5261 +5264 +5273 +5281 +5254 +5265 +5280 +5289 +5294 +5298 +5309 +5310 +5298 +5297 +5306 +5311 +5301 +5306 +5289 +5287 +5300 +5299 +5301 +5308 +5314 +5323 +5329 +5330 +5324 +5325 +5332 +5335 +5332 +5333 +5334 +5337 +5345 +5351 +5355 +5364 +5366 +5382 +5391 +5408 +5400 +5402 +5405 +5390 +5391 +5394 +5407 +5409 +5410 +5411 +5412 +5416 +5412 +5424 +5426 +5425 +5426 +5434 +5421 +5433 +5440 +5441 +5435 +5424 +5417 +5413 +5414 +5415 +5418 +5420 +5421 +5444 +5442 +5433 +5435 +5436 +5437 +5407 +5406 +5424 +5427 +5433 +5434 +5438 +5441 +5443 +5444 +5445 +5446 +5453 +5464 +5465 +5478 +5474 +5462 +5463 +5491 +5498 +5499 +5500 +5501 +5504 +5506 +5530 +5524 +5517 +5521 +5530 +5532 +5538 +5544 +5541 +5554 +5556 +5553 +5554 +5556 +5562 +5563 +5568 +5572 +5584 +5581 +5584 +5582 +5586 +5588 +5599 +5602 +5603 +5601 +5610 +5607 +5602 +5604 +5600 +5602 +5605 +5606 +5608 +5606 +5610 +5619 +5620 +5619 +5623 +5624 +5626 +5627 +5628 +5630 +5637 +5650 +5674 +5677 +5661 +5669 +5675 +5676 +5681 +5685 +5687 +5709 +5713 +5714 +5724 +5728 +5729 +5727 +5741 +5755 +5741 +5730 +5724 +5727 +5726 +5730 +5731 +5732 +5734 +5733 +5734 +5735 +5736 +5737 +5736 +5730 +5732 +5742 +5744 +5747 +5755 +5760 +5755 +5757 +5768 +5793 +5798 +5799 +5805 +5808 +5810 +5812 +5814 +5815 +5817 +5850 +5851 +5839 +5860 +5870 +5871 +5879 +5886 +5897 +5904 +5908 +5907 +5911 +5910 +5914 +5916 +5917 +5919 +5917 +5928 +5930 +5931 +5932 +5941 +5944 +5946 +5951 +5931 +5905 +5930 +5936 +5937 +5935 +5936 +5942 +5944 +5951 +5916 +5899 +5892 +5891 +5902 +5907 +5951 +5952 +5957 +5958 +5961 +5965 +5969 +5974 +5975 +5953 +5956 +5965 +5985 +5987 +6017 +6016 +6017 +5990 +5991 +5999 +5993 +5995 +6016 +6017 +6014 +6049 +6042 +6053 +6055 +6068 +6069 +6074 +6072 +6079 +6074 +6076 +6066 +6065 +6067 +6098 +6104 +6116 +6115 +6113 +6099 +6100 +6101 +6100 +6111 +6115 +6140 +6106 +6107 +6117 +6131 +6135 +6144 +6118 +6113 +6118 +6128 +6129 +6135 +6138 +6143 +6144 +6142 +6144 +6145 +6144 +6147 +6151 +6149 +6150 +6151 +6135 +6136 +6132 +6118 +6113 +6120 +6117 +6118 +6122 +6125 +6126 +6124 +6131 +6132 +6135 +6136 +6154 +6160 +6167 +6179 +6181 +6186 +6196 +6225 +6228 +6232 +6221 +6238 +6249 +6252 +6254 +6256 +6260 +6269 +6271 +6263 +6272 +6271 +6272 +6271 +6285 +6308 +6319 +6327 +6334 +6337 +6356 +6385 +6380 +6387 +6395 +6396 +6392 +6395 +6398 +6400 +6401 +6396 +6399 +6400 +6380 +6379 +6380 +6377 +6397 +6398 +6396 +6415 +6419 +6438 +6449 +6465 +6459 +6461 +6463 +6466 +6492 +6493 +6502 +6501 +6503 +6510 +6511 +6512 +6505 +6506 +6508 +6525 +6523 +6530 +6536 +6535 +6539 +6544 +6545 +6534 +6532 +6537 +6542 +6543 +6544 +6545 +6559 +6560 +6577 +6578 +6580 +6581 +6582 +6591 +6597 +6581 +6595 +6608 +6620 +6624 +6632 +6636 +6639 +6637 +6645 +6648 +6650 +6651 +6645 +6648 +6661 +6658 +6659 +6668 +6667 +6666 +6684 +6700 +6701 +6730 +6736 +6746 +6749 +6750 +6751 +6741 +6728 +6729 +6762 +6763 +6792 +6795 +6796 +6813 +6827 +6835 +6843 +6844 +6852 +6854 +6856 +6868 +6870 +6876 +6874 +6865 +6870 +6867 +6870 +6877 +6887 +6881 +6869 +6871 +6874 +6875 +6876 +6902 +6903 +6901 +6902 +6912 +6913 +6912 +6913 +6927 +6928 +6935 +6936 +6942 +6943 +6942 +6943 +6953 +6954 +6961 +6989 +6992 +6993 +6997 +7018 +7022 +7041 +7052 +7055 +7058 +7049 +7050 +7051 +7047 +7064 +7059 +7074 +7082 +7083 +7097 +7102 +7092 +7094 +7101 +7143 +7165 +7176 +7178 +7183 +7180 +7203 +7204 +7207 +7211 +7217 +7220 +7212 +7215 +7217 +7223 +7207 +7214 +7213 +7215 +7214 +7212 +7219 +7226 +7225 +7230 +7239 +7240 +7241 +7248 +7247 +7254 +7258 +7262 +7280 +7298 +7297 +7307 +7308 +7316 +7314 +7339 +7340 +7359 +7356 +7383 +7382 +7385 +7397 +7399 +7410 +7437 +7440 +7439 +7457 +7455 +7462 +7463 +7464 +7465 +7477 +7478 +7494 +7500 +7507 +7512 +7547 +7558 +7559 +7571 +7572 +7575 +7608 +7633 +7636 +7629 +7628 +7633 +7635 +7641 +7659 +7663 +7677 +7694 +7708 +7701 +7697 +7682 +7684 +7675 +7664 +7672 +7675 +7669 +7671 +7672 +7684 +7688 +7701 +7712 +7741 +7727 +7733 +7735 +7736 +7737 +7744 +7748 +7749 +7750 +7736 +7737 +7752 +7755 +7756 +7757 +7791 +7790 +7785 +7791 +7812 +7825 +7816 +7819 +7824 +7829 +7855 +7846 +7854 +7827 +7831 +7835 +7836 +7845 +7848 +7861 +7862 +7864 +7847 +7858 +7877 +7878 +7888 +7885 +7881 +7878 +7883 +7884 +7882 +7883 +7901 +7916 +7922 +7909 +7915 +7929 +7942 +7953 +7954 +7951 +7967 +7963 diff --git a/day01/main.c b/day01/main.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> + +int main(int argc, char *argv[]) { + printf("advent of code day 01\n"); + if (argc <= 1) { + printf("Usage: %s inputfile.txt\n", argv[0]); + return 0; + } + + FILE *infile = fopen(argv[1], "r"); + if (infile == NULL) { + printf("fopen() error: %s\n", strerror(errno)); + return -1; + } + + char *buf = NULL; + size_t len = 0; + int prev_depth = -1; + int counter = 0; + while ((buf = fgetln(infile, &len)) != NULL) { + if (len == 0) { + break; + } + int depth = atoi(buf); + if (prev_depth > -1 && depth > prev_depth) { + ++counter; + } + prev_depth = depth; + } + + printf("1: %d\n", counter); + + fclose(infile); + + return 0; +}