diff --git a/aoc21/LICENSE b/aoc21/LICENSE new file mode 100644 index 0000000..1b93a68 --- /dev/null +++ b/aoc21/LICENSE @@ -0,0 +1,7 @@ +Copyright 2021 Suhas + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/aoc21/d1/in.txt b/aoc21/d1/in.txt new file mode 100644 index 0000000..3af412a --- /dev/null +++ b/aoc21/d1/in.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/aoc21/d1/sol.py b/aoc21/d1/sol.py new file mode 100644 index 0000000..7bcd746 --- /dev/null +++ b/aoc21/d1/sol.py @@ -0,0 +1,39 @@ +file = open("in.txt", "r") + +lns = file.readlines() + +def p1(): + count = 0 + for i in range(1, len(lns)): + if int(lns[i]) >= int(lns[i-1]): + count += 1 + return count + +def p2(): + count = 0 + sets = [] + for i in range(len(lns)): + if i + 3 > len(lns): + continue + temp = [None] * 3 + temp[0] = lns[i] + temp[1] = lns[i+1] + temp[2] = lns[i+2] + if len(sets) == 0: + index = 0 + else: + index = len(sets) + 1 + sets.append(temp) + + for i in range(1, len(sets)): + set1 = sets[i] + set2 = sets[i-1] + sum1 = int(set1[0]) + int(set1[1]) + int(set1[2]) + sum2 = int(set2[0]) + int(set2[1]) + int(set2[2]) + if sum1 > sum2: + count += 1 + + return count + +print(f"part 1: {p1()}") +print(f"part 2: {p2()}") \ No newline at end of file diff --git a/aoc21/d2/in.txt b/aoc21/d2/in.txt new file mode 100644 index 0000000..a40e69b --- /dev/null +++ b/aoc21/d2/in.txt @@ -0,0 +1,1000 @@ +forward 5 +down 8 +down 6 +down 7 +down 8 +forward 7 +down 3 +up 6 +forward 6 +down 2 +forward 5 +down 6 +up 3 +down 4 +forward 4 +down 6 +down 1 +up 5 +forward 5 +down 1 +down 7 +up 2 +down 7 +forward 1 +forward 6 +down 1 +up 1 +up 4 +forward 3 +forward 6 +forward 1 +forward 4 +up 3 +forward 1 +forward 4 +down 9 +forward 4 +forward 8 +up 8 +forward 5 +up 4 +up 3 +down 8 +forward 5 +down 4 +forward 1 +forward 7 +down 1 +forward 8 +down 4 +forward 2 +forward 7 +forward 9 +up 4 +down 3 +forward 7 +forward 6 +down 8 +forward 2 +forward 5 +forward 4 +down 6 +forward 6 +up 5 +down 3 +down 6 +down 5 +down 7 +down 8 +up 5 +down 5 +forward 5 +forward 4 +up 3 +down 7 +down 3 +forward 4 +down 2 +forward 4 +forward 3 +forward 4 +forward 9 +forward 6 +forward 8 +up 8 +down 8 +up 5 +down 4 +down 8 +up 7 +up 8 +down 6 +down 3 +forward 2 +forward 7 +up 1 +up 2 +forward 2 +down 7 +down 1 +up 9 +forward 6 +forward 4 +down 2 +up 6 +down 2 +down 1 +down 3 +up 6 +down 1 +down 8 +forward 7 +up 8 +forward 5 +forward 8 +down 8 +forward 6 +forward 8 +down 3 +down 4 +down 6 +up 2 +forward 6 +up 9 +forward 4 +forward 8 +up 4 +down 8 +forward 8 +down 8 +down 4 +down 5 +forward 7 +down 6 +down 6 +up 2 +up 1 +forward 7 +forward 8 +forward 4 +forward 9 +down 7 +forward 4 +up 5 +down 3 +up 4 +down 9 +down 2 +down 8 +forward 3 +forward 5 +forward 7 +forward 9 +forward 5 +forward 8 +forward 6 +forward 4 +forward 6 +forward 7 +forward 2 +down 1 +down 8 +down 4 +down 5 +down 6 +up 3 +up 2 +forward 4 +down 4 +forward 7 +up 6 +up 9 +down 1 +down 3 +down 1 +up 3 +up 1 +down 2 +up 5 +forward 1 +down 7 +forward 9 +down 4 +up 4 +down 6 +down 3 +forward 4 +up 6 +up 4 +forward 1 +up 7 +down 1 +down 7 +down 7 +forward 9 +down 3 +down 3 +forward 6 +down 2 +forward 7 +up 4 +up 8 +down 8 +forward 7 +forward 6 +down 7 +forward 5 +up 6 +up 6 +down 9 +up 6 +up 2 +forward 9 +forward 1 +up 5 +up 3 +down 9 +up 8 +down 7 +up 7 +forward 5 +down 7 +down 4 +forward 2 +forward 3 +forward 5 +down 1 +up 6 +down 6 +up 6 +down 8 +down 3 +down 4 +forward 9 +down 3 +forward 3 +up 1 +down 2 +forward 8 +down 7 +up 9 +forward 1 +down 3 +forward 1 +forward 8 +down 3 +forward 8 +forward 6 +down 1 +down 9 +forward 2 +down 1 +down 6 +up 1 +up 7 +down 9 +forward 6 +forward 5 +forward 2 +up 6 +down 6 +forward 6 +up 3 +down 7 +down 8 +forward 5 +down 7 +forward 8 +down 8 +forward 4 +down 6 +forward 4 +down 7 +up 5 +down 5 +down 5 +down 4 +down 3 +forward 8 +forward 1 +down 8 +down 2 +forward 3 +forward 7 +forward 3 +down 5 +down 6 +down 8 +down 6 +forward 9 +forward 4 +forward 8 +down 5 +down 7 +forward 4 +up 5 +down 8 +up 6 +up 7 +down 6 +down 8 +forward 3 +up 6 +forward 7 +down 4 +up 1 +up 8 +forward 3 +down 6 +down 1 +forward 7 +down 1 +down 9 +forward 6 +down 4 +forward 3 +forward 1 +down 5 +down 9 +down 9 +down 5 +down 8 +down 7 +forward 1 +forward 5 +down 2 +forward 2 +forward 1 +down 8 +forward 6 +down 3 +forward 4 +up 2 +up 8 +forward 7 +forward 4 +down 8 +up 6 +forward 3 +up 1 +up 2 +forward 5 +forward 9 +down 5 +forward 2 +forward 5 +up 6 +down 1 +down 1 +down 6 +forward 6 +down 7 +forward 5 +forward 8 +down 7 +down 5 +forward 9 +forward 1 +up 6 +down 7 +forward 1 +forward 4 +down 5 +down 6 +up 3 +up 8 +up 5 +down 8 +down 8 +down 6 +down 2 +down 3 +down 9 +forward 8 +forward 7 +forward 7 +up 5 +down 5 +forward 9 +up 8 +up 5 +forward 1 +down 9 +down 9 +forward 9 +forward 4 +forward 6 +up 9 +up 5 +up 3 +down 9 +up 7 +up 1 +down 3 +down 9 +down 7 +forward 6 +down 7 +forward 7 +forward 8 +down 2 +forward 5 +up 1 +down 6 +up 9 +forward 5 +up 9 +down 2 +down 3 +forward 5 +down 9 +forward 9 +forward 2 +forward 8 +down 1 +forward 8 +up 1 +forward 3 +up 1 +down 1 +forward 9 +down 2 +forward 2 +up 1 +up 8 +down 2 +down 7 +down 5 +up 2 +up 6 +down 9 +down 7 +down 7 +up 6 +up 8 +down 7 +forward 5 +down 4 +down 5 +up 8 +up 6 +down 6 +forward 6 +up 6 +down 1 +down 1 +down 1 +forward 1 +down 8 +down 4 +down 5 +down 2 +down 5 +up 8 +up 8 +down 3 +down 6 +down 1 +forward 6 +forward 5 +forward 1 +down 3 +down 4 +up 9 +down 3 +up 8 +forward 5 +down 5 +forward 2 +down 8 +down 2 +up 1 +forward 7 +up 8 +forward 7 +down 3 +down 1 +down 3 +forward 4 +down 5 +down 8 +forward 8 +forward 3 +forward 7 +down 7 +forward 4 +down 1 +forward 3 +up 2 +down 7 +down 1 +forward 4 +forward 7 +down 3 +down 1 +forward 4 +down 3 +forward 2 +up 9 +down 5 +down 9 +forward 5 +up 5 +down 3 +up 6 +up 8 +down 7 +down 3 +down 9 +forward 6 +forward 8 +forward 3 +down 6 +up 8 +forward 8 +forward 9 +down 4 +down 1 +forward 2 +down 2 +up 2 +down 5 +down 1 +down 3 +forward 4 +down 3 +up 8 +up 6 +up 5 +down 4 +forward 3 +up 6 +forward 6 +forward 2 +down 8 +down 5 +forward 3 +up 1 +forward 5 +forward 9 +forward 5 +down 5 +forward 3 +forward 6 +forward 5 +forward 3 +down 1 +down 1 +down 1 +down 9 +forward 8 +forward 2 +forward 4 +forward 8 +down 1 +up 8 +down 1 +down 6 +down 5 +up 8 +down 4 +forward 8 +forward 6 +down 6 +forward 2 +forward 7 +forward 2 +up 7 +forward 4 +up 1 +up 8 +down 3 +down 2 +down 3 +up 7 +down 9 +up 5 +down 1 +down 3 +up 5 +down 6 +up 9 +down 4 +down 7 +down 6 +down 4 +forward 5 +forward 6 +down 8 +forward 3 +forward 8 +up 5 +up 6 +up 8 +forward 8 +forward 1 +down 6 +forward 3 +forward 3 +forward 6 +down 3 +down 2 +forward 5 +down 5 +forward 6 +down 3 +down 9 +down 8 +down 6 +down 6 +forward 1 +up 5 +down 9 +forward 3 +forward 3 +down 2 +forward 8 +forward 3 +forward 2 +forward 5 +down 4 +down 1 +up 2 +down 1 +down 1 +forward 5 +down 7 +up 7 +down 9 +down 8 +down 6 +forward 3 +forward 5 +down 3 +down 6 +up 3 +up 2 +up 8 +down 3 +up 3 +down 6 +forward 7 +forward 4 +up 5 +forward 1 +up 3 +forward 8 +down 2 +down 5 +down 2 +forward 4 +forward 4 +down 4 +up 8 +down 1 +up 2 +forward 2 +forward 9 +forward 4 +down 3 +down 7 +forward 1 +down 2 +forward 8 +down 8 +forward 3 +down 7 +forward 9 +forward 6 +up 1 +forward 3 +up 2 +up 3 +forward 6 +down 8 +up 9 +down 2 +down 9 +down 6 +down 4 +forward 5 +forward 3 +up 7 +forward 7 +up 7 +up 6 +down 7 +down 2 +up 7 +down 5 +up 9 +forward 3 +up 6 +up 6 +up 6 +up 1 +forward 5 +forward 5 +down 8 +forward 6 +forward 7 +down 3 +down 4 +down 2 +down 4 +down 1 +forward 7 +down 7 +down 5 +forward 8 +up 6 +up 8 +forward 8 +forward 2 +forward 4 +down 6 +down 4 +down 2 +down 3 +forward 8 +forward 6 +down 3 +forward 7 +forward 4 +up 8 +down 9 +forward 5 +up 5 +up 5 +up 7 +forward 3 +up 1 +down 2 +forward 5 +forward 5 +up 1 +forward 4 +down 6 +up 5 +up 3 +forward 9 +down 9 +down 6 +down 1 +down 2 +down 4 +down 7 +forward 3 +up 5 +forward 2 +down 3 +forward 7 +up 8 +up 3 +forward 6 +up 7 +up 1 +up 2 +down 5 +forward 5 +down 3 +down 5 +down 6 +up 1 +down 2 +up 1 +forward 3 +down 3 +down 4 +down 6 +down 1 +down 3 +forward 9 +forward 1 +down 1 +up 3 +forward 4 +forward 7 +forward 4 +down 2 +forward 6 +forward 2 +forward 7 +down 9 +forward 8 +forward 3 +up 8 +down 9 +up 8 +forward 5 +forward 9 +down 4 +forward 1 +up 9 +forward 2 +down 6 +up 3 +forward 1 +forward 3 +forward 8 +down 7 +down 3 +down 5 +down 2 +down 2 +forward 4 +forward 1 +down 2 +up 8 +down 2 +forward 3 +down 2 +down 6 +down 1 +up 1 +down 7 +down 3 +forward 3 +forward 1 +forward 9 +down 9 +down 2 +up 1 +forward 9 +up 2 +down 2 +forward 3 +down 4 +forward 9 +forward 5 +up 5 +forward 2 +up 3 +forward 8 +down 3 +forward 5 +forward 5 +down 8 +up 9 +forward 7 +up 2 +up 2 +up 1 +up 7 +down 8 +forward 9 +forward 9 +up 6 +down 5 +forward 7 +down 9 +down 8 +down 5 +down 3 +down 2 +forward 6 +down 7 +forward 3 +up 5 +forward 1 +up 7 +forward 3 +down 5 +down 9 +down 8 +forward 2 +up 4 +forward 7 +forward 5 +forward 8 +forward 7 +up 7 +forward 4 +up 7 +down 9 +forward 1 +forward 3 +down 3 +forward 4 +down 3 +forward 3 +down 5 +down 1 +forward 6 +down 4 +down 3 +down 2 +up 1 +down 1 +down 6 +down 6 +forward 9 +down 5 +forward 1 +up 4 +forward 7 +down 8 +forward 1 +forward 9 +forward 7 +down 1 +down 3 +up 2 +down 5 +up 6 +forward 2 +up 2 +down 7 +down 9 +forward 3 +up 5 +up 7 +down 4 +forward 6 +down 8 +forward 7 +up 1 +up 4 +forward 4 +down 9 +forward 9 +forward 9 +down 3 +forward 5 +forward 1 +down 3 +down 8 +forward 7 +down 4 +forward 3 +down 3 +forward 8 +forward 2 +forward 6 +up 9 +forward 2 +down 9 +forward 2 +down 1 +forward 9 +up 1 +up 4 +up 1 +down 1 +forward 4 +up 9 +up 8 +down 1 +down 3 +down 2 +forward 9 +down 7 +down 4 +forward 2 +up 9 +down 7 +down 1 +down 9 +forward 2 +down 2 +forward 9 +down 5 +up 1 +down 3 +up 6 +down 4 +forward 8 +down 2 +down 2 +down 9 +forward 9 +forward 2 +down 1 +forward 6 +down 2 +up 4 +down 8 +up 4 +down 6 +down 2 +forward 7 +down 3 +up 3 +forward 1 +up 4 +forward 5 +down 7 +down 8 +forward 7 +forward 3 +down 5 +up 6 +down 7 +down 1 +up 7 +down 1 +forward 6 +forward 3 +forward 3 +forward 7 \ No newline at end of file diff --git a/aoc21/d2/sol.py b/aoc21/d2/sol.py new file mode 100644 index 0000000..5b51abc --- /dev/null +++ b/aoc21/d2/sol.py @@ -0,0 +1,42 @@ +file = open("in.txt", "r") +lns = file.readlines() + +def p1(): + depth = 0 + horizontal = 0 + for i in range(len(lns)): + d = lns[i].split()[0] + v = int(lns[i].split()[1]) + if d == 'down': + depth += v + elif d == 'up': + depth -= v + elif d == 'forward': + horizontal += v + return {"depth": depth, "horizontal": horizontal} + +def p2(): + depth = 0 + horizontal = 0 + aim = 0 + for ln in lns: + d = ln.split()[0] + v = int(ln.split()[1]) + if d == 'down': + aim += v + elif d == 'up': + aim -= v + elif d == 'forward': + horizontal += v + depth += aim * v + return {"depth": depth, "horizontal": horizontal} + +# output lines +# one = p1() +# two = p2() +# d1 = one['depth'] +# h1 = one['horizontal'] +# d2 = two['depth'] +# h2 = two['horizontal'] +# print(f"part 1: {d1 * h1}") +# print(f"part 2: {d2 * h2}") \ No newline at end of file diff --git a/aoc21/d3/in.txt b/aoc21/d3/in.txt new file mode 100644 index 0000000..6ed7c05 --- /dev/null +++ b/aoc21/d3/in.txt @@ -0,0 +1,1000 @@ +110001101000 +111011011100 +100001101100 +111011011010 +001001101100 +100001111100 +110110101101 +110010110000 +111101010011 +101101010110 +000010101110 +110110010001 +011101010111 +000101101011 +010110011010 +101110110000 +111110101011 +010001111110 +010011111110 +101010111001 +110010010111 +110001100101 +111111100101 +101001111010 +111011111000 +100011101000 +011100111001 +100000100110 +001101000100 +010110110100 +011000111111 +101011111000 +011011110011 +000110011101 +001000001010 +101111100000 +011000111110 +011110000001 +101001110100 +110000001110 +010010110110 +110001110011 +001100000101 +000001001101 +111011011011 +000101100111 +010111100000 +000110100010 +001000110101 +110000011100 +101011000111 +111001011110 +001110011101 +100110011000 +000000001101 +011011101101 +110100010011 +110101110011 +111110101010 +111010000001 +111000101101 +000011111111 +000110100011 +101100111011 +100011111110 +111000010000 +010001011111 +101011101001 +110111110010 +100111101100 +101110111001 +101100010000 +101100000000 +010010011111 +101000101011 +111000000000 +001101101100 +001010110100 +101110010111 +010011011111 +001101101111 +000110000010 +101010011100 +010011101010 +001001011111 +010011100100 +011001010000 +101101000110 +000000010010 +110101011000 +000011001001 +110111110110 +010100000110 +001010101100 +001010100000 +101001100110 +011111011000 +001111111101 +001000010001 +011000011001 +100110110000 +100110001100 +110101101001 +101100010111 +100111001110 +010000100101 +111100101100 +000000011001 +110010101101 +111001110100 +011111100001 +010011011011 +100100100111 +011010011000 +100100110010 +111111100000 +111010111110 +001001111101 +101010110001 +101100000011 +011011110010 +100010000101 +110111010011 +101001001111 +000011000111 +010110110001 +100010001101 +000011111110 +100111110110 +110100001110 +000010000000 +011010010101 +000110011010 +110111011101 +110111001100 +100100010100 +100101101011 +001001001001 +101111001010 +010010010100 +010101000001 +111011101100 +011100111110 +011111110010 +001011001110 +110101001110 +000000000010 +100111010000 +000010001010 +110110001111 +001101110111 +010010101010 +011100001011 +110111001010 +001001011001 +000000000100 +110111001000 +010101110011 +110000011011 +101111000000 +001011010100 +001010000100 +111110101111 +000011000100 +100011110110 +010011000010 +000110001001 +111110010110 +100110011010 +110010111101 +001111011101 +100001101111 +110100000001 +011110000000 +011010001001 +110110011111 +100110001111 +001001011100 +010010100010 +011100001100 +011001001011 +011111100010 +101001100101 +011100100110 +101000010011 +110010101010 +000111111100 +010000000101 +111100011010 +101100011010 +011111000011 +011000111101 +111000011011 +110101111101 +001000100101 +100100110101 +000111101110 +010000111011 +001011011101 +111011110101 +100110000101 +111101011111 +011101000011 +010010110101 +000001011101 +111110000100 +010100011100 +101000100011 +101010000011 +111011001011 +010101010111 +111111000111 +001011110100 +000000111010 +110100001111 +110100001001 +011111000100 +001101111101 +001000110000 +100011110100 +111110010100 +001100111110 +010010001110 +000100110101 +111011100111 +001000000110 +100100100011 +000011001101 +000111001110 +000101111101 +011101110010 +011110111111 +000111000011 +101001000101 +101111111110 +100101110100 +101010100010 +000010111010 +001011101011 +100100000111 +011000010001 +100000100101 +001010001010 +001100100001 +001000010010 +110101110001 +100111010111 +100101101001 +100010101101 +011101100101 +011111101011 +101101011010 +101001111011 +111010011101 +010010001100 +110001000010 +101011101010 +010001010011 +101111111000 +001110101000 +111000000111 +010111011100 +101000100100 +010011010111 +011000100010 +111001111101 +101010010011 +110011011000 +100111010101 +100001101110 +011011110110 +110000010111 +001100101111 +000110111111 +111001011011 +001010100100 +011111100011 +011110001110 +011011111000 +010101111101 +100001100011 +111111011111 +100010111101 +110101010100 +101000111001 +001001000001 +110011110011 +001101001000 +001100101110 +010001111100 +101100111000 +001011000011 +110001011101 +101001011010 +110011110110 +011010111101 +001001100001 +011010010100 +010111101011 +000110010101 +110010100011 +001111001101 +100110111001 +100010000110 +010111011011 +001110011110 +011010111100 +110100100010 +001010001110 +010011111010 +101010100111 +111010100101 +010000000000 +000001010101 +111001000001 +011110000010 +001010111111 +100101000001 +001000010111 +101000011011 +011100010000 +111000010100 +010001011100 +111111010001 +011010101110 +011111110001 +000110101100 +111000011001 +001010011100 +000011011100 +110111111101 +001001010101 +011110000011 +001111111001 +110010100000 +101111010100 +100100011000 +010101000111 +111100110111 +010010111011 +001101011111 +011101011000 +111111111111 +010100110110 +111000001010 +000100000110 +000110010000 +110000011000 +001000011001 +011110000100 +101011100011 +000011100001 +110100000011 +100100011100 +011110010111 +101000111111 +001010001100 +100010000100 +011100110110 +101010011000 +100000001111 +010001111111 +101101001011 +100010100101 +011011100000 +111110100111 +000100011000 +011000100001 +110000111000 +010011100101 +000100010011 +101110101011 +011111001111 +010001001101 +111100011111 +010000100000 +001111000101 +100000010010 +000111101000 +101111010000 +110110010000 +110111110001 +111110100000 +101110001010 +011111011001 +000001111101 +101000010100 +110111101010 +001111111011 +000101010101 +110110001011 +100011001010 +101010010111 +111100011110 +010000101101 +111110000010 +000100100111 +000110001100 +011110000111 +101110100001 +110001101010 +110100010100 +111010101101 +110010001001 +000010011110 +001100100110 +011111010011 +111110000001 +110111111100 +011100000110 +000011100111 +001101110100 +100111011101 +011100010010 +011001110110 +110110010010 +011000011011 +110111101100 +101100101100 +100101111001 +101001111000 +101000101001 +011101010100 +001110000100 +011100100000 +110000001010 +010001000111 +001100000110 +000100111011 +101001011101 +011100011110 +001011001000 +111101101100 +001110011111 +100011100110 +011000100101 +111010111111 +111010001110 +111011101111 +010001110011 +000011010100 +000000101001 +010100100001 +101111111011 +100111100000 +111110100101 +000100001000 +000101011101 +110001001110 +110111001001 +110111110011 +111101000111 +010111000100 +000010101000 +000110101101 +100000001010 +010111100101 +110010000100 +000011010111 +000101001001 +100111101110 +111110011111 +011001000010 +110010001101 +001111110010 +101110111111 +100100111101 +010111100110 +000101110001 +010111000001 +001011101010 +101101100110 +110010111111 +001111101010 +110110100100 +101110100101 +011001110010 +000000100011 +110000111100 +011110001011 +001110011000 +000010011011 +011100011100 +110001001010 +100000111010 +010010000111 +010010000001 +001110100100 +111110111101 +001100001011 +110101000000 +111100010110 +100010011100 +001011110011 +100000111001 +000101000111 +100011101011 +011010001000 +111111111001 +100011011001 +101001010011 +110001111001 +001100101101 +111000111100 +101000110110 +000011110011 +000110010001 +110110010011 +011100000000 +101101110001 +100001111101 +110010010000 +100001011011 +100010010000 +000000000110 +001011001101 +000001000101 +011100100010 +000100010001 +001111001110 +100001101001 +010100011111 +000001111011 +110100111110 +101000101000 +000101100101 +011000001101 +001010101000 +100100100110 +101010111101 +010000111100 +000000010000 +101011110100 +111011111010 +000011011111 +011111000010 +001001001110 +001100010111 +011001110100 +101011000110 +001000011101 +111101000010 +011101001001 +100011101110 +110000100101 +011111101100 +101000001001 +011011001110 +001100011110 +010110100001 +011100001000 +001111011010 +110001100100 +000001100011 +101011110001 +100000010111 +010011001000 +101111101110 +110001011100 +110000001011 +010001100000 +100111000111 +110000000100 +000011010010 +000101111001 +000100101000 +111000111111 +011110100111 +111110010010 +111111000010 +011111110111 +101101000100 +110101001111 +011000000101 +011010100110 +100101101000 +011001111000 +010001110101 +011011110111 +101110110100 +100011100101 +000101100000 +100101011011 +010011000110 +000110110111 +011110010010 +101111001111 +101001110111 +100001011001 +101101001111 +011111110101 +110001111111 +010111001011 +100100001010 +000100101111 +110111110111 +001101010100 +001011111100 +100110111101 +000001001001 +100111111101 +011010101101 +100010100001 +110101111110 +010010011100 +111001111000 +101011100001 +011101111110 +110101101011 +011100101100 +110110000001 +010110110110 +101011010111 +110111011011 +010011101001 +000001101010 +000010111000 +101000101010 +111100001000 +001001001100 +010110000010 +010010101111 +101101011111 +111111010011 +111111011101 +100011010000 +001011100111 +011001011110 +110010001110 +001010010100 +000010000010 +100011100001 +011011100110 +100001001111 +111000101010 +111000110100 +110100011011 +111010010101 +010010011001 +010111101111 +001111001100 +000111010011 +010010010001 +011101001100 +011111011110 +000101101010 +001011110111 +010000100011 +111101110001 +110001110010 +011000010101 +111111000110 +100110110101 +010001000110 +010000001111 +100000000110 +100101101110 +010101111111 +111000011010 +011000000100 +010100011110 +001101111111 +111011000100 +011011101100 +011001100011 +010001000010 +011001000111 +001010000101 +111001011001 +110100111101 +100101011010 +011100010101 +100000000010 +110101101110 +110011011011 +100010111000 +010110000100 +100000011000 +011001011100 +010011001110 +001100010101 +111100000000 +001000110001 +000011010101 +110101000010 +001100101001 +100110011100 +100001101011 +111010011011 +011010110010 +010101000000 +000111011111 +111110110101 +101010110101 +111011100100 +010111111111 +101010101111 +000011110010 +100101001010 +101000001100 +000000101100 +011111010001 +110101001010 +101010101110 +000101000100 +000110101001 +010011011110 +111101101111 +110100111000 +011011000111 +010000001000 +110000000110 +010100101111 +010110001001 +000111101111 +101110110001 +101000101110 +011101100001 +010001010110 +010011111111 +011111111101 +010111001010 +010010011011 +000010010001 +101100000010 +011001101001 +011100011011 +011010011100 +111101110101 +001001001011 +011110011101 +100001010100 +010010111110 +010011111101 +110000101001 +101110000101 +110010001100 +011001110111 +010011000000 +000011100101 +101010101100 +001000111000 +110101000001 +111110001000 +110000011001 +100000111000 +010111110001 +011011000001 +101101100100 +111110111011 +101000000101 +011110110110 +011001100111 +100101001011 +001110110100 +011010100101 +011110010001 +110010101110 +111101001111 +100100000100 +100000110001 +100100110011 +110011101000 +000110101011 +011110010101 +010101010000 +111111011110 +101111111111 +001111000010 +100001111001 +011110010000 +100101001101 +111010001100 +001101010010 +100100111110 +011011100001 +110010101001 +010101101101 +101000100101 +001100101011 +111111001010 +001000001011 +011101100111 +100101000010 +111011011110 +001000000101 +001000000000 +000101010110 +001010111011 +110010000000 +010011100001 +001001011011 +000101000101 +010011000111 +100100101101 +011110010110 +100100010000 +101100100010 +110101011011 +000001111111 +101001110010 +000100101011 +110001000000 +011010111011 +001111101110 +100110111111 +011100000100 +111100010101 +100001111111 +100000110000 +101111110000 +100000110101 +001101101010 +101010011110 +011000110010 +001110110110 +101000110010 +000111001111 +011101111001 +010000110010 +101011000000 +001011001010 +001101111100 +010010111001 +010101100010 +011001100000 +011110110011 +010101011100 +011000100011 +001110101010 +100111110001 +101110110111 +110100110101 +101000110111 +100011110111 +010000010010 +001001111111 +010100111110 +101111111101 +110111101111 +011010110101 +101100111001 +110001111010 +000101110010 +110000010110 +010110100011 +111011111111 +001100011010 +011010000010 +000101011000 +101000001000 +011110110101 +000001001011 +010011110001 +110101100000 +101011000001 +101001000010 +111111100111 +011010010010 +100010001100 +111011011101 +010110001111 +001001010011 +111001001111 +101000010101 +110101101111 +011111111001 +111001101010 +100111011010 +001010010011 +110001110100 +011110001010 +110111010101 +001001100110 +001001110011 +100001110011 +001001001101 +100110100100 +010001101101 +101110000111 +001110001111 +010100111100 +010110011111 +100100000011 +100110011001 +011101111011 +011000010000 +010101101001 +100010110011 +000100000010 +111001001000 +001110100000 +110000111011 +000001100111 +000110110000 +111001110000 +100001011100 +101101001101 +111101110011 +100011011100 +011010110111 +111001110001 +101011111100 +110010110110 +011100111010 +100111110101 +010011010010 +011101110111 +101110010100 +011100100001 +001011100011 +110101010001 +101000000111 +000101100100 +100011000011 +111011001101 +101001100111 +000000000111 +010100110011 +011111001101 +111101110000 +000111111000 +110100101011 +100101110001 +001010100011 +110101100001 +100101010110 +011100111011 +100100111001 +000100110001 +001101011100 +000110100110 +010001001111 +110000000000 +001010101101 +100001100001 +110010100111 +000010011111 +101110011001 +110010010101 +010101011101 +010001110010 +011101011111 +100100001011 +001100011100 +100111101001 +110010011001 +001010000011 +101010100000 +111111111110 +011010101001 +011110100010 +110000111101 +111010100001 +100111100110 +000000011010 +011011001100 +001101111011 +011111111010 +000101110111 +101100011011 +100111110000 +111011010100 +000100001001 +010000110000 +010111110000 +000110011001 +101111001110 +001100010000 +011011011011 +001001001000 +110110111011 +001000010100 +010100010000 +010101110111 +001111010100 +001010000010 +011110011001 +100001001001 +001101000101 +010001010101 +101110001001 +011100100111 +111000001111 +101001111111 +101010001011 +111110110011 +101101101000 +011001111010 +000010011001 +100000010001 +101010011111 +000100011101 +010010100000 +000001100101 +001001011110 +100101000101 +011111110110 +111101111001 +100011101100 \ No newline at end of file diff --git a/aoc21/d3/sol.py b/aoc21/d3/sol.py new file mode 100644 index 0000000..e248cb3 --- /dev/null +++ b/aoc21/d3/sol.py @@ -0,0 +1,30 @@ +file = open("in.txt", "r") +lns = [f.rstrip() for f in file.readlines()] + +def p1() -> int: + zero = [0] * 12 + one = [0] * 12 + + for ln in lns: + for i, ch in enumerate(list(ln)): + if ch == "0": + zero[i] += 1 + else: + one[i] += 1 + + gamma = "0b" + epsilon = "0b" + + for i, _ in enumerate(zero): + if zero[i] > one[i]: + gamma += "0" + epsilon += "1" + else: + gamma += "1" + epsilon += "0" + + return (int(gamma, 2) * int(epsilon, 2)) + +# def p2(): + +print(f"part 1: {p1()}") diff --git a/aoc21/d3/test.txt b/aoc21/d3/test.txt new file mode 100644 index 0000000..4ac1a79 --- /dev/null +++ b/aoc21/d3/test.txt @@ -0,0 +1,1999 @@ +110001101000 + +111011011100 + +100001101100 + +111011011010 + +001001101100 + +100001111100 + +110110101101 + +110010110000 + +111101010011 + +101101010110 + +000010101110 + +110110010001 + +011101010111 + +000101101011 + +010110011010 + +101110110000 + +111110101011 + +010001111110 + +010011111110 + +101010111001 + +110010010111 + +110001100101 + +111111100101 + +101001111010 + +111011111000 + +100011101000 + +011100111001 + +100000100110 + +001101000100 + +010110110100 + +011000111111 + +101011111000 + +011011110011 + +000110011101 + +001000001010 + +101111100000 + +011000111110 + +011110000001 + +101001110100 + +110000001110 + +010010110110 + +110001110011 + +001100000101 + +000001001101 + +111011011011 + +000101100111 + +010111100000 + +000110100010 + +001000110101 + +110000011100 + +101011000111 + +111001011110 + +001110011101 + +100110011000 + +000000001101 + +011011101101 + +110100010011 + +110101110011 + +111110101010 + +111010000001 + +111000101101 + +000011111111 + +000110100011 + +101100111011 + +100011111110 + +111000010000 + +010001011111 + +101011101001 + +110111110010 + +100111101100 + +101110111001 + +101100010000 + +101100000000 + +010010011111 + +101000101011 + +111000000000 + +001101101100 + +001010110100 + +101110010111 + +010011011111 + +001101101111 + +000110000010 + +101010011100 + +010011101010 + +001001011111 + +010011100100 + +011001010000 + +101101000110 + +000000010010 + +110101011000 + +000011001001 + +110111110110 + +010100000110 + +001010101100 + +001010100000 + +101001100110 + +011111011000 + +001111111101 + +001000010001 + +011000011001 + +100110110000 + +100110001100 + +110101101001 + +101100010111 + +100111001110 + +010000100101 + +111100101100 + +000000011001 + +110010101101 + +111001110100 + +011111100001 + +010011011011 + +100100100111 + +011010011000 + +100100110010 + +111111100000 + +111010111110 + +001001111101 + +101010110001 + +101100000011 + +011011110010 + +100010000101 + +110111010011 + +101001001111 + +000011000111 + +010110110001 + +100010001101 + +000011111110 + +100111110110 + +110100001110 + +000010000000 + +011010010101 + +000110011010 + +110111011101 + +110111001100 + +100100010100 + +100101101011 + +001001001001 + +101111001010 + +010010010100 + +010101000001 + +111011101100 + +011100111110 + +011111110010 + +001011001110 + +110101001110 + +000000000010 + +100111010000 + +000010001010 + +110110001111 + +001101110111 + +010010101010 + +011100001011 + +110111001010 + +001001011001 + +000000000100 + +110111001000 + +010101110011 + +110000011011 + +101111000000 + +001011010100 + +001010000100 + +111110101111 + +000011000100 + +100011110110 + +010011000010 + +000110001001 + +111110010110 + +100110011010 + +110010111101 + +001111011101 + +100001101111 + +110100000001 + +011110000000 + +011010001001 + +110110011111 + +100110001111 + +001001011100 + +010010100010 + +011100001100 + +011001001011 + +011111100010 + +101001100101 + +011100100110 + +101000010011 + +110010101010 + +000111111100 + +010000000101 + +111100011010 + +101100011010 + +011111000011 + +011000111101 + +111000011011 + +110101111101 + +001000100101 + +100100110101 + +000111101110 + +010000111011 + +001011011101 + +111011110101 + +100110000101 + +111101011111 + +011101000011 + +010010110101 + +000001011101 + +111110000100 + +010100011100 + +101000100011 + +101010000011 + +111011001011 + +010101010111 + +111111000111 + +001011110100 + +000000111010 + +110100001111 + +110100001001 + +011111000100 + +001101111101 + +001000110000 + +100011110100 + +111110010100 + +001100111110 + +010010001110 + +000100110101 + +111011100111 + +001000000110 + +100100100011 + +000011001101 + +000111001110 + +000101111101 + +011101110010 + +011110111111 + +000111000011 + +101001000101 + +101111111110 + +100101110100 + +101010100010 + +000010111010 + +001011101011 + +100100000111 + +011000010001 + +100000100101 + +001010001010 + +001100100001 + +001000010010 + +110101110001 + +100111010111 + +100101101001 + +100010101101 + +011101100101 + +011111101011 + +101101011010 + +101001111011 + +111010011101 + +010010001100 + +110001000010 + +101011101010 + +010001010011 + +101111111000 + +001110101000 + +111000000111 + +010111011100 + +101000100100 + +010011010111 + +011000100010 + +111001111101 + +101010010011 + +110011011000 + +100111010101 + +100001101110 + +011011110110 + +110000010111 + +001100101111 + +000110111111 + +111001011011 + +001010100100 + +011111100011 + +011110001110 + +011011111000 + +010101111101 + +100001100011 + +111111011111 + +100010111101 + +110101010100 + +101000111001 + +001001000001 + +110011110011 + +001101001000 + +001100101110 + +010001111100 + +101100111000 + +001011000011 + +110001011101 + +101001011010 + +110011110110 + +011010111101 + +001001100001 + +011010010100 + +010111101011 + +000110010101 + +110010100011 + +001111001101 + +100110111001 + +100010000110 + +010111011011 + +001110011110 + +011010111100 + +110100100010 + +001010001110 + +010011111010 + +101010100111 + +111010100101 + +010000000000 + +000001010101 + +111001000001 + +011110000010 + +001010111111 + +100101000001 + +001000010111 + +101000011011 + +011100010000 + +111000010100 + +010001011100 + +111111010001 + +011010101110 + +011111110001 + +000110101100 + +111000011001 + +001010011100 + +000011011100 + +110111111101 + +001001010101 + +011110000011 + +001111111001 + +110010100000 + +101111010100 + +100100011000 + +010101000111 + +111100110111 + +010010111011 + +001101011111 + +011101011000 + +111111111111 + +010100110110 + +111000001010 + +000100000110 + +000110010000 + +110000011000 + +001000011001 + +011110000100 + +101011100011 + +000011100001 + +110100000011 + +100100011100 + +011110010111 + +101000111111 + +001010001100 + +100010000100 + +011100110110 + +101010011000 + +100000001111 + +010001111111 + +101101001011 + +100010100101 + +011011100000 + +111110100111 + +000100011000 + +011000100001 + +110000111000 + +010011100101 + +000100010011 + +101110101011 + +011111001111 + +010001001101 + +111100011111 + +010000100000 + +001111000101 + +100000010010 + +000111101000 + +101111010000 + +110110010000 + +110111110001 + +111110100000 + +101110001010 + +011111011001 + +000001111101 + +101000010100 + +110111101010 + +001111111011 + +000101010101 + +110110001011 + +100011001010 + +101010010111 + +111100011110 + +010000101101 + +111110000010 + +000100100111 + +000110001100 + +011110000111 + +101110100001 + +110001101010 + +110100010100 + +111010101101 + +110010001001 + +000010011110 + +001100100110 + +011111010011 + +111110000001 + +110111111100 + +011100000110 + +000011100111 + +001101110100 + +100111011101 + +011100010010 + +011001110110 + +110110010010 + +011000011011 + +110111101100 + +101100101100 + +100101111001 + +101001111000 + +101000101001 + +011101010100 + +001110000100 + +011100100000 + +110000001010 + +010001000111 + +001100000110 + +000100111011 + +101001011101 + +011100011110 + +001011001000 + +111101101100 + +001110011111 + +100011100110 + +011000100101 + +111010111111 + +111010001110 + +111011101111 + +010001110011 + +000011010100 + +000000101001 + +010100100001 + +101111111011 + +100111100000 + +111110100101 + +000100001000 + +000101011101 + +110001001110 + +110111001001 + +110111110011 + +111101000111 + +010111000100 + +000010101000 + +000110101101 + +100000001010 + +010111100101 + +110010000100 + +000011010111 + +000101001001 + +100111101110 + +111110011111 + +011001000010 + +110010001101 + +001111110010 + +101110111111 + +100100111101 + +010111100110 + +000101110001 + +010111000001 + +001011101010 + +101101100110 + +110010111111 + +001111101010 + +110110100100 + +101110100101 + +011001110010 + +000000100011 + +110000111100 + +011110001011 + +001110011000 + +000010011011 + +011100011100 + +110001001010 + +100000111010 + +010010000111 + +010010000001 + +001110100100 + +111110111101 + +001100001011 + +110101000000 + +111100010110 + +100010011100 + +001011110011 + +100000111001 + +000101000111 + +100011101011 + +011010001000 + +111111111001 + +100011011001 + +101001010011 + +110001111001 + +001100101101 + +111000111100 + +101000110110 + +000011110011 + +000110010001 + +110110010011 + +011100000000 + +101101110001 + +100001111101 + +110010010000 + +100001011011 + +100010010000 + +000000000110 + +001011001101 + +000001000101 + +011100100010 + +000100010001 + +001111001110 + +100001101001 + +010100011111 + +000001111011 + +110100111110 + +101000101000 + +000101100101 + +011000001101 + +001010101000 + +100100100110 + +101010111101 + +010000111100 + +000000010000 + +101011110100 + +111011111010 + +000011011111 + +011111000010 + +001001001110 + +001100010111 + +011001110100 + +101011000110 + +001000011101 + +111101000010 + +011101001001 + +100011101110 + +110000100101 + +011111101100 + +101000001001 + +011011001110 + +001100011110 + +010110100001 + +011100001000 + +001111011010 + +110001100100 + +000001100011 + +101011110001 + +100000010111 + +010011001000 + +101111101110 + +110001011100 + +110000001011 + +010001100000 + +100111000111 + +110000000100 + +000011010010 + +000101111001 + +000100101000 + +111000111111 + +011110100111 + +111110010010 + +111111000010 + +011111110111 + +101101000100 + +110101001111 + +011000000101 + +011010100110 + +100101101000 + +011001111000 + +010001110101 + +011011110111 + +101110110100 + +100011100101 + +000101100000 + +100101011011 + +010011000110 + +000110110111 + +011110010010 + +101111001111 + +101001110111 + +100001011001 + +101101001111 + +011111110101 + +110001111111 + +010111001011 + +100100001010 + +000100101111 + +110111110111 + +001101010100 + +001011111100 + +100110111101 + +000001001001 + +100111111101 + +011010101101 + +100010100001 + +110101111110 + +010010011100 + +111001111000 + +101011100001 + +011101111110 + +110101101011 + +011100101100 + +110110000001 + +010110110110 + +101011010111 + +110111011011 + +010011101001 + +000001101010 + +000010111000 + +101000101010 + +111100001000 + +001001001100 + +010110000010 + +010010101111 + +101101011111 + +111111010011 + +111111011101 + +100011010000 + +001011100111 + +011001011110 + +110010001110 + +001010010100 + +000010000010 + +100011100001 + +011011100110 + +100001001111 + +111000101010 + +111000110100 + +110100011011 + +111010010101 + +010010011001 + +010111101111 + +001111001100 + +000111010011 + +010010010001 + +011101001100 + +011111011110 + +000101101010 + +001011110111 + +010000100011 + +111101110001 + +110001110010 + +011000010101 + +111111000110 + +100110110101 + +010001000110 + +010000001111 + +100000000110 + +100101101110 + +010101111111 + +111000011010 + +011000000100 + +010100011110 + +001101111111 + +111011000100 + +011011101100 + +011001100011 + +010001000010 + +011001000111 + +001010000101 + +111001011001 + +110100111101 + +100101011010 + +011100010101 + +100000000010 + +110101101110 + +110011011011 + +100010111000 + +010110000100 + +100000011000 + +011001011100 + +010011001110 + +001100010101 + +111100000000 + +001000110001 + +000011010101 + +110101000010 + +001100101001 + +100110011100 + +100001101011 + +111010011011 + +011010110010 + +010101000000 + +000111011111 + +111110110101 + +101010110101 + +111011100100 + +010111111111 + +101010101111 + +000011110010 + +100101001010 + +101000001100 + +000000101100 + +011111010001 + +110101001010 + +101010101110 + +000101000100 + +000110101001 + +010011011110 + +111101101111 + +110100111000 + +011011000111 + +010000001000 + +110000000110 + +010100101111 + +010110001001 + +000111101111 + +101110110001 + +101000101110 + +011101100001 + +010001010110 + +010011111111 + +011111111101 + +010111001010 + +010010011011 + +000010010001 + +101100000010 + +011001101001 + +011100011011 + +011010011100 + +111101110101 + +001001001011 + +011110011101 + +100001010100 + +010010111110 + +010011111101 + +110000101001 + +101110000101 + +110010001100 + +011001110111 + +010011000000 + +000011100101 + +101010101100 + +001000111000 + +110101000001 + +111110001000 + +110000011001 + +100000111000 + +010111110001 + +011011000001 + +101101100100 + +111110111011 + +101000000101 + +011110110110 + +011001100111 + +100101001011 + +001110110100 + +011010100101 + +011110010001 + +110010101110 + +111101001111 + +100100000100 + +100000110001 + +100100110011 + +110011101000 + +000110101011 + +011110010101 + +010101010000 + +111111011110 + +101111111111 + +001111000010 + +100001111001 + +011110010000 + +100101001101 + +111010001100 + +001101010010 + +100100111110 + +011011100001 + +110010101001 + +010101101101 + +101000100101 + +001100101011 + +111111001010 + +001000001011 + +011101100111 + +100101000010 + +111011011110 + +001000000101 + +001000000000 + +000101010110 + +001010111011 + +110010000000 + +010011100001 + +001001011011 + +000101000101 + +010011000111 + +100100101101 + +011110010110 + +100100010000 + +101100100010 + +110101011011 + +000001111111 + +101001110010 + +000100101011 + +110001000000 + +011010111011 + +001111101110 + +100110111111 + +011100000100 + +111100010101 + +100001111111 + +100000110000 + +101111110000 + +100000110101 + +001101101010 + +101010011110 + +011000110010 + +001110110110 + +101000110010 + +000111001111 + +011101111001 + +010000110010 + +101011000000 + +001011001010 + +001101111100 + +010010111001 + +010101100010 + +011001100000 + +011110110011 + +010101011100 + +011000100011 + +001110101010 + +100111110001 + +101110110111 + +110100110101 + +101000110111 + +100011110111 + +010000010010 + +001001111111 + +010100111110 + +101111111101 + +110111101111 + +011010110101 + +101100111001 + +110001111010 + +000101110010 + +110000010110 + +010110100011 + +111011111111 + +001100011010 + +011010000010 + +000101011000 + +101000001000 + +011110110101 + +000001001011 + +010011110001 + +110101100000 + +101011000001 + +101001000010 + +111111100111 + +011010010010 + +100010001100 + +111011011101 + +010110001111 + +001001010011 + +111001001111 + +101000010101 + +110101101111 + +011111111001 + +111001101010 + +100111011010 + +001010010011 + +110001110100 + +011110001010 + +110111010101 + +001001100110 + +001001110011 + +100001110011 + +001001001101 + +100110100100 + +010001101101 + +101110000111 + +001110001111 + +010100111100 + +010110011111 + +100100000011 + +100110011001 + +011101111011 + +011000010000 + +010101101001 + +100010110011 + +000100000010 + +111001001000 + +001110100000 + +110000111011 + +000001100111 + +000110110000 + +111001110000 + +100001011100 + +101101001101 + +111101110011 + +100011011100 + +011010110111 + +111001110001 + +101011111100 + +110010110110 + +011100111010 + +100111110101 + +010011010010 + +011101110111 + +101110010100 + +011100100001 + +001011100011 + +110101010001 + +101000000111 + +000101100100 + +100011000011 + +111011001101 + +101001100111 + +000000000111 + +010100110011 + +011111001101 + +111101110000 + +000111111000 + +110100101011 + +100101110001 + +001010100011 + +110101100001 + +100101010110 + +011100111011 + +100100111001 + +000100110001 + +001101011100 + +000110100110 + +010001001111 + +110000000000 + +001010101101 + +100001100001 + +110010100111 + +000010011111 + +101110011001 + +110010010101 + +010101011101 + +010001110010 + +011101011111 + +100100001011 + +001100011100 + +100111101001 + +110010011001 + +001010000011 + +101010100000 + +111111111110 + +011010101001 + +011110100010 + +110000111101 + +111010100001 + +100111100110 + +000000011010 + +011011001100 + +001101111011 + +011111111010 + +000101110111 + +101100011011 + +100111110000 + +111011010100 + +000100001001 + +010000110000 + +010111110000 + +000110011001 + +101111001110 + +001100010000 + +011011011011 + +001001001000 + +110110111011 + +001000010100 + +010100010000 + +010101110111 + +001111010100 + +001010000010 + +011110011001 + +100001001001 + +001101000101 + +010001010101 + +101110001001 + +011100100111 + +111000001111 + +101001111111 + +101010001011 + +111110110011 + +101101101000 + +011001111010 + +000010011001 + +100000010001 + +101010011111 + +000100011101 + +010010100000 + +000001100101 + +001001011110 + +100101000101 + +011111110110 + +111101111001 + +100011101100