diff --git a/.gitignore b/.gitignore index 7c6571e..a2246dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ venv *.pyc +target/ diff --git a/2021/01/example b/2021/01/example new file mode 100644 index 0000000..167e291 --- /dev/null +++ b/2021/01/example @@ -0,0 +1,10 @@ +199 +200 +208 +210 +200 +207 +240 +269 +260 +263 diff --git a/2021/01/input b/2021/01/input new file mode 100644 index 0000000..fd426dc --- /dev/null +++ b/2021/01/input @@ -0,0 +1,2000 @@ +188 +192 +193 +194 +192 +213 +214 +216 +219 +221 +222 +228 +231 +234 +239 +240 +252 +262 +267 +279 +278 +277 +279 +293 +309 +310 +312 +307 +308 +316 +320 +323 +335 +336 +343 +368 +357 +370 +377 +386 +387 +386 +402 +379 +393 +394 +403 +404 +405 +400 +421 +422 +423 +408 +409 +411 +408 +415 +417 +430 +439 +432 +459 +462 +463 +464 +466 +472 +485 +473 +488 +491 +492 +493 +496 +497 +501 +503 +516 +514 +513 +514 +517 +521 +522 +526 +548 +553 +560 +563 +565 +600 +601 +595 +596 +597 +599 +613 +630 +631 +635 +642 +648 +651 +654 +645 +653 +657 +676 +688 +711 +717 +718 +728 +735 +730 +733 +734 +737 +736 +738 +741 +749 +751 +752 +762 +765 +776 +779 +758 +743 +754 +759 +772 +773 +783 +790 +791 +783 +781 +784 +785 +791 +780 +789 +805 +792 +793 +797 +825 +828 +820 +817 +820 +821 +824 +825 +801 +815 +816 +829 +844 +845 +850 +853 +845 +841 +842 +844 +830 +844 +839 +842 +857 +859 +861 +871 +880 +881 +903 +935 +960 +964 +967 +969 +972 +990 +996 +999 +1003 +1008 +1034 +1038 +1039 +1053 +1054 +1055 +1061 +1065 +1066 +1061 +1064 +1073 +1078 +1084 +1087 +1106 +1113 +1118 +1128 +1132 +1133 +1126 +1127 +1134 +1150 +1153 +1162 +1176 +1186 +1187 +1215 +1218 +1221 +1224 +1225 +1232 +1234 +1241 +1247 +1248 +1251 +1250 +1252 +1247 +1249 +1251 +1252 +1253 +1260 +1263 +1269 +1270 +1277 +1287 +1262 +1275 +1276 +1281 +1282 +1285 +1284 +1296 +1304 +1310 +1307 +1308 +1285 +1286 +1293 +1298 +1303 +1309 +1312 +1315 +1317 +1325 +1335 +1338 +1343 +1346 +1348 +1360 +1366 +1367 +1371 +1384 +1396 +1400 +1407 +1425 +1424 +1427 +1433 +1446 +1449 +1466 +1469 +1495 +1507 +1508 +1509 +1521 +1514 +1519 +1533 +1534 +1538 +1539 +1541 +1551 +1561 +1569 +1570 +1582 +1583 +1593 +1599 +1607 +1608 +1614 +1618 +1633 +1638 +1646 +1652 +1653 +1680 +1682 +1689 +1700 +1702 +1700 +1706 +1709 +1710 +1712 +1718 +1710 +1711 +1736 +1727 +1729 +1758 +1762 +1780 +1794 +1811 +1813 +1817 +1818 +1826 +1829 +1830 +1811 +1817 +1818 +1820 +1821 +1822 +1824 +1825 +1838 +1840 +1841 +1844 +1846 +1849 +1875 +1878 +1879 +1881 +1908 +1917 +1923 +1918 +1930 +1921 +1926 +1927 +1929 +1940 +1941 +1946 +1949 +1951 +1960 +1964 +1965 +1971 +1975 +1979 +1984 +1986 +1985 +2010 +2005 +2006 +2010 +2011 +2012 +2013 +2029 +2031 +2036 +2039 +2045 +2027 +2035 +2014 +2017 +2031 +2033 +2037 +2040 +2044 +2050 +2051 +2049 +2052 +2053 +2068 +2069 +2071 +2073 +2074 +2075 +2086 +2089 +2091 +2092 +2093 +2094 +2095 +2096 +2097 +2100 +2106 +2107 +2108 +2122 +2094 +2095 +2121 +2131 +2132 +2135 +2162 +2177 +2178 +2180 +2199 +2210 +2211 +2213 +2217 +2229 +2255 +2259 +2266 +2268 +2266 +2272 +2278 +2295 +2296 +2294 +2298 +2303 +2309 +2310 +2311 +2312 +2310 +2315 +2316 +2332 +2335 +2337 +2339 +2342 +2343 +2362 +2371 +2373 +2375 +2381 +2380 +2382 +2396 +2398 +2405 +2406 +2403 +2405 +2413 +2418 +2423 +2440 +2443 +2442 +2434 +2436 +2444 +2450 +2456 +2485 +2486 +2487 +2491 +2489 +2490 +2491 +2513 +2509 +2511 +2525 +2526 +2535 +2548 +2551 +2557 +2559 +2560 +2568 +2565 +2591 +2607 +2614 +2615 +2616 +2630 +2665 +2677 +2680 +2679 +2686 +2687 +2692 +2687 +2689 +2690 +2694 +2692 +2693 +2694 +2695 +2696 +2698 +2720 +2743 +2744 +2752 +2777 +2780 +2778 +2786 +2800 +2807 +2808 +2810 +2817 +2823 +2835 +2840 +2848 +2850 +2855 +2856 +2861 +2864 +2890 +2892 +2894 +2905 +2906 +2907 +2918 +2922 +2927 +2928 +2918 +2933 +2934 +2936 +2939 +2947 +2944 +2932 +2938 +2941 +2954 +2957 +2965 +2970 +2971 +2972 +2981 +2984 +2994 +3006 +3028 +3020 +3023 +3026 +3021 +3024 +3016 +3041 +3042 +3053 +3055 +3056 +3057 +3060 +3061 +3062 +3069 +3070 +3097 +3104 +3107 +3110 +3112 +3114 +3115 +3122 +3120 +3121 +3142 +3143 +3167 +3169 +3170 +3172 +3180 +3182 +3181 +3182 +3183 +3184 +3185 +3186 +3201 +3181 +3185 +3187 +3166 +3162 +3164 +3167 +3168 +3180 +3189 +3190 +3191 +3189 +3191 +3196 +3213 +3224 +3229 +3233 +3232 +3245 +3279 +3302 +3313 +3316 +3333 +3334 +3337 +3339 +3348 +3364 +3365 +3375 +3380 +3381 +3382 +3402 +3418 +3433 +3438 +3439 +3453 +3482 +3484 +3488 +3497 +3511 +3500 +3502 +3497 +3502 +3505 +3516 +3517 +3519 +3525 +3520 +3524 +3528 +3533 +3548 +3552 +3555 +3562 +3573 +3577 +3579 +3587 +3592 +3620 +3615 +3616 +3619 +3620 +3631 +3630 +3640 +3674 +3675 +3684 +3685 +3699 +3701 +3694 +3727 +3746 +3749 +3742 +3745 +3748 +3756 +3759 +3746 +3759 +3762 +3763 +3748 +3762 +3760 +3766 +3770 +3774 +3776 +3778 +3785 +3787 +3788 +3815 +3816 +3822 +3832 +3831 +3832 +3835 +3834 +3820 +3822 +3823 +3825 +3826 +3831 +3833 +3843 +3864 +3889 +3895 +3903 +3908 +3910 +3909 +3911 +3912 +3913 +3921 +3948 +3949 +3954 +3955 +3958 +3960 +3962 +3963 +3975 +3986 +3989 +3990 +3992 +4006 +4012 +4032 +4036 +4037 +4038 +4041 +4048 +4056 +4041 +4044 +4048 +4077 +4076 +4088 +4072 +4073 +4075 +4080 +4075 +4080 +4081 +4110 +4139 +4142 +4143 +4145 +4148 +4155 +4157 +4163 +4164 +4174 +4181 +4186 +4193 +4195 +4198 +4197 +4202 +4209 +4208 +4211 +4213 +4211 +4223 +4222 +4224 +4232 +4234 +4239 +4243 +4245 +4247 +4248 +4252 +4245 +4253 +4289 +4288 +4290 +4292 +4294 +4295 +4298 +4308 +4314 +4315 +4320 +4328 +4326 +4328 +4334 +4330 +4339 +4362 +4363 +4364 +4365 +4366 +4375 +4388 +4389 +4395 +4382 +4393 +4385 +4381 +4380 +4391 +4392 +4409 +4410 +4414 +4434 +4445 +4452 +4457 +4453 +4461 +4469 +4468 +4487 +4482 +4505 +4512 +4513 +4517 +4535 +4542 +4544 +4546 +4559 +4560 +4575 +4576 +4578 +4579 +4580 +4581 +4582 +4585 +4589 +4588 +4592 +4593 +4594 +4620 +4621 +4632 +4633 +4634 +4640 +4641 +4643 +4651 +4666 +4672 +4673 +4672 +4674 +4695 +4697 +4707 +4706 +4708 +4709 +4705 +4702 +4694 +4732 +4734 +4735 +4723 +4728 +4734 +4752 +4754 +4756 +4759 +4768 +4770 +4773 +4780 +4781 +4783 +4792 +4797 +4806 +4825 +4833 +4839 +4838 +4842 +4843 +4853 +4851 +4852 +4853 +4834 +4835 +4836 +4837 +4838 +4837 +4833 +4843 +4844 +4825 +4826 +4832 +4833 +4832 +4840 +4844 +4838 +4839 +4862 +4867 +4868 +4873 +4877 +4881 +4888 +4891 +4896 +4911 +4910 +4911 +4906 +4913 +4915 +4918 +4926 +4933 +4968 +4969 +4970 +4974 +4978 +4979 +5002 +5008 +5010 +5034 +5040 +5034 +5035 +5046 +5042 +5044 +5060 +5063 +5068 +5069 +5078 +5079 +5080 +5081 +5080 +5066 +5081 +5105 +5113 +5122 +5125 +5129 +5144 +5136 +5101 +5102 +5104 +5106 +5107 +5109 +5114 +5116 +5112 +5116 +5114 +5118 +5121 +5127 +5138 +5125 +5133 +5127 +5140 +5142 +5143 +5144 +5150 +5154 +5155 +5156 +5177 +5180 +5182 +5170 +5171 +5159 +5165 +5166 +5173 +5172 +5186 +5195 +5200 +5201 +5229 +5231 +5233 +5234 +5258 +5268 +5278 +5279 +5284 +5288 +5285 +5292 +5319 +5323 +5325 +5332 +5343 +5366 +5368 +5367 +5370 +5377 +5394 +5395 +5394 +5398 +5399 +5405 +5407 +5415 +5416 +5422 +5423 +5424 +5442 +5446 +5447 +5448 +5454 +5455 +5456 +5457 +5473 +5475 +5474 +5475 +5486 +5506 +5489 +5526 +5527 +5529 +5532 +5533 +5548 +5549 +5552 +5541 +5548 +5567 +5577 +5578 +5577 +5592 +5598 +5602 +5609 +5611 +5626 +5604 +5614 +5615 +5616 +5617 +5634 +5644 +5632 +5645 +5644 +5658 +5661 +5662 +5664 +5665 +5660 +5684 +5686 +5689 +5692 +5693 +5700 +5709 +5714 +5715 +5701 +5694 +5696 +5702 +5712 +5727 +5743 +5747 +5750 +5756 +5757 +5758 +5770 +5771 +5780 +5789 +5795 +5800 +5801 +5808 +5809 +5810 +5824 +5825 +5822 +5828 +5829 +5832 +5847 +5848 +5864 +5871 +5879 +5883 +5885 +5888 +5889 +5890 +5903 +5904 +5919 +5924 +5932 +5944 +5950 +5949 +5969 +5961 +5981 +5989 +5992 +5997 +5999 +6000 +6007 +6008 +6011 +6025 +6030 +6034 +6038 +6046 +6051 +6052 +6053 +6082 +6102 +6101 +6105 +6106 +6119 +6124 +6132 +6131 +6133 +6136 +6137 +6170 +6173 +6190 +6199 +6200 +6203 +6207 +6224 +6226 +6227 +6228 +6229 +6231 +6251 +6254 +6279 +6282 +6293 +6294 +6296 +6301 +6306 +6307 +6310 +6315 +6316 +6328 +6329 +6330 +6333 +6351 +6353 +6352 +6362 +6340 +6343 +6349 +6357 +6380 +6379 +6386 +6410 +6433 +6442 +6456 +6457 +6458 +6474 +6485 +6487 +6489 +6481 +6466 +6469 +6474 +6478 +6482 +6492 +6509 +6511 +6534 +6567 +6566 +6569 +6578 +6592 +6593 +6594 +6602 +6607 +6614 +6617 +6614 +6613 +6614 +6618 +6619 +6629 +6645 +6652 +6651 +6655 +6658 +6669 +6692 +6693 +6700 +6705 +6706 +6710 +6709 +6691 +6710 +6711 +6719 +6721 +6722 +6726 +6727 +6739 +6741 +6753 +6754 +6764 +6767 +6772 +6798 +6812 +6818 +6850 +6851 +6886 +6887 +6888 +6889 +6903 +6902 +6903 +6906 +6896 +6902 +6903 +6905 +6909 +6915 +6916 +6917 +6937 +6934 +6935 +6960 +6973 +6974 +6996 +6997 +7009 +7010 +7016 +7017 +7032 +7036 +7049 +7059 +7065 +7066 +7067 +7072 +7102 +7105 +7109 +7134 +7139 +7141 +7135 +7141 +7145 +7150 +7155 +7156 +7157 +7159 +7172 +7186 +7185 +7213 +7217 +7225 +7228 +7251 +7268 +7273 +7271 +7287 +7288 +7289 +7314 +7319 +7323 +7339 +7345 +7346 +7348 +7347 +7348 +7356 +7376 +7385 +7387 +7386 +7389 +7400 +7401 +7408 +7413 +7414 +7415 +7429 +7456 +7442 +7444 +7451 +7452 +7450 +7451 +7450 +7491 +7503 +7496 +7497 +7499 +7517 +7518 +7523 +7526 +7527 +7539 +7540 +7541 +7565 +7568 +7571 +7575 +7576 +7587 +7588 +7598 +7600 +7603 +7605 +7623 +7624 +7629 +7625 +7627 +7632 +7638 +7648 +7650 +7654 +7655 +7656 +7659 +7679 +7681 +7687 +7690 +7691 +7710 +7711 +7712 +7731 +7734 +7735 +7738 +7739 +7737 +7738 +7733 +7752 +7755 +7762 +7763 +7787 +7797 +7798 +7800 +7805 +7838 +7841 +7842 +7867 +7868 +7875 +7882 +7896 +7887 +7889 +7890 +7909 +7885 +7886 +7894 +7897 +7899 +7917 +7918 +7911 +7910 +7916 +7915 +7916 +7917 +7922 +7935 +7943 +7940 +7941 +7953 +7947 +7950 +7969 +7970 +7987 +7997 +8001 +7989 +7990 +7992 +7994 +7996 +7997 +8006 +8021 +8031 +8032 +8042 +8055 +8062 +8066 +8067 +8071 +8073 +8075 +8076 +8078 +8081 +8107 +8106 +8105 +8111 +8116 +8125 +8133 +8130 +8151 +8159 +8158 +8180 +8175 +8184 +8189 +8190 +8193 +8227 +8251 +8252 +8243 +8235 +8236 +8255 +8263 +8272 +8275 +8279 +8281 +8287 +8296 +8299 +8311 +8312 +8315 +8321 +8314 +8323 +8324 +8325 +8318 +8321 +8337 +8338 +8354 +8364 +8374 +8381 +8383 +8393 +8394 +8419 +8433 +8432 +8433 +8441 +8447 +8445 +8457 +8460 +8458 +8469 +8477 +8479 +8480 +8486 +8483 +8485 +8490 +8489 +8490 +8502 +8506 +8505 +8507 +8516 +8525 +8526 +8533 +8539 +8546 +8541 +8545 +8555 +8564 +8580 +8581 +8575 +8585 +8598 +8602 +8603 +8604 +8605 +8601 +8603 +8621 +8608 +8621 +8627 +8631 +8634 +8636 +8669 +8671 +8691 +8687 +8702 +8705 +8714 +8716 +8718 +8719 +8740 +8741 +8742 +8743 +8740 +8744 +8747 +8732 +8734 +8737 +8762 +8767 +8770 +8769 +8773 +8774 +8767 +8800 +8802 +8803 +8808 +8814 +8818 +8823 +8827 +8828 +8835 +8843 +8844 +8850 +8852 +8849 +8858 +8854 +8841 +8844 +8848 +8849 +8885 +8891 +8899 +8902 +8905 +8906 +8917 +8924 +8925 +8931 +8933 +8943 +8951 +8953 +8954 +8966 +8978 +8976 +8989 +8994 +8993 +9002 +9023 +9024 +9057 +9060 +9068 +9070 +9071 +9089 +9099 +9097 +9113 +9123 +9125 +9129 +9124 +9125 +9147 +9151 +9154 +9157 +9159 +9165 +9136 +9138 +9144 +9157 +9190 +9197 +9207 +9214 +9222 +9229 +9230 +9231 +9234 +9243 +9248 +9255 +9256 +9255 +9258 +9269 +9289 +9290 +9292 +9294 +9277 +9278 +9279 +9292 +9293 +9301 +9284 +9285 +9286 +9290 +9293 +9295 +9297 +9314 +9331 +9343 +9346 +9372 +9392 +9395 +9399 +9400 +9401 +9402 +9403 +9416 +9437 +9453 +9455 +9456 +9457 +9458 +9446 +9460 +9461 +9467 +9484 +9469 +9470 +9465 +9480 +9482 +9486 +9490 +9493 +9488 +9510 +9513 +9516 +9518 +9523 +9526 +9530 +9553 +9558 +9562 +9572 +9573 +9583 +9599 +9600 +9601 +9610 +9615 +9634 +9639 +9642 +9669 +9676 +9678 +9679 +9681 +9682 +9684 +9689 +9698 +9709 +9710 +9712 +9719 +9721 +9733 +9734 +9741 +9751 +9767 +9769 +9768 +9770 +9769 +9771 +9773 +9769 +9780 +9787 +9789 +9794 +9802 +9803 +9807 +9809 +9810 +9811 +9813 +9816 +9823 +9828 +9835 +9849 +9851 +9861 +9883 +9884 +9889 +9890 +9893 +9907 +9909 +9923 +9930 +9929 +9912 +9917 +9929 +9930 +9932 +9945 +9959 +9961 +9962 +9982 +9987 +9993 +9996 +9999 +10000 +9990 +9992 +9993 +9995 +10010 +10014 +10020 +10021 +10029 +10041 +10047 +10052 +10056 +10057 +10060 +10078 +10083 +10101 +10103 +10110 +10116 +10128 +10131 +10132 +10143 +10148 +10151 +10156 +10159 +10164 +10165 +10189 +10190 +10202 +10203 +10207 +10199 +10216 +10215 +10221 +10239 +10244 +10245 +10262 +10265 +10270 +10271 +10248 +10269 +10272 +10275 +10274 +10280 +10289 +10301 +10304 +10305 +10309 +10306 +10324 +10330 +10337 +10348 +10357 +10362 +10363 +10365 +10366 +10373 +10378 +10379 +10382 +10387 +10395 +10396 +10397 +10406 +10415 diff --git a/2021/01/part1.rs b/2021/01/part1.rs new file mode 100644 index 0000000..eaacea1 --- /dev/null +++ b/2021/01/part1.rs @@ -0,0 +1,25 @@ +use std::io::stdin; +use std::io::BufRead; + +fn main() { + let mut prev: Option = None; + let mut increased = 0; + for line in stdin().lock().lines() { + let cur = line.unwrap().parse::().unwrap(); + + match prev { + None => println!("{} (N/A)", cur), + Some(prev) => { + if cur > prev { + increased += 1; + } + let evaluate = if cur > prev { "increased" } else { "decreased" }; + println!("{} ({})", cur, evaluate) + } + } + + prev = Some(cur); + } + + println!("{}", increased) +} diff --git a/2021/01/part2.rs b/2021/01/part2.rs new file mode 100644 index 0000000..47440ee --- /dev/null +++ b/2021/01/part2.rs @@ -0,0 +1,27 @@ +use itertools::Itertools; +use std::io::stdin; +use std::io::BufRead; + +fn main() { + let mut prev: Option = None; + let mut increased = 0; + for (a, b, c) in stdin() + .lock() + .lines() + .map(|line| line.unwrap().parse::().unwrap()) + .tuple_windows() + { + let sum = a + b + c; + match prev { + Some(prev) => { + if sum > prev { + increased += 1 + } + } + _ => (), + } + prev = Some(sum) + } + + println!("{}", increased) +} diff --git a/2021/Cargo.lock b/2021/Cargo.lock new file mode 100644 index 0000000..9d91f08 --- /dev/null +++ b/2021/Cargo.lock @@ -0,0 +1,25 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aoc-2021" +version = "0.1.0" +dependencies = [ + "itertools", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "itertools" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" +dependencies = [ + "either", +] diff --git a/2021/Cargo.toml b/2021/Cargo.toml new file mode 100644 index 0000000..315770b --- /dev/null +++ b/2021/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "aoc-2021" +version = "0.1.0" +edition = "2021" + +[dependencies] +itertools = "0.10.1" + +[lib] +name = "util" +path = "util/main.rs" + +[[bin]] +name = "day-01-part-1" +path = "01/part1.rs" + +[[bin]] +name = "day-01-part-2" +path = "01/part2.rs" diff --git a/2021/util/main.rs b/2021/util/main.rs new file mode 100644 index 0000000..c495ae7 --- /dev/null +++ b/2021/util/main.rs @@ -0,0 +1,11 @@ +use std::fs::File; +use std::io::BufRead; +use std::io::BufReader; +use std::io::Lines; + +pub mod math; + +pub fn file_lines(path: String) -> Lines> { + let input = File::open(path).unwrap(); + return BufReader::new(input).lines(); +} diff --git a/2021/util/math.rs b/2021/util/math.rs new file mode 100644 index 0000000..33624d4 --- /dev/null +++ b/2021/util/math.rs @@ -0,0 +1,7 @@ +pub fn sum(x: i32, y: i32) -> i32 { + x + y +} + +pub fn sub(x: i32, y: i32) -> i32 { + x - y +}