From f77481e018a17a003c83dfe042281909ed23e7fc Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Thu, 1 Dec 2022 06:48:39 -0600 Subject: [PATCH 1/7] 2022 Day 01 Complete! --- 2022/day01/input | 2269 ++++++++++++++++++++++++++++++++++++++++++ 2022/day01/main.go | 44 + 2022/day01/problem | 94 ++ 2022/day01/testinput | 14 + 4 files changed, 2421 insertions(+) create mode 100644 2022/day01/input create mode 100644 2022/day01/main.go create mode 100644 2022/day01/problem create mode 100644 2022/day01/testinput diff --git a/2022/day01/input b/2022/day01/input new file mode 100644 index 0000000..3a0ce64 --- /dev/null +++ b/2022/day01/input @@ -0,0 +1,2269 @@ +3264 +4043 +2537 +3319 +2485 +3218 +5611 +1753 +7232 +3265 +1751 +2233 + +10589 +5121 +11465 +9307 +1347 +9392 +12037 + +6025 +4328 +3982 +4487 +1139 +1440 +2970 +3390 +1844 +5400 +1651 +4109 +3584 +2926 +4297 + +8921 +13298 +12300 +5607 +3304 +5037 + +1729 +10057 + +3538 +3984 +3451 +5638 +2880 +1008 +2940 +6245 +3865 +5060 +2878 +2460 +6557 + +1584 +6391 +3479 +2264 +2683 +3680 +1183 +5121 +6499 +5543 +1192 +4818 + +1337 +8128 +8966 +7601 +7749 +5017 +3251 +1074 +6095 + +11824 +17144 +5396 +15416 + +6244 +6589 +4953 +4250 +1422 +1252 +4555 +5240 +4244 +4088 + +27353 + +6629 +7231 +7673 +7029 +6994 +6347 +6381 +1503 +2145 +1114 +6068 + +3473 +3935 +4054 +3558 +3818 +5370 +4807 +2703 +5407 +2532 +6833 +1675 + +20016 +7587 +13088 + +3477 +3118 +5815 +3551 +2316 +4254 +4814 +5726 +5324 +6096 +3596 +3374 +3975 +4152 +1946 + +4549 +3639 +6338 +6882 +3514 +6488 +2192 +4522 +4370 +3637 +3500 +2964 +1850 + +6900 +5145 +13864 +8145 +4579 + +1984 +1589 +9279 +10987 +5213 + +3997 +1978 +5061 +2710 +2695 +4713 +5930 +3005 +6189 +2619 +6897 +5032 +2374 + +1738 +6817 +1993 +13747 +8574 +13341 + +3869 +1810 +3501 +1366 +4240 +2005 +6102 +6069 +4135 +6667 +1239 +2799 +1900 + +4711 +1330 +9725 +5965 +8271 +11932 + +5319 +6078 +1652 +1958 +1992 +1997 +2824 +6542 +1998 +2713 +6806 +4993 +6569 + +9262 + +3814 +11917 +4812 +1884 +3686 +10993 + +8845 +6032 +9899 +10384 +3834 +2275 + +3559 +2268 +1446 + +2265 +5503 +5056 +2547 +7394 +2514 +8105 +4630 +9392 + +2377 +10479 +3452 +9175 +13773 + +6090 +1467 +2747 +9310 +2839 +9392 +10752 +5771 + +8193 +4139 +4728 +5180 +5884 +9236 + +5721 +10884 +10268 +3255 +2377 +11574 +4498 + +17228 +7306 +6465 + +69149 + +6323 +3435 +2801 +6385 +4192 +1593 +4373 +6654 +7190 +6142 + +10960 +3399 +12251 +8249 +8210 +3571 + +2299 +4349 +1476 +5703 +1497 +4008 +1435 +5043 +2203 +4252 +2407 +5891 + +1419 +1588 + +4266 +2424 +1846 +3265 +5720 +5396 +2013 +2664 +4712 +1040 +3186 +1693 +1537 +3226 + +15568 +16153 +15408 +9417 +15524 + +18017 +4247 +1764 +18920 + +14176 +18583 + +4896 +1029 +14517 +10183 +9726 + +5242 +4156 +2314 +4018 +3542 +1619 +5349 +2524 +2620 +4675 +6491 +5315 +3959 +5215 + +2638 +5346 +6209 +1466 +2854 +6677 +2242 +8476 +5236 + +3827 +4489 +7735 +5656 +11568 +12323 + +8560 +7046 +5453 +4141 +1356 +8940 +8338 +3749 +7297 + +10693 +7191 +8803 +10504 +2033 +6374 +6820 +10316 + +5869 +12102 +12675 +7688 +10906 +12593 + +9028 +8234 +4453 +2117 +7328 +9404 +6664 +7206 +6357 + +3018 +5515 +6479 +1522 +4582 +5881 +4019 +1288 +5288 +4007 +5816 +2354 +5648 +5405 + +4120 +3890 +11718 +5713 +6986 +10362 +5529 + +8243 +2097 +10194 +3023 +11120 +9524 +2052 + +12552 +14406 +3981 +9703 +10329 + +7256 +9424 +4701 + +5694 +1262 +3521 +4194 +3530 +7472 +1773 +1787 +6229 +6608 +5905 +3065 + +3366 + +15198 +25328 + +3805 +4163 +4192 +4013 +2693 +3029 +4559 +5243 +3088 +4804 +1245 +1800 +4999 +3162 +6114 + +3808 +3672 +6397 +3747 +4312 +5015 +4237 +5326 +3961 +1382 +1380 +5517 +1140 + +3360 +6936 +3880 +4242 +7431 +5597 +6195 +5305 +1051 +1015 +1866 +3179 + +17144 +2423 +8330 + +5153 +2301 +4944 +1566 +5647 +6726 +6248 +1537 +6951 +1272 +1177 +2013 + +7595 +9953 +19751 +14200 + +2576 +1684 +6463 +6643 +2911 +1650 +2492 +5726 +4830 +6591 +4477 +6691 +6390 + +5209 +5099 +1115 +5456 +4573 +5954 +4389 +1703 +1595 +1348 +5814 +4031 +3086 +4039 +5445 + +3506 +3956 +1504 +5435 +5660 +6882 +1962 +4891 +2596 +3838 +7206 +5554 + +10423 +4792 +16000 +12857 +5040 + +7410 +2589 +6769 +8168 +7526 +4349 + +5160 +12452 +13889 +7499 +1985 +12491 + +1033 +9259 +6288 +5566 +6134 +11010 +7512 + +5196 +4644 +1825 +5564 +5759 +7134 +5589 +5387 +1328 +2314 +4948 +7354 + +6875 +2105 +3444 +6997 +3962 +1141 +2000 +7561 +6447 +5629 +7035 + +1499 +7160 +5201 +3206 +2719 +5177 +6566 +3455 +3304 +1648 +3273 + +6142 +3697 +2247 +6537 +5579 +7126 +2674 +1842 +1482 +5504 +1105 + +5669 +7401 +8229 +6261 +4378 +5548 +2360 +5703 +7650 +2086 + +23865 +10240 +2321 + +4221 +8067 +1395 +1397 +5776 +5136 +6820 +1428 +3375 +6117 +4467 + +2505 +4307 +5626 +8867 + +4709 +5951 +3811 +4998 +4460 +6243 +1790 +2172 +5694 +6245 +3273 +2664 +4813 +5669 + +5803 +4856 +2508 +6301 +4454 +2430 +4868 +4883 +6211 +1749 +2998 +3450 +2414 +5617 + +9135 +8583 +7582 +8349 +7609 +4434 +8362 +3472 + +44093 + +7933 +3349 +6041 +3238 +5036 +9100 +4252 + +14356 +24185 + +11887 +23333 +16694 + +6324 +1438 +5180 +5329 +6798 +4806 +5285 +4757 +4599 +3897 +2308 +5014 + +1455 +4268 +1903 +1436 +4563 +5135 +4876 +6561 +4776 +3530 +3080 +5724 +5520 + +3419 +2363 +4474 +6069 +2504 +6749 +4094 +5991 +8045 +1302 +5649 + +20607 +13990 + +7588 +9960 +8919 +11254 +6295 +3856 +10295 + +1161 +3773 +1559 +1198 +5967 +5237 +3369 +4437 +7698 +2756 +2639 + +43493 + +18577 +2593 +16336 +13785 + +6567 +2409 +8001 +4173 +11587 +8238 +3023 + +5146 +10077 +2630 +4827 +6199 +3701 +3840 +3068 + +3272 +5212 +3674 +5352 +3129 +4242 +2711 +3064 +4987 +5362 +4858 +3180 +6090 +2265 +4791 + +14702 +1034 + +12170 +8780 +14933 +3727 + +4239 +7116 +1120 +7853 +7862 +5512 +2309 +3094 +6359 + +9172 +12494 +8382 + +8629 +11921 +9629 +11535 +7792 +9996 + +6887 +10548 +3429 +2373 +6208 +5406 +5440 + +2164 +3233 +1512 +1556 +5476 +3462 +4261 +3563 +2409 +6236 +2568 +4638 +4775 +1131 + +27798 +30212 + +5409 +4676 +5445 +2119 +3557 +1135 +6724 +2779 +1324 +2157 +4456 +6329 +2155 + +4084 +1379 +7443 +12904 + +7167 +12163 +9588 +11186 +9015 + +35132 +18974 + +3418 + +12568 +1418 +7691 +12369 +1144 +6141 + +2523 +5150 +2276 +6036 +1492 +5069 +5782 +2999 +4505 +2347 +1234 +5376 +3356 +2489 +1456 + +30181 + +3189 +2572 +5145 +4350 +6403 +1285 +5678 +3796 +3792 +2334 +2710 +3536 +5580 + +2991 +7718 +1798 +5300 +11608 +3376 +11658 + +58468 + +6099 +4433 +7634 +7768 +3804 +5523 +6959 +4752 +8693 +2705 + +5315 +4218 + +5678 +2293 +2385 +2568 +1644 +3332 +5968 +4159 +5935 +2667 +4518 +2823 +4648 +3072 +5644 + +14306 +7557 +15251 +6896 +14250 + +10549 +1662 +10040 +2614 +4843 +1111 +9585 + +9531 +2249 +1949 +8715 +9466 +1471 +7952 + +2585 +8702 +10548 +12849 +5342 +10193 + +21463 +24241 +9125 + +36676 + +18212 +11298 +8690 + +6861 +1095 +4586 +1260 +2795 +3208 +4650 +4147 +5764 +1051 +6882 +5670 + +16681 +22273 +1336 + +3370 +3537 +2062 +4985 +2063 +2339 +5988 +3777 +5822 +2760 +1915 +4668 +4717 +5847 +4598 + +5829 +4829 +4872 +3893 +5320 +1832 +7637 +7137 +6079 +3006 +7422 + +34780 +21066 + +1164 +3444 +8079 +4633 +5030 +8296 +8703 +7929 +8767 +4489 + +1950 +5492 +4920 +3849 +6553 +1802 +1574 +4962 +1671 +2382 +4990 +2511 +3485 + +6003 +8237 + +10793 +12510 +2959 +9397 +6153 + +7943 +1934 +3817 +7937 +6856 +3813 +4408 +8046 +4605 +3994 +8081 + +10589 +11870 +8367 +7889 +10172 +9758 +9447 + +6566 +4971 +4600 +6863 +4212 +5240 +6523 +7979 +2695 +4934 + +6527 +2008 +4595 +7104 +7497 +10199 +6640 +7909 + +7970 +7026 +4812 +4331 +3244 +5260 +3089 +2871 +3915 +1445 + +3182 +9915 +5769 +6470 +10524 +7486 +5041 + +5575 + +6482 +2235 +2834 +3999 +4428 +1713 +3366 +4477 +2282 +1331 +5095 +5268 +5482 +3409 + +21109 + +8502 +2007 +3250 +6035 +6099 +2605 +6323 +5532 +3677 +8194 + +11224 +1704 +10152 +11640 +1018 +7016 +2700 + +12204 + +1191 +5039 +5036 +3778 +1669 +5277 +5345 +3833 +5379 +1286 +2042 +5365 +4518 +5517 + +2750 +4544 +3817 +5392 +1745 +4056 +1557 +1819 +6187 +4867 +6445 +4475 +3026 +5516 + +13176 +25505 +2657 + +29617 +4098 + +1733 +3055 +3730 +5327 +3111 +4912 +1842 +2471 +1964 +2747 +1573 +4097 +5558 +4940 +2065 + +1177 +3510 +6178 +1267 +9395 +1387 +1251 +9112 +1265 + +4073 +8822 + +5585 +4905 +1005 +4303 +2129 +1565 +1577 +1747 +7097 +7135 +2546 + +6368 +6384 +1873 +2027 +2111 +5781 +4392 +1640 +1874 +5147 +6551 +4992 + +11673 +15872 +10747 +5457 + +7576 +6084 +3279 +5582 +8329 +7176 +6561 +5342 +8481 +6333 + +7617 +12916 +8957 +17210 + +4173 +1088 +5981 +2094 +4598 +3192 +3968 +1486 +3888 +4186 +5948 +3764 +3173 +1597 +5057 + +7430 +3183 +20030 +4003 + +5891 +6434 +2213 +1762 +6106 +7550 +6766 +6075 +1119 +4462 + +2460 +7385 +3906 +2805 +2519 +2189 +6803 +2705 +5167 +2972 +6855 +6996 + +3922 +4300 +2172 +7515 +9388 +8687 +5087 +6373 +4001 + +3288 +3888 +3873 +7575 +1902 +3315 +4831 +3272 +4914 + +2120 +3223 +3582 +4864 +1944 +2625 +2666 +1710 +2511 +4362 +3073 +3994 +3171 + +8037 +2890 +3124 +8901 +1411 +6858 +5184 +1294 +7790 + +7884 +7169 +4372 +5820 +6836 +2878 +7608 +2434 +8600 +8117 + +33732 +17277 + +31526 +6202 + +6081 +5669 +1460 +7548 +1054 +3713 +8470 + +7033 +4205 +4404 +4261 +2975 +7865 +5190 +1675 +1349 +7748 + +7345 +6389 +3056 +2777 +12209 +10038 + +5285 +7634 +5875 +6074 +3076 +2687 +4342 +5471 +4113 + +2993 +10714 +5204 +6732 +4746 +12416 + +19555 +17202 +13776 +6280 + +2820 +11278 +6160 +9522 +6585 + +9093 +6397 +10417 +4902 +4899 + +5602 +4917 +4964 +5689 +4316 +4041 +5290 +3223 +4065 +3514 +3552 +5864 +4823 +6481 + +3239 +5151 +2862 +4568 +1964 +3003 +3575 +4445 +6875 +5511 +1591 +1681 +6874 + +7348 +1881 +7702 +6305 +2373 +6320 +1544 +2897 +2784 +5977 +6964 + +1757 +7460 +5212 +3491 +1157 +3753 +1983 +3015 +1298 +2812 +3569 +4680 + +22481 + +8578 +7141 +11229 +5622 +13937 +1699 + +3479 +1258 +2782 +5573 +7720 +6726 +4043 +3059 +5028 +8075 + +3232 +6633 +5344 +1862 +6215 +3674 +2507 +5509 +1982 +4422 +1709 + +2759 +2497 +3959 +1725 +2430 +3256 +1416 +4213 +3452 +6809 +6817 +3151 + +5187 +2502 +6982 +3414 +11460 +12085 +5775 + +1490 +4368 +4135 +1494 +5683 +5443 +5182 +6209 +3240 +1433 +3373 +3048 +5768 +4132 + +22305 +10502 + +6633 +2336 +6714 +3046 +4740 +4650 +2901 +5832 +5690 +4211 +6168 +4901 +2448 + +8640 +11265 +10961 +10744 +10955 + +16404 +15126 +4253 +1372 + +9862 +9547 +20599 + +8872 +3452 +2169 +7757 +5535 +9697 +8147 +8775 + +14862 + +68282 + +4343 +11948 +2346 +16745 + +12892 +12538 +15571 +11814 + +4406 +1323 +3769 +5868 +5023 +6057 +5967 +2891 +2778 +5696 +4376 +2244 +4102 +4721 + +8420 + +8564 +2803 +11178 +17801 + +34616 + +4635 +3716 +6634 +3494 +2905 +4254 +8053 +4871 +5523 +5088 +2928 + +7447 +16669 +9215 +14663 + +4248 +3260 +3347 +5552 +4781 +1715 +5642 +5414 +3223 +3043 +3415 +6463 +5932 + +29980 +37187 + +9703 +7176 +8191 +10002 +7145 +5926 +10760 +7384 + +32599 +26889 + +5843 +1632 +3871 +5645 +9544 +3097 +1820 + +6941 +4838 +5440 +4389 +5309 +5449 +5897 +4418 +4641 +6905 +4951 +2198 +1031 + +4553 +1428 +4164 +2850 +1146 +2496 +4807 +4776 +1573 +2865 +1225 +5182 +2617 +1514 +5828 + +5660 +1567 +5066 +4985 +4683 +4819 +3894 +4432 +5188 +4791 +5916 +3867 +4285 +5863 +5570 + +5394 +3391 +4052 +3230 +4524 +1059 +3685 +1808 +2161 +2662 +3718 +5945 +5094 +4867 +4258 + +28646 +31561 + +11012 +2804 +5719 +5299 +2500 +11059 + +1318 +5060 +1097 +5290 +1059 +3435 +1082 +6242 +1623 +2004 +3567 +1725 +5056 + +4643 +5165 +14091 +6412 +13186 + +5560 + +7978 +4943 +8311 +6023 +15930 + +1972 +7310 +6563 +1748 +6142 +4529 +2106 +7066 +4598 +7301 +2132 +4005 + +1173 +6436 +6047 +5197 +6500 +4588 +5341 +4781 +4750 +4244 +1199 +4931 +4863 +5628 + +10302 +8627 +5405 +6570 +11439 +1447 + +22318 +21787 +9491 + +4710 +4259 +5894 +2971 +4273 +4994 +3414 +4179 +2483 +5404 +1646 +3099 +4035 +4066 + +6374 +8210 +4288 +2226 +3271 +8759 +6171 +7020 +8299 +1958 + +2744 +6690 +1431 +5118 +5387 +7128 +5517 +6299 +7515 +4304 +1846 + +1941 +1309 +1888 +4992 +5942 +4182 +2334 +3283 +4907 +2610 +3373 +2936 +1908 + +3400 +6953 +5233 +5348 +8743 +2799 +7890 +1898 +7783 + +38934 + +3843 +1038 +3364 +6113 +3952 +7192 +5767 +3932 +4462 +2088 +3925 +3990 + +2596 +10301 +11026 +12033 +2542 +13448 + +4798 +6076 +3906 +1617 +8462 +2051 +4827 +1905 +5940 +7175 + +8305 +6626 +1600 +5228 +6332 +1206 +4840 +4600 +5363 + +6425 +13475 +11305 +14037 + +6154 +1016 +3673 +1827 +3628 +4238 +2483 +4762 +3413 +3148 +4659 +3451 +6465 +2363 + +35242 +27022 + +2722 +11484 +12323 +6822 +7951 +4387 + +36866 + +5755 +20057 +5657 + +2491 +2205 +3527 +9556 +8363 +3109 +8618 +1481 +6234 + +7365 +1920 +1578 +3271 +3325 +1263 +1816 +7031 +8020 +2353 +3127 + +8027 +13092 +7531 +12350 + +10451 +9259 +13080 +12849 + +3984 +2140 +2655 +2766 +8665 +2282 +4391 +1435 +4821 +4977 + +2366 + +6198 +17922 +22945 + +2077 +6263 +11643 +11377 +3735 +11634 +5022 + +16598 +7968 + +31400 +22664 + +5414 +5057 +1898 +3063 +4075 +2527 +3502 +6713 +3109 +6376 +2487 +2279 +1057 + +12654 +11007 +2365 +8272 +2895 + +15798 +3536 +14549 + +1066 +1181 +6142 +9592 +3412 +8683 + +3274 +1129 +1645 +4784 +4039 +5447 +4766 +1310 +3346 +4062 +2219 +4290 +4733 +3033 +1306 + +2006 +2898 +3600 +1802 +4760 +5306 +1000 +1279 +1205 +5224 +2652 +4914 +4042 +1559 + +20342 +16632 + +18586 +1712 +11316 +16623 + +7964 +6856 +7863 +7417 +4608 +7216 +4263 +6552 +3187 + +6415 +2442 +2928 +4853 +6899 +6747 +3803 +3522 +5680 +6184 +3326 +5707 +1695 + +61737 + +18154 +7052 + +4635 +3560 +8043 +5917 +9440 +7535 +7213 +7625 + +3389 +1034 +4154 +4872 +4843 +2238 +1174 +2922 +1067 +5715 +5093 +3302 +1076 +3017 +4711 + +9322 +11596 +6347 +11332 +9376 +9230 + +6475 +6492 +4953 +6492 +3935 +2286 +7152 +4659 +5762 +4989 +6438 +1020 diff --git a/2022/day01/main.go b/2022/day01/main.go new file mode 100644 index 0000000..9a454c6 --- /dev/null +++ b/2022/day01/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToStringSlice() + fmt.Println("# Answer") + solve(inp) +} + +func solve(input []string) { + var elves []int + var top1, top2, top3 int + elf := 0 + var sum int + record := func() { + elves = append(elves, sum) + if elf != 0 && sum > elves[top1] { + top3, top2, top1 = top2, top1, elf + } else if sum > elves[top2] { + top3, top2 = top2, elf + } else if sum > elves[top3] { + top3 = elf + } + elf++ + sum = 0 + } + for i := 0; i < len(input); i++ { + if input[i] == "" { + record() + continue + } + sum = sum + h.Atoi(input[i]) + } + record() + fmt.Printf("The elf with the most calories is #%d (%d)\n", top1+1, elves[top1]) + fmt.Printf("The elf with the second most calories is #%d (%d)\n", top2+1, elves[top2]) + fmt.Printf("The elf with the third most calories is #%d (%d)\n", top3+1, elves[top3]) + fmt.Printf("Total by top three: %d\n", elves[top1]+elves[top2]+elves[top3]) +} diff --git a/2022/day01/problem b/2022/day01/problem new file mode 100644 index 0000000..5deb3b5 --- /dev/null +++ b/2022/day01/problem @@ -0,0 +1,94 @@ +Advent of Code + + br0xen (AoC++) 2* + +--- Day 1: Calorie Counting --- + + Santa's reindeer typically eat regular reindeer food, but they need a lot of magical energy to deliver presents on Christmas. + For that, their favorite snack is a special type of star fruit that only grows deep in the jungle. The Elves have brought you + on their annual expedition to the grove where the fruit grows. + + To supply enough magical energy, the expedition needs to retrieve a minimum of fifty stars by December 25th. Although the + Elves assure you that the grove has plenty of fruit, you decide to grab any fruit you see along the way, just in case. + + Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is + unlocked when you complete the first. Each puzzle grants one star. Good luck! + + The jungle must be too overgrown and difficult to navigate in vehicles or access from the air; the Elves' expedition + traditionally goes on foot. As your boats approach land, the Elves begin taking inventory of their supplies. One important + consideration is food - in particular, the number of Calories each Elf is carrying (your puzzle input). + + The Elves take turns writing down the number of Calories contained by the various meals, snacks, rations, etc. that they've + brought with them, one item per line. Each Elf separates their own inventory from the previous Elf's inventory (if any) by a + blank line. + + For example, suppose the Elves finish writing their items' Calories and end up with the following list: + + 1000 + 2000 + 3000 + + 4000 + + 5000 + 6000 + + 7000 + 8000 + 9000 + + 10000 + + This list represents the Calories of the food carried by five Elves: + + • The first Elf is carrying food with 1000, 2000, and 3000 Calories, a total of 6000 Calories. + • The second Elf is carrying one food item with 4000 Calories. + • The third Elf is carrying food with 5000 and 6000 Calories, a total of 11000 Calories. + • The fourth Elf is carrying food with 7000, 8000, and 9000 Calories, a total of 24000 Calories. + • The fifth Elf is carrying one food item with 10000 Calories. + + In case the Elves get hungry and need extra snacks, they need to know which Elf to ask: they'd like to know how many Calories + are being carried by the Elf carrying the most Calories. In the example above, this is 24000 (carried by the fourth Elf). + + Find the Elf carrying the most Calories. How many total Calories is that Elf carrying? + + Your puzzle answer was 72070. + +--- Part Two --- + + By the time you calculate the answer to the Elves' question, they've already realized that the Elf carrying the most Calories + of food might eventually run out of snacks. + + To avoid this unacceptable situation, the Elves would instead like to know the total Calories carried by the top three Elves + carrying the most Calories. That way, even if one of those Elves runs out of snacks, they still have two backups. + + In the example above, the top three Elves are the fourth Elf (with 24000 Calories), then the third Elf (with 11000 Calories), + then the fifth Elf (with 10000 Calories). The sum of the Calories carried by these three elves is 45000. + + Find the top three Elves carrying the most Calories. How many Calories are those Elves carrying in total? + + Your puzzle answer was 211805. + + Both parts of this puzzle are complete! They provide two gold stars: ** + +References + + Visible links + . https://adventofcode.com/ + . https://adventofcode.com/2022/about + . https://adventofcode.com/2022/events + . https://teespring.com/stores/advent-of-code + . https://adventofcode.com/2022/settings + . https://adventofcode.com/2022/auth/logout + . Advent of Code Supporter + https://adventofcode.com/2022/support + . https://adventofcode.com/2022 + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/support + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022/leaderboard + . https://adventofcode.com/2022/stats + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2018/day/25 + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/day/1/input diff --git a/2022/day01/testinput b/2022/day01/testinput new file mode 100644 index 0000000..2094f91 --- /dev/null +++ b/2022/day01/testinput @@ -0,0 +1,14 @@ +1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000 From b9ab5f5787b4b4d8c2643ff8365ab1bdcdde6b98 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Fri, 2 Dec 2022 07:38:32 -0600 Subject: [PATCH 2/7] 2022 Day 02 Complete! --- 2022/day02/input | 2500 +++++++++++++++++++++++++++++++++++++++++ 2022/day02/main.go | 56 + 2022/day02/problem | 77 ++ 2022/day02/testinput | 3 + 2022/day02/testinput2 | 9 + 5 files changed, 2645 insertions(+) create mode 100644 2022/day02/input create mode 100644 2022/day02/main.go create mode 100644 2022/day02/problem create mode 100644 2022/day02/testinput create mode 100644 2022/day02/testinput2 diff --git a/2022/day02/input b/2022/day02/input new file mode 100644 index 0000000..0b2139a --- /dev/null +++ b/2022/day02/input @@ -0,0 +1,2500 @@ +C Y +B Z +B Z +C Y +B Y +C Z +C Z +C Y +B Z +C Z +C X +C Y +C Z +C Y +C Y +B Z +A Y +C Z +C Z +C Z +B X +B Z +C Y +A X +C X +C Z +C Y +C Z +C Z +C Z +C Y +C Y +A X +C X +C Z +B Z +B Z +B Z +B Z +C Z +C Y +C Z +B Z +A Y +A X +C Z +C Y +C Z +C Y +C Z +A X +C Z +C Z +C Z +C Z +C Y +C Y +C Z +C Z +C Z +C Z +B X +C Y +B Y +B X +A X +C Y +C Z +C Z +C Y +C Z +C Z +A Y +C Y +C Z +C Y +B Z +C Z +C Y +B Z +B Z +C Z +C Y +C Y +C Z +C Z +C Y +C Z +C Y +C Y +C Y +C Y +B X +C Z +C Z +C X +C X +C Z +B Z +A Y +C Y +A Y +C Y +C Z +C Y +C Z +C Y +B Z +C Z +C Z +C Y +A Y +C Z +B Z +C Z +C Z +C X +C Z +C Z +C Z +C Z +C Z +C Z +B Z +C Z +C Y +B Z +C Y +C X +A X +C Z +A Y +C Y +C Z +B Z +C Z +B X +C Z +C Y +C Z +B Z +C Z +C Z +C Y +C Y +C Y +B Z +C Y +C Y +B X +C Z +B Z +B Z +C Z +C Z +C Z +C Z +C Z +A Y +C Y +C Z +C Y +B Z +B Z +C Y +C Z +B Z +C Y +C Y +C Z +B Z +C Y +C Z +C Y +B Z +C Z +A X +C Z +C Y +C Z +B Z +C Z +C Y +C Y +C Y +C Y +C Y +C Z +C Z +A Y +C Z +C Z +C Z +C Y +B Z +C Z +B Z +C Z +C X +C X +B Z +C Y +C X +C Y +B Z +C Y +C X +C Z +C Z +C Y +C Z +C Z +B Z +A X +C Y +C Z +C Z +C Z +C Y +C Y +C Z +C Z +C Y +C Z +A Y +C Z +B Z +C Z +A Z +C Z +C X +B Z +C Y +C X +C Z +C X +C Y +A Y +C Y +C Y +C Z +C Z +C Y +B Z +A X +C Z +C X +C Y +B Z +C X +C Z +C Y +C Z +C Y +A Y +B Z +C Z +C Y +C Y +C Z +B Y +C Y +B X +C Y +C Y +C Z +C Z +C Z +C Y +C Y +C Y +B X +C Z +C Z +C Z +B X +A Y +C Z +C Z +A Y +B Z +C Z +A X +C Z +C Z +C Z +C X +C Y +C Y +C Z +C Z +C Z +C Z +C Z +C Z +C Y +B Y +C Z +C Z +C Y +C Z +C Z +C Y +C Z +A Y +C Y +C Z +B Y +A X +B Z +C Z +C Z +C Z +A Z +C Z +B Z +B Z +C Y +B X +C Z +C Y +C Z +C Y +A Y +C Z +C Z +C Z +B Z +B Z +C Y +C Z +C Y +C Z +C X +C Z +C Y +C Y +C Y +C X +B Y +C Y +B Z +C Z +C Z +C Y +C Y +C Z +C Z +C Y +C Y +C Z +C Z +C Z +C Y +C Y +C Z +C Z +C Y +B Z +C Z +C X +A Y +B Z +C Z +C Z +B Z +C Z +B Z +C Y +C X +C Z +C Z +A Y +C X +C Y +A X +C Z +C Z +C Z +B Z +C Z +C Y +B Z +B Z +C Z +C Z +A Y +C X +C Z +B Z +C Z +C Z +C Z +B Z +C Z +C Z +B Z +C Z +C Y +C X +C Z +C Z +A Y +C Z +C Z +C Z +A Z +B X +C X +C Y +C Z +C Y +C Y +C X +C Z +B Z +C Z +A Y +C Y +C Z +A X +B Z +B Z +A Y +C Z +C Z +C X +C Z +C Y +C Y +C Z +C Y +B Y +C Y +C Z +C Y +C Z +C Z +C X +C Z +C Y +C Z +C Y +A X +C Z +B Z +B Z +C Y +C Y +C Y +C Y +C Z +C Y +A X +C Z +B Z +C Y +C Y +C Z +C Z +C Y +C Z +C Z +C Z +C Z +C Z +B Z +C Z +C Y +C X +C Z +C Z +B Z +C Z +C Z +C Z +B Z +C X +B Z +A Z +C Z +C Y +C Y +C Y +B Z +C X +A Y +C X +C Y +B Z +C Y +B Y +A X +B Z +C Z +B Z +C Y +B Z +B X +C Y +C Z +C Y +C Y +C Z +B Z +C Z +C Z +C Y +C Z +B Z +B Y +C Z +C Y +A Y +C Z +C Z +A X +C Z +B Z +C Z +A Z +C Z +C X +C Z +C Z +C Z +C Z +C Z +C Z +B Z +C Y +B Z +B X +C Y +C Z +B Z +C Z +C Y +C Y +C Y +B Z +B Y +C Y +C Y +C Z +C Z +C Z +B Y +C Y +C Y +C Y +C Z +A X +C Y +B Z +C Z +A X +A X +C Z +C Y +B X +C X +B Y +C Y +C X +A Y +C Z +C X +C Z +B X +A Y +C Y +C X +B Z +C Y +C Z +C Z +C X +C Y +C Z +C Z +C Z +C X +A X +C Y +A Y +C Z +C Z +C Z +C Y +C Y +C Z +C Z +C X +C Z +C Y +B Z +B Z +C X +C Z +B Y +C Z +B Z +C Z +C Z +B X +C Y +A Y +C Z +C Z +A Y +C Z +C Y +C Y +C Z +C Z +C Z +C Z +B Y +C Y +C Y +C X +C Z +C Z +C Z +B Y +A Y +A X +A X +C Z +C Z +C Y +A Y +C Z +C Z +B Z +C Y +C Z +C Z +A X +C Z +C Z +C Z +C X +C Y +C Z +C Y +A X +C Y +C Z +A Y +C Z +C Z +B Z +B Z +C Z +A Y +A X +C Y +C Z +C Y +A Z +C Y +A Y +B Z +C Z +C Z +C X +A Y +C Y +C Y +C Y +B Z +B X +A X +C Y +B Z +C X +C Z +C Z +C Y +C Y +C Y +C Z +C Z +A Y +C Z +C Z +C Z +C Z +C Y +B Z +C Z +C Z +B Z +C Y +A Y +C Z +C X +B Z +C Z +A X +C Y +A Y +C Z +C Y +A X +A X +B X +C Y +C Z +C Z +C X +B X +C Z +C Z +A X +C Z +C Z +B Z +C Z +C Y +C X +C Z +A X +C Z +C Y +C Z +C Y +B Z +C Y +A X +C Z +A X +C X +C Z +B Z +C Y +C Z +B Z +B X +C Y +C Z +C Y +B Z +C Y +C Z +B Z +B Z +C Y +B Y +C Z +C Y +B Z +B X +B Z +A Y +C Z +C Y +B Z +C Z +C Z +C Z +C Z +C Y +C Z +C X +C Z +C Z +C Y +C Z +C Z +C Z +C Y +B X +C Y +C Z +C Y +C Z +A Y +C Y +C Y +B Y +C Z +C Z +B Z +A Y +C Y +C Y +A Z +B Z +C X +B Z +B X +C Z +C Y +C Y +C Y +B Z +C Z +B Z +C Z +C Z +A X +C Z +B X +C Y +C X +C Z +C Y +C Z +C Z +B Z +C Z +C Y +A X +C Z +C Y +C Z +B X +C Y +C Z +C Y +C Y +C Y +A Y +B Z +C Z +C Z +C Z +C Z +B Z +C Z +C X +B X +B Z +A X +C Y +B Y +C Z +C Z +C X +C Z +B Z +C Y +C Y +B Y +C Y +C Z +C Z +C Y +A Z +C Y +B Z +B Z +C X +C X +C Y +C Z +C Z +C Z +C Z +A Y +C Z +B Z +A Y +C Z +C Y +A X +B Z +C Z +C Z +C Z +C Z +B Z +C Y +B Z +C Y +C Y +A X +B Z +C Y +B Z +B Z +A Z +A Y +C Y +C Y +C Z +C Z +A X +C Z +C X +C Y +C Z +C Y +C Z +C Z +C Z +C Y +A X +C Z +C Y +C Z +C Z +C Y +C Z +C Y +C Y +A X +B Z +C Y +C Z +C Z +C Y +C Y +C Z +C Z +A Y +C Y +B Z +B Z +C X +B Z +B Z +C Z +B Z +C Z +C Y +C Y +C Y +A Y +C Z +C Z +C Y +B X +C Y +C Y +C X +C Y +C Z +B X +C Z +B Z +C Y +C Z +C Z +B Z +C Z +C Y +C X +B Z +C Y +C Z +C Z +C Z +A Y +C Z +C Z +C Y +C Z +C Y +C Y +C Z +C Y +A X +C Y +C Z +C Z +C Z +C Y +C Y +C Z +B Z +C Z +B Z +C Z +C Y +A Y +C Z +C X +C Y +C Y +B Z +C Z +C Z +B Z +C Y +C Y +C Y +C Z +C Z +B Z +C Z +B Z +B Y +B Z +A Y +C Y +C Y +C Z +C Y +C Z +C Y +B Z +C Z +C Z +C Z +C Z +B X +B Z +C Z +B Z +C Y +A X +C Y +B Z +B Z +B Z +C Y +B Y +B Z +C Z +B Z +B Z +C Z +A Y +C Z +C Z +C Z +B Z +C Z +C Z +A Y +B Z +A Y +A Y +C Y +C Z +C Z +C Z +C Y +C Z +C Z +B Z +C Y +C Y +A X +C Y +B Z +C Y +B Z +C Y +A X +C Z +C Z +C Y +C Z +B Z +C Y +C Z +B Z +C Y +B Z +C Z +C Y +C Y +C Y +C X +C X +C Z +C Z +A Z +B X +C Y +A Y +C X +A Y +C Y +B Y +A X +A X +C Y +C Z +C Z +B Z +B Z +C Z +B Z +B Z +B Z +C X +C Z +C Z +B Z +C Z +C Y +C X +B Z +C X +B Z +C Z +C Z +B Z +C Y +C Z +C Y +B Z +B Z +C Y +A X +C Y +C Z +B Z +C Z +C Y +C Z +C Y +C Y +C Z +C Y +C Z +C Z +A Y +C Y +C Y +C Y +A Z +B Z +C Z +C Y +C Z +C Y +B X +C Z +A X +B Y +C Z +C Z +C Z +C Y +C Z +C Z +C Z +C Y +B Y +C Y +C Z +C X +C Y +B Z +A Y +B Z +C Y +C Y +C Z +C Z +A X +C X +B Z +C Z +B Z +B Z +C Z +C Y +C Y +C Y +B Z +C Y +A Y +C Z +C Z +C Z +C Z +C Z +B Z +C Z +C Z +C Z +A X +A X +C Y +B Y +C Z +B Z +B Z +A Y +C Z +B Z +C Y +C Z +B Z +C Z +C Y +C Z +C Y +C Z +A Y +C Z +C Z +B Y +A Y +C Z +C Y +B Z +C X +A Y +B Z +C Z +B Y +C X +C Y +C Y +C Z +C Y +B Y +C Z +B Z +C Y +C Y +C Z +C Z +B Z +A Y +C X +C Y +C X +B Z +C Z +C Z +C X +C Y +B X +C Y +C Z +C Y +C Y +C Z +C Z +B Z +C Y +C Y +A X +B Z +B Z +B Z +B Z +C Y +C Y +C Z +A Y +B Z +C Y +C Y +C Y +C Y +C Y +C Z +C Y +C Z +C Z +C Y +C Y +C Y +C Z +C Z +C Z +C Z +C Z +A X +C Y +B Z +C Y +A Y +C Z +B Z +C Y +A Y +C Y +B X +C Y +C Z +B Z +C Z +C Z +B Z +C Z +B Z +C X +C Y +B Z +C Z +B Z +A Y +C Z +B Z +C Y +C Y +C Y +C Z +C Z +B Z +C Z +B Z +A Y +C Y +B Z +B Z +C Z +C Y +C X +C Y +C Z +C Z +C X +A Y +A Z +C Z +A Z +C Z +C Z +C Z +C Z +C Y +C Z +C Y +C Y +C Y +A X +C Y +C Z +C X +C X +C Y +A Y +C Y +C Z +C X +C Z +B Z +C Y +A X +C X +C Z +C X +C Y +C Z +B Z +C Z +B X +C Y +C Z +A Y +C X +B Z +B Z +C Z +C Z +C Z +B Z +C Z +B Z +C Z +B Z +C X +A X +B X +C Y +C Z +C Y +C Z +C Z +B Y +C X +B Y +A X +A X +C Y +C Z +C Y +C X +B Z +C Z +C Z +C Z +C Z +C Y +C Z +C Y +C Z +C Z +C Z +C Y +C Y +C Z +B Z +B X +A X +B Z +C Z +C Z +B Z +B Z +B Z +C Y +C Y +C Y +C Y +C Z +B Z +C Y +C Z +C Z +C Y +B Z +C Z +C Z +C X +C Z +C Y +C Y +C Z +C X +C Z +C Z +B Z +B Z +C Y +A X +C X +C Y +C Z +C X +C Y +B Z +C Z +B Z +C Y +C Y +C Z +C Z +C Z +C Z +C Z +C Z +C Y +C Y +C Z +A X +C Z +C Z +C Z +C Z +C X +C X +C Z +B X +C Z +C Z +C Z +C Z +C Z +A X +C Z +C Y +C Y +B Z +B Y +C Z +C Z +A X +C Y +B X +B Z +C Z +C Y +C Z +B Z +C Z +C Z +C Y +C Z +C Z +C Z +C Z +C Z +B Z +C Y +C Z +B Z +C Y +C Y +C X +C Y +A X +C Z +C Y +C Y +C Z +C X +C Z +B Z +B Z +A Y +B Z +C X +C Y +C Z +C Y +B X +B X +C Y +C Z +C Z +A X +C Z +C Y +C Z +C Z +B Z +B Z +C Z +C Z +C Z +C Z +A X +C Y +A Z +C Y +C Z +B Z +C Y +C X +C X +A X +C Z +C Y +C Z +C Z +C Y +B Z +C Y +C Y +C Z +C X +B Z +C Y +C Y +C Y +C Z +B Z +B Z +B Z +B Z +C Z +B Z +B Z +B Z +C Y +B Z +B Z +A Y +C Z +C Z +C Y +B Z +C Y +C Y +C Y +C Y +A X +C Z +A Y +C Y +C Y +C Y +C Z +B X +C Z +B Z +C X +C Y +B Z +C Y +C Z +C Z +C X +B Z +B Z +C Y +B Z +C Y +C Z +C Z +C Y +A Y +C Y +A Z +B Z +C Z +B Y +C Y +C Y +B Z +C Y +C X +C Y +A Y +B Z +C Y +A Y +C Y +C Y +B Z +C Z +C Y +C Z +C Y +C Z +C Z +A X +A X +C Y +B Z +C Y +C Z +C X +A X +C X +C Z +C Z +B Y +C Z +B Z +C Y +A X +C Z +B Z +C Z +C Z +C Z +C Y +C Y +C Z +B Z +C X +B Y +B Z +B Z +C Y +B Z +C Z +C X +C Y +C Y +C Z +C Y +C Y +B X +B Z +B Z +B Z +B Z +C Z +B X +C Z +C Z +A Z +C Z +A Y +C Z +C Y +C Y +B Z +C X +C Y +C Y +B Y +C Y +B Z +C Y +C Y +A X +B Z +C Z +A X +C Y +C Z +C Z +A Y +C Z +C X +C Z +C Y +C Z +C Y +C Y +C Z +B Z +A Y +C Z +B Z +C Z +C Z +A Z +C Z +C Y +C Z +C Z +C Z +B Z +A Y +C Y +C Y +C Y +C Z +B Y +B Z +C Y +C Z +C Z +C Y +C Y +A Z +B Z +C X +B Z +C Z +C Y +A Y +B Z +C Y +C Y +B Z +C Z +C Z +C Z +B Z +C Z +C Z +C Z +C Z +C Z +A X +A X +B Z +C Z +C Z +C Z +B Z +C Z +B X +C Y +C X +C X +C Y +C Z +C Z +A X +A X +C Z +C Z +C Z +C Z +C Z +C Y +A X +C X +C Y +C Y +C Y +A X +C Y +B Z +C Z +C Z +A Y +C Y +C Z +C Z +B Z +C Y +C Y +C Y +C Z +B Z +C Y +B Z +C X +C Y +A Y +C Y +B Z +B Z +C Z +C Z +A X +B Z +C Z +C Z +C Z +C X +C Y +C Y +C Z +C Y +C Y +B Y +C Z +B Z +A Z +C Z +C Y +C Y +B Y +C Z +B Z +A Y +C Y +A Y +C Y +C Y +C Z +C Z +C Y +C Y +C Z +C Y +C Z +C Y +C Y +C Z +C Y +C Z +C X +C Z +C Z +C Y +B Z +C X +B Z +B Z +C X +B X +C Z +C Y +B Z +C Z +C Y +C Z +C X +C Z +C Z +C Z +A Y +C Z +C Y +C X +C Y +C Z +C Z +C Y +B Z +C Z +B X +C Y +C Y +C X +C Z +C Z +C Y +C Z +B Z +C Z +C X +B Z +C Y +C Z +B Z +C Y +B X +C Z +C Z +C Z +C Y +C Z +C Y +A Y +C Y +C Y +C Z +C Z +B Z +B Z +C Y +C X +C Z +C Z +C Z +C Z +A X +C Y +C Y +C X +C Z +A X +A Y +C Y +A Y +C Y +C Y +C Z +C Z +C Y +B Z +C Y +B Z +C Y +C Y +A X +C Y +C Z +B Z +A Y +A Y +C X +B Z +B Z +C Z +C X +C X +C Y +C Y +C X +A X +C Z +C Y +B Z +C Z +C Z +A Y +C X +C X +C Z +C Y +A Y +C Z +C Z +B Z +C Z +C X +C Z +A Y +C Y +C Y +C Y +B X +C Z +C Y +B Y +C Y +C Z +C Z +A Z +C Z +A Y +B Z +C Y +B Z +C Y +C Y +C Z +C X +A Y +C Z +A Z +C Y +C Z +C Y +C Y +C Z +B Z +A Y +C Y +A Y +B Z +C Z +C Z +C Z +C Z +C Z +C Z +C Z +C Y +B Z +B Z +C Y +C Z +A Y +C Z +C Z +C Z +C X +C Z +A X +B Z +C Z +C Z +B Z +B Y +C Z +C Z +C Z +C Z +C Z +C Z +B Z +C Z +A X +C Y +C Z +B Z +B Z +B Z +B Z +C Z +B Z +C Y +A X +B Z +C Z +B Z +B Z +C Y +B Z +C Y +C Z +A Y +C Y +C X +C Y +C Y +B Z +C Y +C Z +C Y +C Z +B Z +C Z +B Z +A Y +C Z +C Y +C Y +B Z +C Z +C Y +C Y +C Z +A Y +C Z +C Y +C Z +B Z +C Z +C Z +C Z +C Y +C Z +C Z +B Z +C Z +C Z +C Z +B Z +C Z +C Z +C Y +C Y +A X +C Z +C Z +B Z +C Z +C Z +C X +C Z +C X +A X +B Z +A X +C Z +C X +C Y +C Z +B X +C Y +C X +B X +C Y +B X +C Y +C Z +B Z +C Y +C Y +C Z +C Z +B Z +C Z +C Y +C Z +B Z +C Z +A Y +B X +C Y +C Z +A X +C Y +A X +C Z +C Z +C Z +B X +B Z +B Z +B Z +B Z +C Z +B Z +A Z +C X +B Z +C Z +C Z +C Z +B Z +B X +C Z +C Y +C Y +C X +C Z +C Y +C Z +B Z +B Z +A Y +A Y +C Z +B Y +C Z +B Z +C Y +B Z +C Z +B Z +C Z +A Y +C Z +C X +C Z +C Y +C Y +C Z +B Z +C Y +C Z +C Z +C Z +A Y +C Z +C Z +C Y +C Z +A Y +A Z +B X +C Y +C Z +C Z +C Z +C Z +B Z +C Y +A X +C Z +A Y +C Z +C Z +C Z +C Y +B Y +B X +B Z +C Z +A X +A Y +C Z +C Y +C Z +B X +B Y +C Y +C Y +C Z +C Z +C Z +B Y +C Z +C Y +C Z +C Y +C Y +C Y +B Z +B Z +A Y +C Y +A X +C Z +C Z +B Z +A Y +B Z +C X +C Y +B X +C Z +A X +C Z +C Y +C Y +C Y +C Z +C Z +C Y +A Y +C Z +C Z +C X +C Z +C Y +C Z +C Z +A Y +A Y +B Z +C Y +B Z +C Z +C X +C Z +B Z +A Y +C Z +B Z +C Y +C Z +C X +C Y +A X +C Z +B Z +C Y +B Y +C Z +B Y +A Y +C X +C Z +A Y +B Z +A X +C Y +C Z +C Z +C Y +C Y +B X +A Y +C Z +C Y +C Z +C Z +B Z +C Z +B Z +C X +C Y +A Y +C Z +C Y +C Z +C Z +C Y +C Z +C Y +C Y +B Z +C Z +C Z +C Z +B Z +C Y +C Z +C Z +C Z +A X +C Y +C Y +A X +A X +C X +C Z +B Z +C Z +C Y +C X +C Z +B X +C X +A X +C X +C Y +A Y +C Y +C Z +C Z +C Y +C Z +A X +B Z +C Z +C Y +C Z +C Y +C Y +C Y +C Z +C Y +B X +C Z +C Y +C Y +C Y +B Y +C Z +C Z +C Z +C Y +B Z +C Y +A X +B Z +C Y +C Y +C Z +B Z +B Z +C Z +B Z +B Z +A Y +C Z +C Z +C Z +C Y +C Z +C Z +C X +B Z +C Y +B Z +B Z +B Y +A Y +C Z +C X +C Z +C Z +C Z +C Y +C Z +C Z +C X +A X +B X +A Y +A X +C Y +C Y +C Y +B X +A Y +C Z +C Y +A Y +C Z +C Y +C Y +C Z +C Z +B X +C X +C Z +C Z +B Z +C Y +C Z +C Z +C Y +C Z +C Z +B Z +C Y +C Z +B Z +C Y +C Y +C Z +C Y +C X +C Z +C Y +A Y +C Z +B Z +C X +C Y +B Z +B Z +C Z +C Z +C Y +C Y +C Z +B X +A X +C Z +C Z +A Y +C Y +C Z +B Z +C Y +A X +C Y +C Z +C Z +C Y +C Z +C Z +C Z +B Z +B Z +C X +C Y +C Z +C Z +C Z +C Z +A X +C Y +C Y +C Z +B Z +C Y +C Y +A X +C X +B Z +C Y +C Y +B X +C Y +C Z +C Z +C Y +C Y +C Z +C Y +C Z +C Z +C Y +C Z +C Z +B Z +C Z +C Z +C Z +C Y +C Y +C Z +C Y +C Z +B X +A X +C Y diff --git a/2022/day02/main.go b/2022/day02/main.go new file mode 100644 index 0000000..53d4334 --- /dev/null +++ b/2022/day02/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "fmt" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToStringSlice() + fmt.Println("# Part 1") + fmt.Printf("Score: %d\n", part1(inp)) + fmt.Println("# Part 2") + fmt.Printf("Score: %d\n", part2(inp)) +} + +func part1(input []string) int { + score := 0 + for i := range input { + first, second := input[i][0], (input[i][2] - 23) + score += int(second - 'A' + 1) + switch second - first { + case 1, 254: + score += 6 + case 0: + score += 3 + } + } + return score +} + +func part2(input []string) int { + score := 0 + for i := range input { + against, to := input[i][0], input[i][2] + choose := byte(64) + switch to { + case 'X': + choose = (against - 1) + if choose < 'A' { + choose = 'C' + } + case 'Y': + score += 3 + choose = against + case 'Z': + choose = (against + 1) + if choose > 'C' { + choose = 'A' + } + score += 6 + } + score += int(choose - 64) + } + return score +} diff --git a/2022/day02/problem b/2022/day02/problem new file mode 100644 index 0000000..5b74b8d --- /dev/null +++ b/2022/day02/problem @@ -0,0 +1,77 @@ +Advent of Code + + br0xen (AoC++) 4* + +--- Day 2: Rock Paper Scissors --- + + The Elves begin to set up camp on the beach. To decide whose tent gets to be closest to the snack storage, a giant Rock Paper Scissors tournament is already in progress. + + Rock Paper Scissors is a game between two players. Each game contains many rounds; in each round, the players each simultaneously choose one of Rock, Paper, or Scissors using a hand shape. Then, a winner for that round is selected: Rock defeats + Scissors, Scissors defeats Paper, and Paper defeats Rock. If both players choose the same shape, the round instead ends in a draw. + + Appreciative of your help yesterday, one Elf gives you an encrypted strategy guide (your puzzle input) that they say will be sure to help you win. "The first column is what your opponent is going to play: A for Rock, B for Paper, and C for + Scissors. The second column--" Suddenly, the Elf is called away to help with someone's tent. + + The second column, you reason, must be what you should play in response: X for Rock, Y for Paper, and Z for Scissors. Winning every time would be suspicious, so the responses must have been carefully chosen. + + The winner of the whole tournament is the player with the highest score. Your total score is the sum of your scores for each round. The score for a single round is the score for the shape you selected (1 for Rock, 2 for Paper, and 3 for Scissors) + plus the score for the outcome of the round (0 if you lost, 3 if the round was a draw, and 6 if you won). + + Since you can't be sure if the Elf is trying to help you or trick you, you should calculate the score you would get if you were to follow the strategy guide. + + For example, suppose you were given the following strategy guide: + + A Y + B X + C Z + + This strategy guide predicts and recommends the following: + + • In the first round, your opponent will choose Rock (A), and you should choose Paper (Y). This ends in a win for you with a score of 8 (2 because you chose Paper + 6 because you won). + • In the second round, your opponent will choose Paper (B), and you should choose Rock (X). This ends in a loss for you with a score of 1 (1 + 0). + • The third round is a draw with both players choosing Scissors, giving you a score of 3 + 3 = 6. + + In this example, if you were to follow the strategy guide, you would get a total score of 15 (8 + 1 + 6). + + What would your total score be if everything goes exactly according to your strategy guide? + + Your puzzle answer was 13268. + +--- Part Two --- + + The Elf finishes helping with the tent and sneaks back over to you. "Anyway, the second column says how the round needs to end: X means you need to lose, Y means you need to end the round in a draw, and Z means you need to win. Good luck!" + + The total score is still calculated in the same way, but now you need to figure out what shape to choose so the round ends as indicated. The example above now goes like this: + + • In the first round, your opponent will choose Rock (A), and you need the round to end in a draw (Y), so you also choose Rock. This gives you a score of 1 + 3 = 4. + • In the second round, your opponent will choose Paper (B), and you choose Rock so you lose (X) with a score of 1 + 0 = 1. + • In the third round, you will defeat your opponent's Scissors with Rock for a score of 1 + 6 = 7. + + Now that you're correctly decrypting the ultra top secret strategy guide, you would get a total score of 12. + + Following the Elf's instructions for the second column, what would your total score be if everything goes exactly according to your strategy guide? + + Your puzzle answer was 15508. + + Both parts of this puzzle are complete! They provide two gold stars: ** + +References + + Visible links + . https://adventofcode.com/ + . https://adventofcode.com/2022/about + . https://adventofcode.com/2022/events + . https://adventofcode.com/2022/settings + . https://adventofcode.com/2022/auth/logout + . Advent of Code Supporter + https://adventofcode.com/2022/support + . https://adventofcode.com/2022 + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/support + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022/leaderboard + . https://adventofcode.com/2022/stats + . https://adventofcode.com/2022/sponsors + . https://en.wikipedia.org/wiki/Rock_paper_scissors + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/day/2/input diff --git a/2022/day02/testinput b/2022/day02/testinput new file mode 100644 index 0000000..db60e36 --- /dev/null +++ b/2022/day02/testinput @@ -0,0 +1,3 @@ +A Y +B X +C Z diff --git a/2022/day02/testinput2 b/2022/day02/testinput2 new file mode 100644 index 0000000..7872bf6 --- /dev/null +++ b/2022/day02/testinput2 @@ -0,0 +1,9 @@ +A X +B X +C X +A Y +B Y +C Y +A Z +B Z +C Z From e1bfbcde97a68b7df047de77ed50c00e4432edd4 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Sat, 3 Dec 2022 07:14:41 -0600 Subject: [PATCH 3/7] 2022 Day3 Complete! --- 2022/day03/input | 300 +++++++++++++++++++++++++++++++++++++++++++ 2022/day03/main.go | 74 +++++++++++ 2022/day03/problem | 140 ++++++++++++++++++++ 2022/day03/testinput | 6 + 4 files changed, 520 insertions(+) create mode 100644 2022/day03/input create mode 100644 2022/day03/main.go create mode 100644 2022/day03/problem create mode 100644 2022/day03/testinput diff --git a/2022/day03/input b/2022/day03/input new file mode 100644 index 0000000..53d6524 --- /dev/null +++ b/2022/day03/input @@ -0,0 +1,300 @@ +lDDWVvlVVQfDMlWjGJTRjQCgTGLCLj +ZLZpwzLBhwZhSLBsjntGCtgJRjbnJgSG +qppdZzzsdsmZphrNsNwZhllDHLcVVDWFPvFWcWdFlv +ztdhgJDBJghmQtPFQPpmbw +lVlLRcnfllcfVcccGnSQVLcsTPFbpwsPFspTSqmbpswpbF +cCHRGcGcCRGlGrGcVGnrdWHWBDzBNhhQZWWNBhJz +NfnSSQpdnRSSpvWdSsjZDGNDjGDwTGTjHG +wlPzPqzPFbMmqPCFCJmbsjbHLDDHDZjDjbGHsT +gwMlgmtmPcqVVvhVnvcRnn +cBNBBCHhbhNhblBcCCvcBHSwTwDQSqRwDQpDRsjHST +dPmzMVWdmmMnnZJtZVdqjTSrjTjrpQrsTTVwQRSj +qzmZMmdZPtnGqclblGlbGvgBFc +ZfpmNDfRhzbbqDnD +SFtFjTTZVTFvVTjHrsVvqGBJqhnSSnbJznLGJwJq +TjdPPtdMPPWCcZgW +qsbmGCsjHNhmhmhzTDznpnlQZlbWlZ +LTSSfSvggVVgBgfLtvvtTSczzpWnZQZnlnzpBcnWpQWc +FrLvrrrVPgdPftSHHdNsjTHjmGThhm +wGQlMjvMwpvjvZjZTZlWjplWJJTggDTgfCnntPgTJPbtPgSP +qNhJmcVmdJqhHnPnDNtnPDCg +LrrchqhRdLVzRdmhJcFFQWGGMjpGlvZzlQQv +ZqZMbZMfQZptpjlF +PJCggvHlwWHvSSvCJNvSPvDBtFDQThFQjtRQhhFTsVThQtsF +PwWCnBBCClcMMznMdG +rNwwQJrJrnQswrQrRRwCShBSLndZpdnhpGFSdhBp +PvzzWVzbclGFhLFGdZll +VWjPWvbjcVbVcGVzjcgzgwQQRRRrqwRJQwwstCRR +zjBMMz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WPjGWMPSJJzrBSpzdFSddCFdncrs +bPzRlMPTzTMldJMnhswcjzfQVccQhc +HCCqNmNmQQmQssJn +pHptprtgRStTtMJt +nTmhrsPMsTfmHHGcSgtj +bJJwdlrJQLlvwlQDDwSbgffGVNjfgjNtVbcf +QlpDQFJdvdFqJdFpLvDFpLLnzZMnBMRRzMTqnrzqTRPznz +qRVRqBzgwqRpqRgVqQRPpQJJPrPhPGJnsGrCFdFJrZdG +ZvWDmMvmSvCndssrsJ +WcZcNWlcMjBQpzNTqVBp +DpLPZLDDlcgmDmhVgfgfWWRwhwwt +VrVMdbCrrBTjCMQQtMwQNSqMQW +VCBHdJHdvrrFsbsdrBJTdTzZcpmZGDGPlmzmlccFDZDn diff --git a/2022/day03/main.go b/2022/day03/main.go new file mode 100644 index 0000000..65b4cb1 --- /dev/null +++ b/2022/day03/main.go @@ -0,0 +1,74 @@ +package main + +import ( + "fmt" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToStringSlice() + fmt.Println("# Part 1") + fmt.Println(part1(inp)) + fmt.Println("# Part 2") + fmt.Println(part2(inp)) +} + +func part1(inp []string) int { + var ret int + for i := range inp { + sack := inp[i] + c1, c2 := sack[:len(sack)/2], sack[len(sack)/2:] + var dupe byte + for _, c1w := range c1 { + for _, c2w := range c2 { + if c1w == c2w { + dupe = byte(c1w) + break + } + } + if dupe != 0 { + break + } + } + if dupe >= 'a' { + ret += int(dupe - 'a' + 1) + } else if dupe >= 'A' { + ret += int(dupe - 'A' + 27) + } + } + return ret +} + +func part2(inp []string) int { + var ret int + elves := []string{"", "", ""} + for i := range inp { + elves[i%3] = inp[i] + if i%3 == 2 { + var badge byte + // Check 'em + for _, e1 := range elves[0] { + for _, e2 := range elves[1] { + for _, e3 := range elves[2] { + if e1 == e2 && e2 == e3 { + badge = byte(e1) + } + } + if badge != 0 { + break + } + } + if badge != 0 { + break + } + } + if badge >= 'a' { + ret += int(badge - 'a' + 1) + } else if badge >= 'A' { + ret += int(badge - 'A' + 27) + } + } + } + return ret +} diff --git a/2022/day03/problem b/2022/day03/problem new file mode 100644 index 0000000..15e0a05 --- /dev/null +++ b/2022/day03/problem @@ -0,0 +1,140 @@ + Advent of Code + + • [About] + • [Events] + • [Shop] + • [Settings] + • [Log Out] + + br0xen (AoC++) 6* + +       /*2022*/ + + • [Calendar] + • [AoC++] + • [Sponsors] + • [Leaderboard] + • [Stats] + + Our sponsors help make Advent of Code possible: + Spotify - Follow our engineering blog to see how our developers solve complex tech problems, at scale, every day. + +--- Day 3: Rucksack Reorganization --- + + One Elf has the important job of loading all of the rucksacks with supplies for the jungle journey. Unfortunately, that + Elf didn't quite follow the packing instructions, and so a few items now need to be rearranged. + + Each rucksack has two large compartments. All items of a given type are meant to go into exactly one of the two + compartments. The Elf that did the packing failed to follow this rule for exactly one item type per rucksack. + + The Elves have made a list of all of the items currently in each rucksack (your puzzle input), but they need your help + finding the errors. Every item type is identified by a single lowercase or uppercase letter (that is, a and A refer to + different types of items). + + The list of items for each rucksack is given as characters all on a single line. A given rucksack always has the same + number of items in each of its two compartments, so the first half of the characters represent items in the first + compartment, while the second half of the characters represent items in the second compartment. + + For example, suppose you have the following list of contents from six rucksacks: + + vJrwpWtwJgWrhcsFMMfFFhFp + jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL + PmmdzqPrVvPwwTWBwg + wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn + ttgJtRGJQctTZtZT + CrZsJsPPZsGzwwsLwLmpwMDw + + • The first rucksack contains the items vJrwpWtwJgWrhcsFMMfFFhFp, which means its first compartment contains the items + vJrwpWtwJgWr, while the second compartment contains the items hcsFMMfFFhFp. The only item type that appears in both + compartments is lowercase p. + • The second rucksack's compartments contain jqHRNqRjqzjGDLGL and rsFMfFZSrLrFZsSL. The only item type that appears in + both compartments is uppercase L. + • The third rucksack's compartments contain PmmdzqPrV and vPwwTWBwg; the only common item type is uppercase P. + • The fourth rucksack's compartments only share item type v. + • The fifth rucksack's compartments only share item type t. + • The sixth rucksack's compartments only share item type s. + + To help prioritize item rearrangement, every item type can be converted to a priority: + + • Lowercase item types a through z have priorities 1 through 26. + • Uppercase item types A through Z have priorities 27 through 52. + + In the above example, the priority of the item type that appears in both compartments of each rucksack is 16 (p), 38 + (L), 42 (P), 22 (v), 20 (t), and 19 (s); the sum of these is 157. + + Find the item type that appears in both compartments of each rucksack. What is the sum of the priorities of those item + types? + + Your puzzle answer was 7967. + +--- Part Two --- + + As you finish identifying the misplaced items, the Elves come to you with another issue. + + For safety, the Elves are divided into groups of three. Every Elf carries a badge that identifies their group. For + efficiency, within each group of three Elves, the badge is the only item type carried by all three Elves. That is, if a + group's badge is item type B, then all three Elves will have item type B somewhere in their rucksack, and at most two of + the Elves will be carrying any other item type. + + The problem is that someone forgot to put this year's updated authenticity sticker on the badges. All of the badges need + to be pulled out of the rucksacks so the new authenticity stickers can be attached. + + Additionally, nobody wrote down which item type corresponds to each group's badges. The only way to tell which item type + is the right one is by finding the one item type that is common between all three Elves in each group. + + Every set of three lines in your list corresponds to a single group, but each group can have a different badge item + type. So, in the above example, the first group's rucksacks are the first three lines: + + vJrwpWtwJgWrhcsFMMfFFhFp + jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL + PmmdzqPrVvPwwTWBwg + + And the second group's rucksacks are the next three lines: + + wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn + ttgJtRGJQctTZtZT + CrZsJsPPZsGzwwsLwLmpwMDw + + In the first group, the only item type that appears in all three rucksacks is lowercase r; this must be their badges. In + the second group, their badge item type must be Z. + + Priorities for these items must still be found to organize the sticker attachment efforts: here, they are 18 (r) for the + first group and 52 (Z) for the second group. The sum of these is 70. + + Find the item type that corresponds to the badges of each three-Elf group. What is the sum of the priorities of those + item types? + + Your puzzle answer was 2716. + + Both parts of this puzzle are complete! They provide two gold stars: ** + + At this point, you should return to your Advent calendar and try another puzzle. + + If you still want to see it, you can get your puzzle input. + + You can also [Shareon Twitter Mastodon] this puzzle. + +References + + Visible links + . https://adventofcode.com/ + . https://adventofcode.com/2022/about + . https://adventofcode.com/2022/events + . https://teespring.com/stores/advent-of-code + . https://adventofcode.com/2022/settings + . https://adventofcode.com/2022/auth/logout + . Advent of Code Supporter + https://adventofcode.com/2022/support + . https://adventofcode.com/2022 + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/support + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022/leaderboard + . https://adventofcode.com/2022/stats + . https://adventofcode.com/2022/sponsors + . https://engineering.atspotify.com/ + . https://en.wikipedia.org/wiki/Rucksack + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/day/3/input + . https://twitter.com/intent/tweet?text=I%27ve+completed+%22Rucksack+Reorganization%22+%2D+Day+3+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F3&related=ericwastl&hashtags=AdventOfCode + . javascript:void(0); diff --git a/2022/day03/testinput b/2022/day03/testinput new file mode 100644 index 0000000..f17e726 --- /dev/null +++ b/2022/day03/testinput @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw From 9a3a29d7df6d3fed0f74eadde3a644b3feced43a Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Sun, 4 Dec 2022 06:37:53 -0600 Subject: [PATCH 4/7] 2022 Day 4 Complete! --- 2022/day04/input | 1000 ++++++++++++++++++++++++++++++++++++++++++ 2022/day04/main.go | 83 ++++ 2022/day04/problem | 106 +++++ 2022/day04/testinput | 6 + 4 files changed, 1195 insertions(+) create mode 100644 2022/day04/input create mode 100644 2022/day04/main.go create mode 100644 2022/day04/problem create mode 100644 2022/day04/testinput diff --git a/2022/day04/input b/2022/day04/input new file mode 100644 index 0000000..f527fb0 --- /dev/null +++ b/2022/day04/input @@ -0,0 +1,1000 @@ +1-93,2-11 +26-94,26-94 +72-92,48-88 +36-37,37-52 +2-98,1-98 +1-83,1-84 +74-79,76-76 +66-85,66-86 +6-73,6-73 +31-57,30-58 +1-98,1-98 +28-47,55-97 +29-71,70-72 +40-53,40-53 +14-71,39-71 +19-98,18-94 +94-96,81-95 +79-98,79-97 +52-66,60-61 +2-3,8-89 +53-59,59-83 +79-81,3-80 +14-84,84-92 +90-90,7-89 +10-76,11-76 +9-31,10-12 +8-8,8-72 +2-97,1-96 +3-33,2-94 +3-5,4-99 +46-94,8-94 +97-98,14-92 +60-98,81-99 +11-98,11-97 +27-82,26-81 +21-61,12-18 +26-55,26-56 +89-96,97-97 +29-30,29-31 +66-90,40-87 +7-49,8-88 +37-61,39-58 +8-65,9-96 +7-72,2-51 +14-73,15-56 +7-11,16-24 +12-83,13-85 +72-91,7-71 +78-82,56-77 +1-46,15-46 +1-76,1-75 +75-98,5-98 +37-41,22-41 +1-1,2-98 +76-94,77-93 +88-88,4-89 +86-87,38-90 +85-89,46-86 +64-99,1-99 +16-48,32-96 +6-95,6-95 +44-68,43-49 +19-78,19-79 +35-95,7-34 +72-72,32-71 +21-26,24-26 +20-57,21-58 +17-98,17-98 +22-97,21-98 +62-92,92-99 +1-74,1-75 +9-75,10-74 +5-7,4-8 +37-41,4-81 +3-96,4-99 +92-98,94-96 +69-89,75-88 +13-29,14-18 +35-48,42-49 +10-11,11-95 +17-33,32-32 +16-80,61-77 +38-41,40-42 +6-79,6-80 +51-95,50-52 +18-94,19-33 +95-99,15-96 +18-37,19-47 +25-33,24-31 +9-9,10-98 +5-72,6-72 +6-6,7-95 +39-96,38-84 +79-95,57-78 +61-67,61-61 +44-95,9-94 +69-93,16-68 +24-24,23-95 +56-90,49-57 +13-82,13-13 +5-94,4-94 +46-61,44-46 +3-37,7-84 +3-73,3-72 +2-2,3-95 +12-94,24-94 +37-58,37-57 +79-95,7-78 +10-77,76-76 +4-98,5-97 +64-99,27-99 +68-68,69-69 +18-28,18-29 +58-95,9-95 +4-93,5-94 +9-84,85-85 +50-89,51-90 +38-97,2-39 +22-70,78-90 +62-68,67-67 +36-44,36-44 +59-59,36-58 +97-97,1-97 +14-15,15-94 +90-90,3-62 +2-4,3-80 +29-97,81-97 +8-35,34-54 +14-57,14-60 +42-78,10-56 +32-99,31-98 +31-87,86-87 +44-57,44-57 +1-92,92-92 +8-69,5-83 +33-47,34-59 +94-98,11-98 +60-66,67-76 +20-21,21-81 +18-76,17-76 +24-61,24-62 +48-48,1-49 +28-84,85-91 +4-51,4-50 +30-32,31-69 +38-70,39-39 +28-92,37-79 +22-65,22-68 +29-56,9-46 +11-97,2-99 +4-98,31-94 +29-92,29-93 +93-97,32-92 +24-27,25-48 +54-55,6-77 +10-81,82-96 +27-94,28-89 +32-81,47-81 +64-83,65-97 +41-49,50-79 +99-99,14-94 +66-78,66-77 +16-95,17-95 +98-98,3-97 +2-6,6-53 +26-26,12-25 +2-54,3-86 +59-95,94-95 +40-62,2-40 +9-90,9-91 +3-53,2-52 +91-93,88-92 +63-98,64-99 +32-68,68-84 +34-77,74-80 +2-83,1-2 +32-79,60-73 +96-98,3-96 +28-74,29-87 +8-96,29-96 +50-64,50-65 +26-72,15-73 +63-80,44-86 +10-87,11-86 +5-94,36-94 +5-93,6-92 +3-92,4-93 +83-83,14-83 +9-9,9-40 +88-96,12-89 +31-56,34-42 +83-96,28-84 +5-6,6-36 +31-96,30-96 +26-82,41-82 +95-95,18-96 +32-71,31-71 +55-69,56-85 +1-87,2-98 +15-92,9-91 +1-76,1-76 +3-45,3-27 +53-59,52-58 +1-97,5-96 +2-78,4-78 +65-84,84-89 +74-80,79-79 +36-90,37-66 +3-66,54-74 +35-79,35-80 +76-76,75-75 +66-77,65-78 +3-91,3-90 +25-45,26-62 +35-35,36-82 +28-73,29-72 +36-96,37-64 +46-85,85-87 +70-99,2-99 +27-65,36-39 +8-70,70-84 +39-47,38-50 +66-89,23-66 +2-93,5-92 +1-70,92-92 +12-95,15-95 +44-85,45-84 +17-54,17-72 +20-23,19-31 +27-37,14-33 +16-96,82-96 +8-61,7-62 +11-91,73-96 +3-93,40-81 +30-30,29-90 +7-38,38-44 +70-82,12-93 +53-57,54-58 +37-66,66-99 +94-96,11-95 +11-97,11-96 +39-56,40-55 +27-74,1-96 +43-48,3-98 +62-79,63-79 +16-22,24-25 +1-96,2-99 +58-83,57-83 +43-76,42-67 +41-46,8-46 +2-52,2-55 +50-80,28-51 +9-34,9-9 +47-48,46-46 +47-85,85-99 +29-44,29-45 +20-89,19-88 +51-58,60-75 +57-58,57-57 +39-90,38-89 +18-77,20-76 +55-76,54-62 +26-83,25-82 +2-87,2-86 +1-83,2-94 +7-88,88-89 +6-33,7-99 +17-18,10-13 +40-99,40-99 +14-66,31-95 +46-98,46-98 +50-76,73-76 +39-45,2-80 +19-76,18-23 +19-92,98-98 +95-95,1-94 +1-86,87-88 +44-86,45-87 +4-99,4-87 +15-30,14-16 +11-66,13-76 +1-84,14-55 +2-72,2-87 +34-83,77-83 +13-90,30-33 +55-77,49-54 +18-25,7-16 +46-46,47-91 +14-86,14-58 +14-75,79-99 +13-45,14-46 +6-26,7-81 +24-99,35-48 +3-95,94-99 +71-81,20-71 +30-30,31-82 +15-15,14-41 +81-92,82-87 +3-49,48-67 +2-89,2-90 +18-92,19-92 +9-76,8-70 +40-47,41-64 +53-81,81-88 +44-86,44-44 +4-90,98-98 +8-94,95-95 +31-31,32-78 +31-82,30-83 +59-59,40-60 +48-69,48-68 +9-28,28-51 +23-90,23-91 +25-36,57-93 +31-88,30-32 +6-99,4-15 +9-68,28-69 +2-99,3-99 +3-31,30-32 +4-99,4-98 +17-74,11-18 +19-91,19-70 +74-97,75-89 +80-80,33-79 +10-76,2-4 +4-98,18-94 +1-63,1-63 +5-97,5-96 +16-63,16-81 +2-92,91-92 +1-78,79-79 +60-99,35-98 +74-84,39-73 +9-87,9-88 +78-85,77-78 +1-1,1-43 +11-44,12-43 +33-93,9-98 +6-74,5-65 +4-50,4-6 +27-30,25-39 +3-69,39-45 +83-85,86-86 +10-49,50-50 +81-83,8-82 +17-17,18-63 +10-24,20-24 +28-85,86-92 +36-36,37-69 +49-73,46-49 +8-88,7-88 +8-71,9-62 +10-47,46-75 +95-95,92-96 +10-97,7-7 +4-9,3-97 +58-93,43-95 +41-94,40-75 +5-79,3-79 +45-76,46-77 +15-88,7-14 +3-93,3-93 +96-99,4-97 +4-9,6-13 +69-77,5-61 +47-56,71-72 +98-99,15-97 +19-57,53-54 +14-58,37-59 +5-90,22-97 +79-81,63-80 +32-65,33-70 +2-50,50-50 +84-96,7-96 +26-26,27-95 +99-99,2-98 +21-39,21-21 +53-80,54-80 +69-98,59-68 +51-57,57-59 +56-59,29-72 +1-98,2-99 +23-82,34-83 +29-67,30-67 +69-84,85-85 +7-78,78-88 +26-80,81-81 +12-43,12-97 +46-76,45-78 +10-22,9-94 +26-29,25-36 +26-85,26-26 +14-98,15-19 +5-23,9-96 +54-55,55-70 +97-99,2-98 +39-71,3-26 +6-96,6-99 +24-89,62-89 +21-37,37-38 +16-98,15-99 +62-64,2-63 +4-73,4-72 +4-58,6-59 +14-68,14-68 +48-50,49-88 +51-82,45-49 +17-75,4-76 +31-78,78-78 +22-34,14-34 +2-96,1-92 +1-99,98-98 +41-65,64-73 +80-82,17-85 +23-97,22-59 +19-54,16-58 +85-97,47-86 +4-24,23-50 +12-91,90-90 +91-98,91-98 +10-63,9-9 +49-82,48-50 +22-80,23-99 +12-82,13-98 +1-60,2-47 +28-50,19-72 +44-61,44-44 +98-99,66-97 +37-37,37-83 +22-24,23-25 +65-71,65-70 +10-90,89-93 +10-42,42-66 +13-91,90-99 +38-62,48-62 +3-98,4-99 +26-68,27-68 +8-71,82-83 +5-49,50-70 +1-35,1-36 +20-78,79-79 +39-59,39-39 +61-79,61-80 +94-99,95-95 +51-82,83-90 +1-57,2-72 +10-19,11-42 +55-99,54-54 +24-90,89-94 +24-34,34-88 +98-99,45-97 +27-65,2-90 +6-73,5-73 +73-89,72-90 +81-83,78-82 +3-99,3-98 +96-99,52-95 +75-92,6-92 +58-58,12-57 +17-38,37-41 +75-75,5-75 +22-46,22-47 +89-97,2-98 +53-70,19-53 +25-90,89-93 +36-54,46-55 +1-98,97-97 +34-36,2-33 +32-55,31-85 +2-56,56-68 +1-59,1-58 +83-84,1-82 +3-67,4-66 +65-84,41-85 +7-73,16-73 +66-66,23-68 +42-83,42-76 +17-91,17-82 +29-78,29-36 +29-82,29-81 +17-55,54-55 +64-77,63-87 +85-85,45-84 +4-34,3-3 +16-51,52-73 +4-96,39-95 +1-94,31-94 +1-87,2-88 +11-24,12-25 +1-1,3-79 +26-64,13-17 +35-81,54-71 +1-44,1-43 +59-62,22-24 +14-77,8-14 +64-83,83-99 +64-87,87-89 +1-15,15-99 +43-57,48-48 +2-25,2-26 +39-78,39-79 +13-98,14-56 +5-33,75-93 +98-98,3-98 +11-72,10-72 +6-92,5-6 +4-57,4-56 +94-94,40-95 +55-85,55-84 +46-75,45-74 +35-94,34-94 +33-86,85-90 +85-96,42-86 +7-92,5-92 +11-33,10-33 +43-73,38-77 +22-96,1-99 +5-98,4-6 +79-83,78-81 +4-73,32-72 +14-20,20-52 +31-89,30-88 +18-74,9-75 +2-65,2-64 +17-32,33-41 +4-99,8-98 +96-97,77-96 +91-96,63-94 +23-71,52-54 +40-89,49-56 +10-89,10-90 +21-57,21-88 +32-91,33-57 +44-97,44-44 +5-65,4-86 +19-60,18-45 +30-79,80-80 +9-12,8-12 +60-60,59-59 +18-57,48-53 +32-71,72-85 +65-78,35-66 +27-44,41-44 +43-72,14-42 +28-97,28-99 +35-55,35-56 +27-50,1-51 +69-69,51-70 +65-66,5-25 +4-20,3-20 +30-91,31-91 +61-90,61-86 +38-74,98-98 +45-82,78-81 +64-64,5-65 +3-23,2-99 +26-45,2-26 +97-98,19-75 +76-76,5-77 +13-71,12-72 +17-53,52-99 +15-86,87-87 +57-98,23-29 +15-69,9-12 +8-99,18-91 +94-94,19-95 +1-93,93-96 +10-92,52-92 +47-54,70-85 +13-36,12-13 +7-96,15-47 +10-98,11-98 +79-94,89-95 +28-80,80-81 +36-72,37-56 +67-83,67-83 +91-91,80-90 +8-78,1-84 +16-41,40-42 +3-6,5-7 +12-96,8-12 +68-95,95-95 +88-89,16-92 +97-97,43-96 +20-35,34-92 +45-93,46-92 +8-19,9-32 +30-44,13-22 +5-50,6-50 +30-85,84-86 +11-58,57-74 +36-75,7-26 +6-86,3-6 +21-95,94-98 +10-94,14-93 +72-72,7-72 +50-65,51-97 +67-67,68-75 +97-98,10-94 +37-75,33-38 +4-89,4-98 +3-97,2-98 +3-50,47-68 +51-89,52-59 +50-85,84-85 +97-99,29-98 +95-97,35-96 +51-98,99-99 +4-99,75-75 +35-62,5-62 +22-56,21-56 +38-43,49-86 +5-38,5-15 +11-70,6-69 +63-86,28-86 +8-89,10-20 +14-94,4-97 +10-51,10-50 +3-40,4-41 +45-46,46-85 +61-97,62-96 +5-88,5-92 +29-92,91-96 +89-94,3-88 +3-71,2-72 +33-81,34-82 +48-57,47-84 +2-83,48-76 +24-67,24-66 +30-90,30-89 +82-82,58-83 +52-58,52-59 +23-80,8-80 +33-79,34-80 +22-70,23-70 +24-59,25-77 +1-50,8-61 +19-91,91-96 +6-6,7-85 +84-84,81-83 +25-41,16-41 +1-18,2-8 +40-86,78-83 +24-40,41-84 +92-96,3-93 +5-97,2-3 +59-95,94-98 +13-18,13-19 +1-68,5-65 +39-66,66-84 +12-56,8-9 +37-94,38-71 +27-74,27-75 +18-18,19-92 +14-29,14-81 +91-94,11-90 +61-77,3-62 +5-7,6-74 +24-67,23-66 +4-96,4-98 +40-94,41-93 +30-51,52-91 +3-35,1-35 +24-40,39-39 +91-91,76-90 +13-89,14-69 +6-95,7-96 +2-72,1-71 +71-72,72-94 +5-6,6-58 +14-26,28-77 +63-99,57-99 +32-88,4-88 +3-64,63-63 +62-86,85-87 +48-92,24-47 +69-74,62-80 +10-98,53-56 +22-87,1-22 +23-87,92-98 +30-76,31-76 +20-66,21-40 +23-87,87-91 +10-10,11-12 +36-74,75-94 +36-36,10-35 +20-73,14-81 +56-68,55-66 +8-98,7-61 +4-96,4-97 +13-90,1-90 +45-87,45-85 +66-68,24-67 +53-60,39-66 +98-99,2-97 +6-81,80-99 +4-98,4-97 +88-88,14-87 +20-57,21-38 +25-76,24-76 +8-8,10-61 +13-46,13-45 +71-98,70-97 +3-6,9-41 +18-41,40-40 +9-70,21-36 +33-83,11-33 +8-22,80-83 +5-37,6-36 +32-67,67-87 +26-48,25-47 +15-70,69-71 +11-94,15-93 +16-39,16-40 +81-85,81-85 +23-75,23-74 +55-79,55-79 +30-85,29-86 +7-79,78-78 +13-15,7-16 +82-82,29-81 +2-69,15-68 +63-91,52-63 +35-86,87-87 +17-96,18-96 +57-57,58-87 +46-54,46-53 +26-78,27-93 +12-81,12-82 +15-85,5-20 +28-88,36-88 +62-73,63-72 +42-43,17-43 +56-97,56-98 +20-65,17-66 +32-99,33-57 +14-96,15-95 +8-25,7-25 +56-60,56-59 +20-86,19-20 +19-97,20-96 +86-86,58-87 +60-70,59-72 +9-50,32-51 +8-10,14-62 +56-89,88-88 +46-93,92-97 +12-25,1-66 +11-16,18-95 +62-64,17-61 +78-89,43-78 +30-92,30-90 +68-86,69-71 +89-98,33-44 +9-20,8-20 +57-77,16-57 +12-86,11-53 +7-11,28-53 +13-92,14-82 +49-91,92-92 +60-86,60-99 +73-99,73-97 +34-67,54-63 +75-76,43-76 +9-95,94-96 +37-69,38-77 +76-77,45-77 +42-69,42-68 +2-35,2-14 +95-96,15-96 +1-97,2-98 +31-57,31-56 +34-37,33-68 +25-54,24-54 +19-43,9-59 +38-94,93-95 +38-73,38-73 +58-85,58-84 +64-98,58-63 +12-22,12-21 +13-13,14-82 +17-55,17-81 +90-97,88-96 +8-99,47-99 +2-60,35-60 +5-66,6-60 +78-78,4-79 +61-68,48-90 +23-94,93-97 +13-69,12-12 +17-74,1-74 +17-47,48-48 +56-71,70-72 +17-17,17-99 +11-98,12-63 +58-58,58-59 +64-64,65-94 +83-91,1-65 +31-79,78-80 +4-77,78-78 +53-80,3-52 +34-63,62-64 +97-98,1-98 +93-94,41-94 +49-79,50-80 +14-66,14-66 +53-89,45-53 +11-47,10-99 +60-65,61-85 +27-78,26-78 +18-92,19-98 +31-45,17-31 +6-42,5-61 +52-79,51-84 +82-86,83-92 +8-72,71-82 +7-39,6-6 +3-75,75-99 +22-22,22-55 +6-88,6-88 +3-78,34-71 +70-70,11-71 +88-90,52-89 +11-14,28-33 +61-71,50-60 +80-84,7-84 +5-97,98-99 +2-79,3-80 +8-94,8-94 +5-83,83-84 +41-41,10-40 +51-76,13-96 +47-97,48-98 +6-96,7-96 +40-47,41-51 +22-97,22-23 +3-62,3-61 +48-80,43-80 +86-88,8-87 +80-80,52-79 +30-43,29-44 +57-75,56-75 +4-85,3-77 +39-83,38-79 +2-50,1-51 +12-93,11-93 +4-81,3-21 +80-98,79-79 +44-52,51-53 +2-93,92-93 +15-86,2-15 +5-85,5-85 +36-73,36-72 +4-86,3-4 +7-27,8-28 +11-70,69-71 +36-60,37-60 +10-10,16-55 +87-92,88-94 +21-93,20-92 +16-16,15-92 +18-44,19-45 +24-24,24-79 +50-63,15-76 +64-68,65-66 +34-36,30-35 +83-85,2-84 +37-82,37-82 +17-69,17-80 +29-30,30-90 +9-95,9-94 +58-86,58-58 +96-99,17-96 +4-52,12-64 +7-99,8-99 +7-75,7-75 +2-52,26-75 +92-92,9-93 +2-64,3-70 +2-6,5-69 +19-86,9-19 +76-76,7-76 +4-99,1-99 +44-74,2-43 +20-97,79-96 +31-75,31-74 +13-97,13-96 +76-90,90-94 +3-63,4-94 +16-17,17-98 +2-84,84-98 +6-90,5-89 +23-25,24-24 +56-78,78-80 +8-63,7-29 +23-29,23-29 +26-94,25-95 +51-70,51-51 +9-57,14-57 +26-31,25-28 +59-96,59-94 +3-54,1-1 +57-69,31-57 +6-97,5-97 +2-88,55-82 +74-99,73-77 +36-44,36-43 +15-15,2-26 +3-59,4-69 +25-79,26-81 +97-99,59-98 +10-89,74-89 +56-93,92-93 +73-75,18-74 +89-89,12-88 +30-91,31-94 +16-24,15-92 +52-93,51-93 +42-93,41-98 +73-97,21-99 +12-88,87-94 +10-14,10-15 +83-95,53-82 +72-90,68-72 +52-66,14-81 +70-72,11-71 +43-43,13-42 +2-46,2-45 +46-94,76-89 +27-67,9-67 +9-89,28-89 +2-92,92-92 +5-85,86-99 +38-86,12-38 +4-98,3-98 +1-82,6-82 +24-30,24-29 +28-93,27-68 +39-76,5-38 +6-19,5-86 +12-14,13-17 +86-87,29-86 +12-91,12-91 +3-99,3-99 +7-84,6-65 +30-45,31-90 +11-14,21-57 +8-62,61-62 +20-92,20-91 +8-89,8-89 +18-36,6-14 +18-45,17-45 +66-66,5-65 +95-96,11-96 +1-3,4-74 +12-94,94-98 +25-58,25-57 +15-70,15-69 +6-82,1-6 +4-5,5-12 +28-60,59-64 +2-92,92-98 +61-85,86-94 +48-97,39-97 +51-53,42-73 +7-94,93-94 +19-49,15-68 +14-56,3-56 +21-85,20-84 +18-19,19-63 +2-98,3-99 +86-94,73-99 +62-64,4-63 +18-86,19-86 +24-56,25-96 +93-99,16-93 +37-96,36-50 +16-91,15-53 +27-32,28-34 +16-71,15-16 +55-57,56-70 +82-93,70-83 +24-66,24-83 +1-96,2-95 +8-18,9-28 +1-59,1-60 +26-57,11-26 +45-50,46-48 +7-90,8-41 +56-92,57-93 +8-91,8-91 +1-63,6-12 +48-96,96-99 +26-99,26-97 +51-51,52-68 +47-50,6-46 +3-64,13-40 +5-75,3-3 +66-66,9-65 +92-92,7-91 diff --git a/2022/day04/main.go b/2022/day04/main.go new file mode 100644 index 0000000..4370e81 --- /dev/null +++ b/2022/day04/main.go @@ -0,0 +1,83 @@ +package main + +import ( + "fmt" + "strings" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToStringSlice() + part1(inp) + part2(inp) +} + +func part1(inp []string) { + fmt.Println("# Part 1") + var ret int + for _, pair := range inp { + elves := strings.Split(pair, ",") + e1S, e1E := getRange(elves[0]) + e2S, e2E := getRange(elves[1]) + if rangesFullyOverlap(e1S, e1E, e2S, e2E) { + ret++ + } + } + fmt.Printf("Fully Overlapping Ranges: %d\n", ret) +} + +func part2(inp []string) { + fmt.Println("# Part 2") + var ret int + for _, pair := range inp { + elves := strings.Split(pair, ",") + e1S, e1E := getRange(elves[0]) + e2S, e2E := getRange(elves[1]) + if rangesOverlap(e1S, e1E, e2S, e2E) { + ret++ + } + } + fmt.Printf("Overlapping Ranges: %d\n", ret) +} + +func partXAllOverlaps(inp []string) { + fmt.Println("# Part x") + var overlaps int + sections := make(map[int]int) + for _, pair := range inp { + elves := strings.Split(pair, ",") + for elfIdx, elf := range elves { + var overlapped bool + i1, i2 := getRange(elf) + for i := i1; i <= i2; i++ { + if _, ok := sections[i]; ok { + overlapped = true + } else { + sections[i] = elfIdx + } + } + if overlapped { + overlaps++ + } + } + } + fmt.Printf("Overlapping Assignments: %d\n", overlaps) +} + +func rangesFullyOverlap(e1start, e1end, e2start, e2end int) bool { + return (e1start >= e2start && e1end <= e2end) || + (e2start >= e1start && e2end <= e1end) +} +func rangesOverlap(e1start, e1end, e2start, e2end int) bool { + ret := (e1start >= e2start && e1start <= e2end) || + (e1end >= e2start && e1end <= e2end) || + (e2start >= e1start && e2start <= e1end) || + (e2end >= e1start && e2end <= e1end) + return ret +} + +func getRange(elf string) (int, int) { + idxsS := strings.Split(elf, "-") + return h.Atoi(idxsS[0]), h.Atoi(idxsS[1]) +} diff --git a/2022/day04/problem b/2022/day04/problem new file mode 100644 index 0000000..6d085f4 --- /dev/null +++ b/2022/day04/problem @@ -0,0 +1,106 @@ +Advent of Code + +br0xen (AoC++) 7* + +--- Day 4: Camp Cleanup --- + + Space needs to be cleared before the last supplies can be unloaded from the ships, and so several Elves have been + assigned the job of cleaning up sections of the camp. Every section has a unique ID number, and each Elf is assigned a + range of section IDs. + + However, as some of the Elves compare their section assignments with each other, they've noticed that many of the + assignments overlap. To try to quickly find overlaps and reduce duplicated effort, the Elves pair up and make a big list + of the section assignments for each pair (your puzzle input). + + For example, consider the following list of section assignment pairs: + + 2-4,6-8 + 2-3,4-5 + 5-7,7-9 + 2-8,3-7 + 6-6,4-6 + 2-6,4-8 + + For the first few pairs, this list means: + + • Within the first pair of Elves, the first Elf was assigned sections 2-4 (sections 2, 3, and 4), while the second Elf + was assigned sections 6-8 (sections 6, 7, 8). + • The Elves in the second pair were each assigned two sections. + • The Elves in the third pair were each assigned three sections: one got sections 5, 6, and 7, while the other also + got 7, plus 8 and 9. + + This example list uses single-digit section IDs to make it easier to draw; your actual list might contain larger + numbers. Visually, these pairs of section assignments look like this: + + .234..... 2-4 + .....678. 6-8 + + .23...... 2-3 + ...45.... 4-5 + + ....567.. 5-7 + ......789 7-9 + + .2345678. 2-8 + ..34567.. 3-7 + + .....6... 6-6 + ...456... 4-6 + + .23456... 2-6 + ...45678. 4-8 + + Some of the pairs have noticed that one of their assignments fully contains the other. For example, 2-8 fully contains + 3-7, and 6-6 is fully contained by 4-6. In pairs where one assignment fully contains the other, one Elf in the pair + would be exclusively cleaning sections their partner will already be cleaning, so these seem like the most in need of + reconsideration. In this example, there are 2 such pairs. + + In how many assignment pairs does one range fully contain the other? + + Your puzzle answer was 503. + + The first half of this puzzle is complete! It provides one gold star: * + +--- Part Two --- + + It seems like there is still quite a bit of duplicate work planned. Instead, the Elves would like to know the number of + pairs that overlap at all. + + In the above example, the first two pairs (2-4,6-8 and 2-3,4-5) don't overlap, while the remaining four pairs (5-7,7-9, + 2-8,3-7, 6-6,4-6, and 2-6,4-8) do overlap: + + • 5-7,7-9 overlaps in a single section, 7. + • 2-8,3-7 overlaps all of the sections 3 through 7. + • 6-6,4-6 overlaps in a single section, 6. + • 2-6,4-8 overlaps in sections 4, 5, and 6. + + So, in this example, the number of overlapping assignment pairs is 4. + + In how many assignment pairs do the ranges overlap? + + Your puzzle answer was 827. + + Both parts of this puzzle are complete! They provide two gold stars: ** + + At this point, you should return to your Advent calendar and try another puzzle. + + If you still want to see it, you can get your puzzle input. + +References + + Visible links + . https://adventofcode.com/ + . https://adventofcode.com/2022/about + . https://adventofcode.com/2022/events + . https://adventofcode.com/2022/settings + . https://adventofcode.com/2022/auth/logout + . Advent of Code Supporter + https://adventofcode.com/2022/support + . https://adventofcode.com/2022 + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/support + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022/leaderboard + . https://adventofcode.com/2022/stats + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022/day/4/input diff --git a/2022/day04/testinput b/2022/day04/testinput new file mode 100644 index 0000000..9f9e9cf --- /dev/null +++ b/2022/day04/testinput @@ -0,0 +1,6 @@ +2-4,6-8 +2-3,4-5 +5-7,7-9 +2-8,3-7 +6-6,4-6 +2-6,4-8 From 67300ad82fa9d886f171dba965ad956ca254f057 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Mon, 5 Dec 2022 09:47:05 -0600 Subject: [PATCH 5/7] 2022 Day 5 Complete --- 2022/day05/input | 511 +++++++++++++++++++++++++++++++++++++++++++ 2022/day05/main.go | 121 ++++++++++ 2022/day05/problem | 161 ++++++++++++++ 2022/day05/testinput | 9 + helpers/helpers.go | 2 +- 5 files changed, 803 insertions(+), 1 deletion(-) create mode 100644 2022/day05/input create mode 100644 2022/day05/main.go create mode 100644 2022/day05/problem create mode 100644 2022/day05/testinput diff --git a/2022/day05/input b/2022/day05/input new file mode 100644 index 0000000..b8e9535 --- /dev/null +++ b/2022/day05/input @@ -0,0 +1,511 @@ +[N] [R] [C] +[T] [J] [S] [J] [N] +[B] [Z] [H] [M] [Z] [D] +[S] [P] [G] [L] [H] [Z] [T] +[Q] [D] [F] [D] [V] [L] [S] [M] +[H] [F] [V] [J] [C] [W] [P] [W] [L] +[G] [S] [H] [Z] [Z] [T] [F] [V] [H] +[R] [H] [Z] [M] [T] [M] [T] [Q] [W] + 1 2 3 4 5 6 7 8 9 + +move 3 from 9 to 7 +move 4 from 4 to 5 +move 2 from 4 to 6 +move 4 from 7 to 5 +move 3 from 7 to 3 +move 2 from 5 to 9 +move 5 from 6 to 3 +move 5 from 9 to 1 +move 3 from 8 to 4 +move 3 from 4 to 6 +move 8 from 1 to 8 +move 1 from 8 to 6 +move 2 from 8 to 2 +move 5 from 8 to 4 +move 1 from 8 to 1 +move 6 from 6 to 4 +move 1 from 7 to 9 +move 5 from 1 to 7 +move 1 from 1 to 2 +move 2 from 9 to 8 +move 6 from 4 to 9 +move 1 from 6 to 8 +move 3 from 2 to 7 +move 4 from 2 to 8 +move 4 from 9 to 3 +move 6 from 5 to 4 +move 7 from 8 to 1 +move 10 from 4 to 1 +move 12 from 1 to 5 +move 1 from 4 to 9 +move 1 from 2 to 3 +move 2 from 9 to 1 +move 1 from 9 to 3 +move 1 from 6 to 7 +move 1 from 9 to 1 +move 3 from 1 to 3 +move 9 from 5 to 9 +move 2 from 2 to 7 +move 2 from 7 to 4 +move 3 from 9 to 4 +move 7 from 5 to 7 +move 5 from 1 to 3 +move 2 from 4 to 5 +move 1 from 4 to 6 +move 1 from 6 to 9 +move 4 from 9 to 2 +move 12 from 7 to 9 +move 2 from 4 to 9 +move 6 from 5 to 9 +move 3 from 7 to 6 +move 12 from 9 to 6 +move 5 from 9 to 1 +move 1 from 7 to 6 +move 14 from 6 to 1 +move 20 from 3 to 5 +move 5 from 9 to 5 +move 3 from 2 to 8 +move 1 from 6 to 4 +move 1 from 9 to 2 +move 1 from 4 to 6 +move 1 from 2 to 6 +move 16 from 1 to 5 +move 1 from 2 to 1 +move 12 from 5 to 6 +move 1 from 8 to 4 +move 29 from 5 to 1 +move 5 from 6 to 9 +move 20 from 1 to 3 +move 4 from 1 to 3 +move 11 from 3 to 8 +move 1 from 4 to 3 +move 4 from 9 to 8 +move 7 from 1 to 8 +move 2 from 3 to 2 +move 2 from 6 to 7 +move 1 from 9 to 8 +move 10 from 3 to 5 +move 1 from 6 to 1 +move 1 from 7 to 2 +move 3 from 1 to 2 +move 6 from 2 to 4 +move 2 from 6 to 3 +move 4 from 6 to 5 +move 1 from 6 to 2 +move 1 from 2 to 9 +move 6 from 5 to 2 +move 1 from 9 to 3 +move 24 from 8 to 7 +move 1 from 4 to 8 +move 5 from 5 to 4 +move 1 from 4 to 8 +move 1 from 8 to 7 +move 2 from 8 to 9 +move 1 from 9 to 7 +move 6 from 2 to 4 +move 10 from 3 to 7 +move 3 from 5 to 3 +move 1 from 9 to 8 +move 3 from 3 to 8 +move 4 from 8 to 7 +move 1 from 4 to 6 +move 1 from 6 to 4 +move 13 from 4 to 3 +move 17 from 7 to 6 +move 1 from 6 to 3 +move 2 from 4 to 8 +move 3 from 7 to 5 +move 14 from 6 to 7 +move 1 from 5 to 9 +move 1 from 5 to 9 +move 2 from 6 to 7 +move 1 from 5 to 1 +move 1 from 1 to 6 +move 1 from 9 to 3 +move 29 from 7 to 4 +move 10 from 4 to 3 +move 6 from 7 to 5 +move 1 from 6 to 5 +move 1 from 9 to 7 +move 1 from 7 to 2 +move 4 from 3 to 2 +move 1 from 2 to 9 +move 1 from 8 to 5 +move 11 from 3 to 4 +move 24 from 4 to 7 +move 2 from 2 to 5 +move 10 from 3 to 2 +move 6 from 2 to 1 +move 5 from 4 to 7 +move 1 from 9 to 2 +move 3 from 5 to 1 +move 1 from 4 to 6 +move 4 from 2 to 3 +move 5 from 5 to 7 +move 2 from 5 to 3 +move 32 from 7 to 5 +move 16 from 5 to 1 +move 1 from 1 to 2 +move 3 from 2 to 9 +move 1 from 8 to 6 +move 3 from 7 to 6 +move 1 from 2 to 4 +move 5 from 6 to 8 +move 5 from 8 to 6 +move 2 from 9 to 3 +move 1 from 7 to 5 +move 9 from 5 to 4 +move 1 from 9 to 1 +move 2 from 3 to 1 +move 4 from 3 to 6 +move 1 from 3 to 8 +move 6 from 4 to 6 +move 6 from 5 to 9 +move 1 from 9 to 6 +move 1 from 5 to 1 +move 1 from 5 to 4 +move 1 from 3 to 6 +move 1 from 8 to 3 +move 1 from 4 to 2 +move 1 from 2 to 3 +move 17 from 6 to 4 +move 4 from 1 to 8 +move 3 from 9 to 6 +move 1 from 8 to 4 +move 1 from 9 to 7 +move 2 from 6 to 2 +move 1 from 7 to 8 +move 12 from 1 to 9 +move 8 from 9 to 2 +move 1 from 6 to 9 +move 6 from 2 to 8 +move 2 from 8 to 3 +move 18 from 4 to 9 +move 2 from 1 to 6 +move 1 from 6 to 5 +move 3 from 4 to 3 +move 7 from 3 to 8 +move 4 from 2 to 7 +move 1 from 4 to 6 +move 2 from 6 to 4 +move 13 from 9 to 6 +move 1 from 5 to 2 +move 5 from 9 to 3 +move 9 from 1 to 2 +move 1 from 1 to 8 +move 1 from 2 to 6 +move 3 from 7 to 6 +move 2 from 2 to 6 +move 9 from 8 to 6 +move 1 from 7 to 8 +move 1 from 8 to 7 +move 2 from 4 to 6 +move 5 from 3 to 6 +move 17 from 6 to 9 +move 7 from 8 to 4 +move 4 from 2 to 3 +move 17 from 6 to 2 +move 1 from 6 to 4 +move 1 from 7 to 8 +move 1 from 8 to 9 +move 24 from 9 to 6 +move 4 from 3 to 1 +move 1 from 1 to 5 +move 20 from 6 to 4 +move 4 from 6 to 9 +move 1 from 5 to 7 +move 2 from 4 to 2 +move 1 from 9 to 7 +move 25 from 4 to 3 +move 1 from 4 to 2 +move 2 from 1 to 6 +move 3 from 9 to 4 +move 2 from 4 to 7 +move 2 from 7 to 5 +move 1 from 4 to 2 +move 1 from 6 to 3 +move 1 from 1 to 5 +move 5 from 3 to 9 +move 1 from 5 to 6 +move 10 from 2 to 8 +move 9 from 2 to 5 +move 21 from 3 to 6 +move 1 from 7 to 6 +move 2 from 6 to 5 +move 5 from 9 to 7 +move 6 from 7 to 8 +move 19 from 6 to 9 +move 1 from 6 to 1 +move 8 from 8 to 1 +move 1 from 6 to 1 +move 2 from 8 to 5 +move 5 from 9 to 2 +move 6 from 8 to 2 +move 2 from 9 to 7 +move 9 from 9 to 4 +move 7 from 2 to 4 +move 1 from 6 to 4 +move 14 from 5 to 9 +move 1 from 1 to 8 +move 1 from 7 to 9 +move 4 from 2 to 9 +move 16 from 4 to 6 +move 3 from 2 to 8 +move 1 from 6 to 2 +move 2 from 8 to 9 +move 1 from 8 to 7 +move 1 from 8 to 3 +move 3 from 2 to 7 +move 1 from 3 to 9 +move 8 from 9 to 3 +move 4 from 7 to 8 +move 1 from 5 to 4 +move 4 from 6 to 3 +move 1 from 4 to 2 +move 9 from 3 to 8 +move 10 from 9 to 5 +move 8 from 6 to 7 +move 13 from 8 to 4 +move 8 from 5 to 2 +move 3 from 6 to 3 +move 7 from 9 to 6 +move 7 from 7 to 2 +move 2 from 4 to 6 +move 5 from 6 to 2 +move 3 from 1 to 5 +move 5 from 5 to 8 +move 4 from 6 to 2 +move 4 from 1 to 8 +move 15 from 2 to 6 +move 11 from 4 to 9 +move 12 from 6 to 8 +move 1 from 6 to 9 +move 5 from 3 to 7 +move 2 from 2 to 6 +move 6 from 7 to 1 +move 3 from 1 to 3 +move 1 from 4 to 1 +move 1 from 3 to 9 +move 1 from 3 to 9 +move 1 from 7 to 6 +move 1 from 3 to 2 +move 4 from 2 to 6 +move 4 from 2 to 7 +move 1 from 2 to 6 +move 4 from 1 to 6 +move 12 from 6 to 7 +move 2 from 6 to 1 +move 8 from 9 to 6 +move 1 from 7 to 4 +move 14 from 8 to 1 +move 8 from 1 to 5 +move 1 from 3 to 9 +move 5 from 9 to 5 +move 1 from 8 to 9 +move 1 from 9 to 2 +move 1 from 9 to 3 +move 5 from 8 to 3 +move 12 from 5 to 4 +move 1 from 9 to 2 +move 6 from 7 to 3 +move 7 from 3 to 2 +move 1 from 5 to 1 +move 1 from 8 to 3 +move 2 from 1 to 3 +move 2 from 6 to 9 +move 5 from 6 to 5 +move 5 from 1 to 7 +move 4 from 4 to 1 +move 7 from 2 to 8 +move 4 from 3 to 8 +move 1 from 9 to 3 +move 1 from 9 to 5 +move 4 from 1 to 8 +move 10 from 7 to 9 +move 1 from 6 to 7 +move 2 from 8 to 6 +move 6 from 4 to 2 +move 5 from 3 to 1 +move 2 from 6 to 3 +move 2 from 7 to 1 +move 5 from 2 to 5 +move 2 from 7 to 1 +move 7 from 5 to 7 +move 2 from 5 to 6 +move 2 from 5 to 3 +move 3 from 2 to 9 +move 9 from 9 to 3 +move 1 from 6 to 4 +move 3 from 3 to 1 +move 9 from 8 to 2 +move 6 from 3 to 6 +move 8 from 7 to 9 +move 4 from 9 to 8 +move 14 from 1 to 5 +move 1 from 9 to 2 +move 1 from 1 to 5 +move 2 from 3 to 6 +move 12 from 5 to 3 +move 2 from 2 to 8 +move 7 from 6 to 2 +move 12 from 2 to 8 +move 2 from 6 to 2 +move 6 from 9 to 6 +move 1 from 1 to 2 +move 1 from 9 to 3 +move 2 from 5 to 9 +move 1 from 9 to 2 +move 1 from 9 to 4 +move 1 from 3 to 2 +move 2 from 6 to 7 +move 2 from 6 to 9 +move 5 from 4 to 2 +move 14 from 3 to 9 +move 15 from 9 to 4 +move 1 from 7 to 4 +move 10 from 8 to 6 +move 1 from 5 to 9 +move 2 from 9 to 5 +move 10 from 8 to 1 +move 1 from 7 to 4 +move 5 from 1 to 2 +move 2 from 1 to 5 +move 3 from 4 to 6 +move 4 from 5 to 8 +move 5 from 8 to 6 +move 14 from 2 to 9 +move 2 from 6 to 7 +move 3 from 2 to 9 +move 3 from 1 to 7 +move 1 from 7 to 3 +move 3 from 7 to 1 +move 1 from 3 to 6 +move 1 from 7 to 6 +move 1 from 8 to 9 +move 2 from 1 to 4 +move 1 from 1 to 2 +move 16 from 9 to 4 +move 7 from 4 to 8 +move 5 from 8 to 1 +move 2 from 8 to 3 +move 2 from 1 to 7 +move 13 from 6 to 7 +move 2 from 2 to 3 +move 4 from 7 to 4 +move 6 from 4 to 5 +move 4 from 7 to 6 +move 3 from 1 to 2 +move 2 from 2 to 6 +move 3 from 3 to 8 +move 5 from 5 to 3 +move 2 from 9 to 6 +move 3 from 3 to 7 +move 1 from 8 to 1 +move 22 from 4 to 8 +move 1 from 4 to 3 +move 9 from 6 to 3 +move 1 from 2 to 1 +move 4 from 3 to 4 +move 2 from 4 to 5 +move 1 from 1 to 7 +move 4 from 3 to 7 +move 2 from 6 to 1 +move 1 from 6 to 7 +move 18 from 8 to 7 +move 2 from 6 to 5 +move 2 from 3 to 4 +move 1 from 5 to 4 +move 30 from 7 to 6 +move 2 from 1 to 3 +move 18 from 6 to 8 +move 12 from 6 to 4 +move 13 from 4 to 9 +move 2 from 3 to 8 +move 1 from 6 to 2 +move 3 from 7 to 2 +move 1 from 1 to 2 +move 2 from 5 to 9 +move 8 from 8 to 1 +move 1 from 7 to 8 +move 7 from 1 to 3 +move 2 from 4 to 9 +move 1 from 1 to 6 +move 4 from 2 to 1 +move 16 from 8 to 1 +move 1 from 2 to 6 +move 2 from 4 to 8 +move 2 from 5 to 1 +move 4 from 3 to 7 +move 3 from 7 to 1 +move 1 from 6 to 8 +move 1 from 8 to 9 +move 1 from 7 to 3 +move 6 from 3 to 5 +move 1 from 3 to 8 +move 1 from 6 to 9 +move 16 from 9 to 5 +move 4 from 5 to 3 +move 15 from 5 to 1 +move 1 from 5 to 8 +move 3 from 9 to 8 +move 9 from 8 to 5 +move 6 from 5 to 1 +move 4 from 5 to 6 +move 2 from 6 to 4 +move 1 from 6 to 4 +move 1 from 8 to 4 +move 3 from 3 to 6 +move 3 from 6 to 8 +move 1 from 6 to 8 +move 21 from 1 to 9 +move 4 from 8 to 5 +move 3 from 5 to 7 +move 2 from 5 to 1 +move 2 from 4 to 8 +move 2 from 8 to 2 +move 2 from 7 to 8 +move 1 from 7 to 9 +move 1 from 8 to 7 +move 5 from 1 to 8 +move 1 from 7 to 8 +move 4 from 8 to 4 +move 2 from 4 to 5 +move 1 from 2 to 7 +move 1 from 2 to 7 +move 2 from 7 to 6 +move 2 from 6 to 9 +move 1 from 4 to 9 +move 1 from 3 to 4 +move 16 from 1 to 5 +move 16 from 5 to 7 +move 2 from 5 to 4 +move 14 from 9 to 6 +move 5 from 4 to 3 +move 3 from 3 to 6 +move 5 from 1 to 4 +move 2 from 4 to 7 +move 7 from 9 to 4 +move 2 from 9 to 7 +move 10 from 6 to 9 +move 8 from 4 to 6 +move 1 from 8 to 4 +move 1 from 1 to 9 +move 14 from 6 to 3 +move 10 from 3 to 2 +move 3 from 7 to 8 +move 6 from 3 to 1 +move 2 from 7 to 9 +move 5 from 7 to 9 +move 10 from 9 to 1 +move 2 from 4 to 3 +move 1 from 2 to 1 +move 16 from 1 to 4 +move 1 from 6 to 1 +move 2 from 3 to 9 +move 3 from 8 to 5 +move 8 from 7 to 1 +move 3 from 5 to 9 +move 7 from 4 to 6 +move 7 from 1 to 5 +move 2 from 8 to 3 +move 1 from 7 to 8 diff --git a/2022/day05/main.go b/2022/day05/main.go new file mode 100644 index 0000000..f809123 --- /dev/null +++ b/2022/day05/main.go @@ -0,0 +1,121 @@ +package main + +import ( + "fmt" + "sort" + "strings" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToStringSlice() + part1(inp) + fmt.Println("") + part2(inp) +} + +func part1(inp []string) { + fmt.Println("# Part 1") + stacks, bottom := buildStacks(inp) + + // Run instructions + // Instructions start at bottom+2 + for i := bottom + 2; i < len(inp); i++ { + inst := strings.Fields(inp[i]) + count := h.Atoi(inst[1]) + from := h.Atoi(inst[3]) + to := h.Atoi(inst[5]) + for c := 0; c < count; c++ { + moveCrates(stacks, from, to, 1) + } + } + + for i := range stacks { + fmt.Print(string(stacks[i][0])) + } + fmt.Println("") +} + +func part2(inp []string) { + fmt.Println("# Part 2") + stacks, bottom := buildStacks(inp) + + // Run instructions + // Instructions start at bottom+2 + for i := bottom + 2; i < len(inp); i++ { + inst := strings.Fields(inp[i]) + count := h.Atoi(inst[1]) + from := h.Atoi(inst[3]) + to := h.Atoi(inst[5]) + + moveCrates(stacks, from, to, count) + } + + for i := range stacks { + fmt.Print(string(stacks[i][0])) + } + fmt.Println("") +} + +func getCrateHash(stacks [][]byte) string { + var ret []byte + for i := range stacks { + for j := range stacks[i] { + ret = append(ret, stacks[i][j]) + } + } + sort.Slice(ret, func(p, q int) bool { + return ret[p] > ret[q] + }) + return string(ret) +} +func validateCrates(valid string, stacks [][]byte) bool { + return valid == getCrateHash(stacks) +} + +func buildStacks(inp []string) ([][]byte, int) { + var stacks [][]byte + // Find the bottom + var bottom int + for i, row := range inp { + if len(row) > 1 && row[1] == '1' { + bottom = i + break + } + } + // Allocate stacks + stCnt := strings.Fields(inp[bottom]) + for i := 0; i < len(stCnt); i++ { + stacks = append(stacks, []byte{}) + } + + // Build stacks + for i := bottom - 1; i >= 0; i-- { + for stI := 0; stI < len(stCnt); stI++ { + pos := stI*4 + 1 + if len(inp[i]) >= pos && (inp[i][pos] >= 'A' && inp[i][pos] <= 'Z') { + stacks[stI] = append([]byte{inp[i][pos]}, stacks[stI]...) + } + } + } + return stacks, bottom +} + +func moveCrates(stacks [][]byte, from, to, count int) { + var x []byte + if count > 1 { + x, stacks[from-1] = stacks[from-1][0:count], stacks[from-1][count:] + } else { + x, stacks[from-1] = []byte{stacks[from-1][0]}, stacks[from-1][count:] + } + for i := len(x) - 1; i >= 0; i-- { + stacks[to-1] = append([]byte{x[i]}, stacks[to-1]...) + } +} + +func printStacks(stacks [][]byte) { + for i := range stacks { + fmt.Println(i+1, string(stacks[i])) + } +} diff --git a/2022/day05/problem b/2022/day05/problem new file mode 100644 index 0000000..b1881a5 --- /dev/null +++ b/2022/day05/problem @@ -0,0 +1,161 @@ +Advent of Code +br0xen (AoC++) 10* + +--- Day 5: Supply Stacks --- + + The expedition can depart as soon as the final supplies have been unloaded from the + ships. Supplies are stored in stacks of marked crates, but because the needed supplies + are buried under many other crates, the crates need to be rearranged. + + The ship has a giant cargo crane capable of moving crates between stacks. To ensure none + of the crates get crushed or fall over, the crane operator will rearrange them in a + series of carefully-planned steps. After the crates are rearranged, the desired crates + will be at the top of each stack. + + The Elves don't want to interrupt the crane operator during this delicate procedure, but + they forgot to ask her which crate will end up where, and they want to be ready to unload + them as soon as possible so they can embark. + + They do, however, have a drawing of the starting stacks of crates and the rearrangement + procedure (your puzzle input). For example: + + [D] + [N] [C] + [Z] [M] [P] + 1 2 3 + + move 1 from 2 to 1 + move 3 from 1 to 3 + move 2 from 2 to 1 + move 1 from 1 to 2 + + In this example, there are three stacks of crates. Stack 1 contains two crates: crate Z + is on the bottom, and crate N is on top. Stack 2 contains three crates; from bottom to + top, they are crates M, C, and D. Finally, stack 3 contains a single crate, P. + + Then, the rearrangement procedure is given. In each step of the procedure, a quantity of + crates is moved from one stack to a different stack. In the first step of the above + rearrangement procedure, one crate is moved from stack 2 to stack 1, resulting in this + configuration: + + [D] + [N] [C] + [Z] [M] [P] + 1 2 3 + + In the second step, three crates are moved from stack 1 to stack 3. Crates are moved one + at a time, so the first crate to be moved (D) ends up below the second and third crates: + + [Z] + [N] + [C] [D] + [M] [P] + 1 2 3 + + Then, both crates are moved from stack 2 to stack 1. Again, because crates are moved one + at a time, crate C ends up below crate M: + + [Z] + [N] + [M] [D] + [C] [P] + 1 2 3 + + Finally, one crate is moved from stack 1 to stack 2: + + [Z] + [N] + [D] + [C] [M] [P] + 1 2 3 + + The Elves just need to know which crate will end up on top of each stack; in this + example, the top crates are C in stack 1, M in stack 2, and Z in stack 3, so you should + combine these together and give the Elves the message CMZ. + + After the rearrangement procedure completes, what crate ends up on top of each stack? + + Your puzzle answer was PTWLTDSJV. + +--- Part Two --- + + As you watch the crane operator expertly rearrange the crates, you notice the process + isn't following your prediction. + + Some mud was covering the writing on the side of the crane, and you quickly wipe it away. + The crane isn't a CrateMover 9000 - it's a CrateMover 9001. + + The CrateMover 9001 is notable for many new and exciting features: air conditioning, + leather seats, an extra cup holder, and the ability to pick up and move multiple crates + at once. + + Again considering the example above, the crates begin in the same configuration: + + [D] + [N] [C] + [Z] [M] [P] + 1 2 3 + + Moving a single crate from stack 2 to stack 1 behaves the same as before: + + [D] + [N] [C] + [Z] [M] [P] + 1 2 3 + + However, the action of moving three crates from stack 1 to stack 3 means that those three + moved crates stay in the same order, resulting in this new configuration: + + [D] + [N] + [C] [Z] + [M] [P] + 1 2 3 + + Next, as both crates are moved from stack 2 to stack 1, they retain their order as well: + + [D] + [N] + [C] [Z] + [M] [P] + 1 2 3 + + Finally, a single crate is still moved from stack 1 to stack 2, but now it's crate C that + gets moved: + + [D] + [N] + [Z] + [M] [C] [P] + 1 2 3 + + In this example, the CrateMover 9001 has put the crates in a totally different order: + MCD. + + Before the rearrangement process finishes, update your simulation so that the Elves know + where they should stand to be ready to unload the final supplies. After the rearrangement + procedure completes, what crate ends up on top of each stack? + + Your puzzle answer was WZMFVGGZP. + + Both parts of this puzzle are complete! They provide two gold stars: ** + +References + + Visible links + . https://adventofcode.com/ + . https://adventofcode.com/2022/about + . https://adventofcode.com/2022/events + . https://adventofcode.com/2022/settings + . https://adventofcode.com/2022/auth/logout + . Advent of Code Supporter + https://adventofcode.com/2022/support + . https://adventofcode.com/2022 + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/support + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022/leaderboard + . https://adventofcode.com/2022/stats + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/day/5/input diff --git a/2022/day05/testinput b/2022/day05/testinput new file mode 100644 index 0000000..42ef47f --- /dev/null +++ b/2022/day05/testinput @@ -0,0 +1,9 @@ + [D] +[N] [C] +[Z] [M] [P] + 1 2 3 + +move 1 from 2 to 1 +move 3 from 1 to 3 +move 2 from 2 to 1 +move 1 from 1 to 2 diff --git a/helpers/helpers.go b/helpers/helpers.go index ec8e9b7..00aef74 100644 --- a/helpers/helpers.go +++ b/helpers/helpers.go @@ -148,7 +148,7 @@ func Atoi(i string) int { var ret int var err error if ret, err = strconv.Atoi(i); err != nil { - log.Fatal("Invalid Atoi:", i) + log.Fatalf("Invalid Atoi: %s\n%v", i, err) } return ret } From 235801201faca5f1bd6bbda99e9e8ee2a972f745 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Tue, 6 Dec 2022 07:04:10 -0600 Subject: [PATCH 6/7] 2022 Day 6 Complete! --- 2022/day06/input | 1 + 2022/day06/main.go | 51 ++++++++++++++++++++ 2022/day06/problem | 112 +++++++++++++++++++++++++++++++++++++++++++ 2022/day06/testinput | 1 + 4 files changed, 165 insertions(+) create mode 100644 2022/day06/input create mode 100644 2022/day06/main.go create mode 100644 2022/day06/problem create mode 100644 2022/day06/testinput diff --git a/2022/day06/input b/2022/day06/input new file mode 100644 index 0000000..0ba323b --- /dev/null +++ b/2022/day06/input @@ -0,0 +1 @@ +mgwwjddqzqdqsstctjjsdjsdsrsfsmfsfwwltwlwhwnhhlffzddgffwlffbsfshfshhgvvdrrltlzlnzznrrnrsnnhgnnfjnnvpnnbjjnwwrcwrrhlhvlhhmzmqzqrqtqmqpmpwwmssgsrgrgtgmtgmtgtdtvdvmvsvsbvsbvbtthmmftmmdnmddcrcvcrrfjfhhfjhffjllcpllmcctjtrttwmtwmwffrlrqlqzzpddsqdqqgjqgjgngwnncjnnvsnswwbzbtzzflzzqsqbsbvbmbnnjpnpnnpfpmpmnpmmjljtltssqnsqslstswtwswwjddvmmzlzqlzqzqjjlttmtrtbtmtgmtmsttrctrrsqrqvvrzrcrhhlnhllbfbtthrhdhllmwlmlgglgsgmgsmszzprpwpfprfftffpssjzjgzjzddqfqmmwqwvwlvlqqtbtwwrwttmsmppbmmpcmctcnnhssnjncnlcnctcjjrzrwrfwfcwffczztrtsrtstlsssljssmvssjzssrqqrcqqwlqwlwffsflssrrzhzzhrzzdgdppspwplpqptttvddggzszccrrnzzwwdwjddrvvwggpvgpvvhdhqddffrnngcncjcjlcchrrftrrjccrcrqqgcglcgcscmmlzmmtcmcffwfcfrcrggdmggdvvnrvnnphnngzzpdpgpspqqgrrnffmfpmffmgfmmjmzztlljlggljjcnnrqnqpnqndnffnwwbpwpjwjjlslmsmtmtjttsvsggrmmdpmmcjjswsqqwfwwrwffczfzggqvggdlldhllsdsfdsdhhmmzmjjmpjpddsccqrrjhjlhjjcnnpwnnffjwwcsszrrnmnsmnnjbnndwnnnhnwwjtwtlwtwqqbnqnbnqqfjfdjdbbwbqwqpqggbcbhhtrtqrrddpdwdlwdddzvzwvvdfdpdcdvdtdpttwwdzdzmdmqmzmnzmnmhmwmjwwshhcqcpcvvzgzdggnjnnhwnhhswwvccqrqlqggcngnmggmffblbglltlstshhrjjlvlppsqslljtjtgglvltvlvmllhrhdrrmqrmqmjjdcjjppqwwllvsvsrszslsvvghvvhmmfbfvfpfmmvdvppwggtrrjvvsbbzffbmffpqqqhnhncclzczwcwpwssrprfrsrbsbnbvnnwzwqqpsqsspmssztssstrtcczsznzvvpvttnssdjdhjddngdgvvmsszbzsbsmbbgsbgsgmmhwhghrhjhphshchgglmlvlhlbhlldwdggdsscvcbcssfbbvggvwwtstltrrwttjdtdvttlsttfhfmhhcbclbcbffqqslshlldhdqhhjwwlffrbrdbrrgcrrfmffbhhlslrslrslrlsrsnsnvvqfqnnfdfmfmttmcmcrrcmmmjttjvtvvjbjqjnnbtbnblbtlblplgltlqltlztzvvtdvvtpvvwdwfflbflfrrhbrbbmjmcjmccztzwwjzwwzwdzdnnwcclbllqgghjhlhthwrdglrmcpbmtrnrdtvjrpmzqmljzzrtpzsrhnjrsdmpnsgdhvqchcfqjqdncjqfnscwjqvszpzzfhpjljmvsqnjzmrsgsbzlvrddtdmwbwwgprlvdfflrpztdzrhtmlzrrtdmpmcprqzzwlnmfjvsrltfjgcnnfllnzmbjcbthvbffczsspmczrpgpdjmvrvfmprfmnqdcnfwwvgdrwvrbtlqmhrrjvtrmmgrlprtnzdlszgbtbwztdrmpmlfblshzcnsczlblgwzrpnlccwhmcqhssmpznbdnnqgzzmjprjttdjhmjbmgqvzblsjwmplzsthrswhsdbvtqgrfzmbpqtpqgqdqcvzlgjrtvrhvzgmcmrwdmfpdvjddsmmsnvrdgnsbsdzcbprbqchqcgnwmfsrmqtrcdhdtzztbvmpblftwqlmlmmjcjhhjlgnnhljnncvbnjhgbjrltlwscswgvqmcnssbcdrtbgnhgmpmvjwtrbrbrdbdqfrncvhdstwztwcpbjrjwzmdlwvlvmsrhghjwjnjstbcqjqtjrgcvhzjdhdgbgdlhvjmztwvhgzzggwwhhhzvtrldchztmwfjvnqnvhnwpfvzzvnlvsccmvsngzgtnttssmdmhwzlhtpnfhczsdfnrstbwvwpqmslcvpvhfzttzhsgzpbhqdtswshljpncznjhzmgvvbcllmzprhrvwljwcjpcdqmwbzvsdcgtmwnrhswsgqhwpwhbjpnhnpjvgsqcjltzrqvqfflcdcvpwnznvtqbfbtlpmtdgbbwdwncqsqnbtgfdzzqzzvjnwmzdmlgstmnjwznjqghglvmwjzlqrnddcqhgndlhlbmqdhrqgrjqztnhpzssnwmrqclmwpgbvfrvgqqvtthznsqwgndjrprbgrhcvhpzbfhdmgnhsrqjvjstbtmnltsbjfzczvjqnhtldqclsflbhvvlzjwrqqgbgpwqwpfjctqpzdqwcfstmwbzgrgrtzngljjnvtggrqcbgjwtqsdgwmfjqppnzgfsfdmlctztbhnntnntdlvrsdvnllvmpggjzspqfhzwrttwzpqrnqjhmpjnmrzrpnqzshcqgctbtflqflcrzpmnphgbbghhwzplljwngbtffwmrwggdztvtfgwldlswqvjptvbfvnbpglhgrdgcfmvrslqldmwjqvjpvwgpjddvglllvpqwvbchqsmjrncgvgmqbsbcwfbsbpqcqzjfpcdzszgmvqgqjlflpfzbsrhsrzrdbpssrjbcfhvztftlzqpsglpwhbscgwdlbgghzsbwznnbgnnsgjghmmpmmrmqmdhnflgvgprqfcbpzbcpjscvnpfrmtvzsbflmffvcfsvdsggzdqtppcjzphcqwrqtrczqmwcdmdqndzmhdpnfqsbndnvjlzrsjzmpcrfgjwccsdtzvslccwhlvzjwjgvwpsnsggmqgsjfbwmjstsgnqmtjhljvfnflnngdrqvscwlqqdsglhghczhjdvgrjcqblmncdbjvsbwgptgpvvzhcjgjnvttrgzrjnqlvfbrmpzdcbbnnrqptpzpssznbsrstdphbgdrsnrhcjwwgsncdzvqfnmnvqcmcgdgjdbqjzdrvvbvhjdfcqndmqwscmsvppclzrhgbldqtwctbdhpbbwfvwpcpsvddmrhqbhlrrmrblnmqqqbwvcwwbwprlmhtdncmjhmjgphmrrhcdrqgmcrzwsznqzpngbtsvjgglrddhjflbrhvqwmmhmqzhphwnvqwzczdvqjsnlhfqbcgddtwgnlcgbfqmzfpqmnbpvfhdhjlnwtrlmggtbfnfvmqrzjvjjvffctsrwgfcpghhnzqmwtlsfhjrvqpwqhngrhpswslsvtgnbvbmwsfwmpntfsfpshrjzvghhpvnlbmnrhltfpmqdwzfhztvhlmbnmhnbvdzbbtczvwbvwtvjghhjjrtgbrqrhmbgvssstdwztdmdsqtctghjhsnpslqttdlvndmjfnmdzwrblfjqcwptfttvlcgsvwcbmfzbdlmrtchgqlfspwznbzfjthjtfwshqgfsfdsmzsmpptzschlzjshvfwtmpszvrvlggbrgpcnqwndhjjprztdfddblhfljbvttfvhchhdfsftrhccrbncmhwpcpwfqthngcqptmvsmpcswdrdlcbqvvhwmcqqwbzlblrgfcrrndwdvlvnpjvwchzjzmgrqhzzmgqqdsdflpclpdtlhvhcthzjfbvjvzsnbvwfsnglvbnwnbgrqwpbgclhjhztttbjwvmlmmgmzncbwswncqhmcfjfnwnpbrmchhpgwngrfwgdfdqmblwlghdjvdhjftdblrtcvvgbvpmbjhfwgpmghqbqrcpgfvhtvqtlbjdblggcpjzlrhpbsqwntfhbhwwszpdlsgbpfqhvrjrhsldcgvqhqmwdfcrcmhrvvwvbrfsrrcvwzhqqvgltlnhwhdrhrdqsvmdzjwgmqdsccwhcgwltfhdfqpsltjccwsttmrc diff --git a/2022/day06/main.go b/2022/day06/main.go new file mode 100644 index 0000000..b7907bd --- /dev/null +++ b/2022/day06/main.go @@ -0,0 +1,51 @@ +package main + +import ( + "fmt" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToString() + fmt.Println("# Part 1") + fmt.Printf("First Start of Packet @ %d\n", findFirstStartOfPacket(inp)) + fmt.Println("") + fmt.Println("# Part 2") + fmt.Printf("First Start of Message @ %d\n", findFirstStartOfMessage(inp)) +} + +func findFirstStartOfPacket(inp string) int { + return findFirstWithXUnique(inp, 4) +} + +func findFirstStartOfMessage(inp string) int { + return findFirstWithXUnique(inp, 14) +} + +func findFirstWithXUnique(inp string, x int) int { + for i := range inp { + if i < x { + continue + } + if findUniqueCountBefore(inp, i) >= x { + return i + 1 + } + } + return -1 +} + +func findUniqueCountBefore(inp string, pos int) int { + if len(inp) < pos { + return -1 + } + counts := make(map[byte]int) + for i := pos; i >= 0; i-- { + if _, ok := counts[inp[i]]; !ok { + counts[inp[i]]++ + } else { + return len(counts) + } + } + return pos +} diff --git a/2022/day06/problem b/2022/day06/problem new file mode 100644 index 0000000..bb0b4a7 --- /dev/null +++ b/2022/day06/problem @@ -0,0 +1,112 @@ +Advent of Code +br0xen (AoC++) 12* +{ʼyearʼ:2022} + +--- Day 6: Tuning Trouble --- + + The preparations are finally complete; you and the Elves leave camp on + foot and begin to make your way toward the star fruit grove. + + As you move through the dense undergrowth, one of the Elves gives you a + handheld device. He says that it has many fancy features, but the most + important one to set up right now is the communication system. + + However, because he's heard you have significant experience dealing with + signal-based systems, he convinced the other Elves that it would be okay + to give you their one malfunctioning device - surely you'll have no + problem fixing it. + + As if inspired by comedic timing, the device emits a few colorful sparks. + + To be able to communicate with the Elves, the device needs to lock on to + their signal. The signal is a series of seemingly-random characters that + the device receives one at a time. + + To fix the communication system, you need to add a subroutine to the + device that detects a start-of-packet marker in the datastream. In the + protocol being used by the Elves, the start of a packet is indicated by a + sequence of four characters that are all different. + + The device will send your subroutine a datastream buffer (your puzzle + input); your subroutine needs to identify the first position where the + four most recently received characters were all different. Specifically, + it needs to report the number of characters from the beginning of the + buffer to the end of the first such four-character marker. + + For example, suppose you receive the following datastream buffer: + + mjqjpqmgbljsphdztnvjfqwrcgsmlb + + After the first three characters (mjq) have been received, there haven't + been enough characters received yet to find the marker. The first time a + marker could occur is after the fourth character is received, making the + most recent four characters mjqj. Because j is repeated, this isn't a + marker. + + The first time a marker appears is after the seventh character arrives. + Once it does, the last four characters received are jpqm, which are all + different. In this case, your subroutine should report the value 7, + because the first start-of-packet marker is complete after 7 characters + have been processed. + + Here are a few more examples: + + • bvwbjplbgvbhsrlpgdmjqwftvncz: first marker after character 5 + • nppdvjthqldpwncqszvftbrmjlhg: first marker after character 6 + • nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: first marker after character 10 + • zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: first marker after character 11 + + How many characters need to be processed before the first start-of-packet + marker is detected? + + Your puzzle answer was 1544. + +--- Part Two --- + + Your device's communication system is correctly detecting packets, but + still isn't working. It looks like it also needs to look for messages. + + A start-of-message marker is just like a start-of-packet marker, except it + consists of 14 distinct characters rather than 4. + + Here are the first positions of start-of-message markers for all of the + above examples: + + • mjqjpqmgbljsphdztnvjfqwrcgsmlb: first marker after character 19 + • bvwbjplbgvbhsrlpgdmjqwftvncz: first marker after character 23 + • nppdvjthqldpwncqszvftbrmjlhg: first marker after character 23 + • nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: first marker after character 29 + • zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: first marker after character 26 + + How many characters need to be processed before the first start-of-message + marker is detected? + + Your puzzle answer was 2145. + + Both parts of this puzzle are complete! They provide two gold stars: ** + +References + + Visible links + . https://adventofcode.com/ + . https://adventofcode.com/2022/about + . https://adventofcode.com/2022/events + . https://adventofcode.com/2022/settings + . https://adventofcode.com/2022/auth/logout + . Advent of Code Supporter + https://adventofcode.com/2022/support + . https://adventofcode.com/2022 + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/support + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022/leaderboard + . https://adventofcode.com/2022/stats + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2016/day/6 + . https://adventofcode.com/2016/day/25 + . https://adventofcode.com/2019/day/7 + . https://adventofcode.com/2019/day/9 + . https://adventofcode.com/2019/day/16 + . https://adventofcode.com/2021/day/25 + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/day/6/input diff --git a/2022/day06/testinput b/2022/day06/testinput new file mode 100644 index 0000000..7980a82 --- /dev/null +++ b/2022/day06/testinput @@ -0,0 +1 @@ +mjqjpqmgbljsphdztnvjfqwrcgsmlb From e7892906d678209484d1169f7ee07b0d01452740 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Wed, 7 Dec 2022 07:51:21 -0600 Subject: [PATCH 7/7] 2022 Day 7 Complete! --- 2022/day07/input | 1091 ++++++++++++++++++++++++++++++++++++++++++ 2022/day07/main.go | 212 ++++++++ 2022/day07/problem | 151 ++++++ 2022/day07/testinput | 23 + 4 files changed, 1477 insertions(+) create mode 100644 2022/day07/input create mode 100644 2022/day07/main.go create mode 100644 2022/day07/problem create mode 100644 2022/day07/testinput diff --git a/2022/day07/input b/2022/day07/input new file mode 100644 index 0000000..3a8fce3 --- /dev/null +++ b/2022/day07/input @@ -0,0 +1,1091 @@ +$ cd / +$ ls +dir fts +dir jnwr +dir lrvl +dir nzgprvw +dir snwqjgj +16394 tllvcdr.sjl +195891 zbdp.gqb +dir zddrb +$ cd fts +$ ls +dir dlqtffw +dir rbfmmjvd +254713 wvwhrb.dhh +$ cd dlqtffw +$ ls +73533 nqbvg.fgd +$ cd .. +$ cd rbfmmjvd +$ ls +290697 zcgrgff.fnf +$ cd .. +$ cd .. +$ cd jnwr +$ ls +323577 ghmtnzr +57588 tdcbdpnr +dir wbv +dir zzbvdcf +$ cd wbv +$ ls +dir nmdwbnnr +253584 slzdbm.ncn +$ cd nmdwbnnr +$ ls +208370 scbcsb.pjg +$ cd .. +$ cd .. +$ cd zzbvdcf +$ ls +8052 ssssrhwz +$ cd .. +$ cd .. +$ cd lrvl +$ ls +dir bqqltcg +189288 cwpwh +90813 jhnddzml.lww +dir pwc +dir rjl +dir rzvqvv +dir slzdbm +dir tcbjmq +140665 zbdp.gqb +dir zhbpqlnd +$ cd bqqltcg +$ ls +dir dlbjblbf +dir fdlw +dir jnwr +dir slzdbm +dir zcgrgff +$ cd dlbjblbf +$ ls +11732 rnsrrf.rtv +$ cd .. +$ cd fdlw +$ ls +dir hlvpfw +228436 mzsfcvgv.pqw +$ cd hlvpfw +$ ls +dir dhwq +$ cd dhwq +$ ls +127459 cgdpqh.tct +58310 jnwr.nqt +$ cd .. +$ cd .. +$ cd .. +$ cd jnwr +$ ls +305998 ssssrhwz +129135 vrt.qdt +86204 wnvm.bld +$ cd .. +$ cd slzdbm +$ ls +40915 zbdp.gqb +120991 zsvffwlt.rbp +$ cd .. +$ cd zcgrgff +$ ls +94614 jnwr.mqm +191626 zbdp.gqb +dir ztrslh +$ cd ztrslh +$ ls +dir bhzn +201167 dvcjtzvs.rvd +dir slzdbm +dir szrth +dir zcp +$ cd bhzn +$ ls +119164 qbgmrqw +102090 zbdp.gqb +$ cd .. +$ cd slzdbm +$ ls +124928 gtdq +$ cd .. +$ cd szrth +$ ls +dir hpbbsq +dir vlwlsdjp +dir zcgrgff +$ cd hpbbsq +$ ls +151717 qsdhff.jsv +$ cd .. +$ cd vlwlsdjp +$ ls +15049 glpdjtq.mwm +302526 jnwr.tds +9550 lhwtbh +22857 ssssrhwz +$ cd .. +$ cd zcgrgff +$ ls +73640 mpq.cdn +dir zcgrgff +$ cd zcgrgff +$ ls +115955 rssmrfbq.trs +$ cd .. +$ cd .. +$ cd .. +$ cd zcp +$ ls +dir qdjtmwrr +dir wpdjttm +$ cd qdjtmwrr +$ ls +138185 jnwr +$ cd .. +$ cd wpdjttm +$ ls +207755 vvwtghjb +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd pwc +$ ls +15911 fqw +$ cd .. +$ cd rjl +$ ls +119274 ssssrhwz +$ cd .. +$ cd rzvqvv +$ ls +273935 ssssrhwz +$ cd .. +$ cd slzdbm +$ ls +dir hlvpfw +290414 lgzbzjvd.glj +dir ljpmphn +316440 slzdbm.tsj +$ cd hlvpfw +$ ls +dir mhvmszgh +107004 slzdbm +$ cd mhvmszgh +$ ls +dir tftstdp +$ cd tftstdp +$ ls +176794 mpq.cdn +$ cd .. +$ cd .. +$ cd .. +$ cd ljpmphn +$ ls +37528 slfdb.bqt +$ cd .. +$ cd .. +$ cd tcbjmq +$ ls +96506 lrz.nhb +$ cd .. +$ cd zhbpqlnd +$ ls +14027 ccswrthv.pfd +dir clnqtjz +dir fdsqmnn +dir fwdt +dir nljb +dir npmsdrgp +57812 slfdb.bqt +184299 wmlmg +241025 zcgrgff.wbh +dir zggqfj +$ cd clnqtjz +$ ls +62391 cbhw.wgr +309318 jlm.lfq +dir mzsfcvgv +dir rrn +307583 ssssrhwz +$ cd mzsfcvgv +$ ls +1356 hrbh.wpz +dir vnwqstw +$ cd vnwqstw +$ ls +184434 hnhzdshl.lrl +150624 wsrnprdb.pjf +$ cd .. +$ cd .. +$ cd rrn +$ ls +105792 dzprqqc.rbh +107482 ffdjdbc +dir hnr +dir rdmgtf +dir rgrwp +325147 shqr.pdj +43186 slfdb.bqt +236667 zcgrgff +$ cd hnr +$ ls +dir gljrlhjm +250526 mzsfcvgv.nsb +43164 ssssrhwz +$ cd gljrlhjm +$ ls +dir wjwqrnj +$ cd wjwqrnj +$ ls +142366 gshl.qfc +$ cd .. +$ cd .. +$ cd .. +$ cd rdmgtf +$ ls +193562 gdrdnc.vml +123723 hmqfdht +dir lzfntb +dir mjfwsmgd +208819 nqbgcn.qfq +dir tqh +$ cd lzfntb +$ ls +dir gwnpsvw +dir rsgwzhp +103487 scvllbjh.pnw +$ cd gwnpsvw +$ ls +dir lqnz +81937 zbdp.gqb +$ cd lqnz +$ ls +27250 zcgrgff +$ cd .. +$ cd .. +$ cd rsgwzhp +$ ls +dir hhz +$ cd hhz +$ ls +46435 djvfz +$ cd .. +$ cd .. +$ cd .. +$ cd mjfwsmgd +$ ls +25726 clcvm +170085 zbdp.gqb +$ cd .. +$ cd tqh +$ ls +111272 gdq.llg +3215 hdghs +dir lpdcdr +dir vhfr +$ cd lpdcdr +$ ls +203902 hmqfdht +$ cd .. +$ cd vhfr +$ ls +91584 hmqfdht +dir stmvj +$ cd stmvj +$ ls +315660 wwpq.ffq +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd rgrwp +$ ls +dir dhwtfld +187439 hmqfdht +dir jnwr +dir npr +dir sdsppq +228581 twd.nnc +42349 wbf.cwb +194162 zbdp.gqb +224441 zcgrgff.qpg +$ cd dhwtfld +$ ls +152381 dqdrd +$ cd .. +$ cd jnwr +$ ls +229758 hmvw.gdz +92710 mzsfcvgv.cdd +79954 stjtn.gft +89831 zbdp.gqb +$ cd .. +$ cd npr +$ ls +52767 hlvpfw.rqb +dir nrbjzvgq +270579 pbsq.msg +240181 slfdb.bqt +dir znbwnh +$ cd nrbjzvgq +$ ls +295237 bwqqvn +229608 dhrjnvtt.lvm +55391 nlvn +dir zcgrgff +$ cd zcgrgff +$ ls +124604 hlvpfw.mlw +$ cd .. +$ cd .. +$ cd znbwnh +$ ls +228293 zcgrgff +$ cd .. +$ cd .. +$ cd sdsppq +$ ls +235741 bcsdzpfj.lvd +dir jnwr +dir njtrhrfm +dir tvq +dir wshgn +$ cd jnwr +$ ls +273541 brcps +dir gjt +dir hlvpfw +dir nbsdvpnj +dir zcgrgff +$ cd gjt +$ ls +184707 zbdp.gqb +$ cd .. +$ cd hlvpfw +$ ls +242810 zcgrgff +$ cd .. +$ cd nbsdvpnj +$ ls +181797 hlvpfw.gsd +294284 hmqfdht +215098 mqbclwwq +$ cd .. +$ cd zcgrgff +$ ls +188814 hmqfdht +$ cd .. +$ cd .. +$ cd njtrhrfm +$ ls +dir dqpjdztt +$ cd dqpjdztt +$ ls +178036 vwg +$ cd .. +$ cd .. +$ cd tvq +$ ls +233085 rmq.zgq +215613 slzdbm.wvf +$ cd .. +$ cd wshgn +$ ls +209007 jnwr.hsr +dir ntrlll +$ cd ntrlll +$ ls +245558 jnwr.tbr +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd fdsqmnn +$ ls +dir dfl +dir hqffnmq +268076 zcgrgff.cfm +dir ztc +$ cd dfl +$ ls +5553 bbvqpgf +128390 lqtvvc.tdj +190189 vnmfcdws +$ cd .. +$ cd hqffnmq +$ ls +28438 ssssrhwz +$ cd .. +$ cd ztc +$ ls +247470 slfdb.bqt +$ cd .. +$ cd .. +$ cd fwdt +$ ls +60342 bdwbzpzz +dir cdcc +dir jldlzttm +261042 ssssrhwz +dir sws +293090 zbdp.gqb +93624 zcgrgff.vgh +$ cd cdcc +$ ls +dir cwpfczr +dir lsrgfml +$ cd cwpfczr +$ ls +303853 wzz.chs +$ cd .. +$ cd lsrgfml +$ ls +63205 hmqfdht +$ cd .. +$ cd .. +$ cd jldlzttm +$ ls +184715 brclwptp +309967 gdbfh.vhn +5460 hlvpfw.fwb +46159 jnwr.ggw +173896 zbdp.gqb +$ cd .. +$ cd sws +$ ls +dir hlvpfw +75133 nqrp.jdg +$ cd hlvpfw +$ ls +71403 cvdd.whl +$ cd .. +$ cd .. +$ cd .. +$ cd nljb +$ ls +105380 lrhmdl +$ cd .. +$ cd npmsdrgp +$ ls +176062 bhm.gfd +dir dgdl +24535 fdfmntpt.qvp +dir jnwr +279503 ssssrhwz +4671 zbdp.gqb +$ cd dgdl +$ ls +4624 qqcp.rcg +$ cd .. +$ cd jnwr +$ ls +dir cvw +122648 hmqfdht +26565 jnwr.fst +271544 jnwr.tqb +170968 mpq.cdn +dir ncqflwrb +103826 qgzlff.frl +dir wclwg +dir wtcfswt +$ cd cvw +$ ls +58583 pjthqdbr.zzh +398 ssssrhwz +$ cd .. +$ cd ncqflwrb +$ ls +105747 wwstfng.cdl +$ cd .. +$ cd wclwg +$ ls +75020 wbq +$ cd .. +$ cd wtcfswt +$ ls +182813 dnln +255923 hmqfdht +$ cd .. +$ cd .. +$ cd .. +$ cd zggqfj +$ ls +dir gpnfpv +dir gzfsnbv +186684 jnwr +dir msrz +$ cd gpnfpv +$ ls +dir hlvpfw +$ cd hlvpfw +$ ls +186814 bgqpn +41444 mzsfcvgv.qpp +292879 zcgrgff +$ cd .. +$ cd .. +$ cd gzfsnbv +$ ls +321796 jnwr.ghb +dir sdgwjtf +$ cd sdgwjtf +$ ls +127216 mzsfcvgv.qlv +$ cd .. +$ cd .. +$ cd msrz +$ ls +dir fzl +32371 jqtgpzw.thg +271389 slfdb.bqt +270845 tchtnp.rsw +146371 zmwbmj +$ cd fzl +$ ls +140610 ssssrhwz +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd nzgprvw +$ ls +dir hgfdbf +218138 mpq.cdn +73419 slfdb.bqt +dir vfztvnjm +269866 wldptfv.bbb +dir zgdsgh +$ cd hgfdbf +$ ls +163792 ssssrhwz +262305 zcgrgff +$ cd .. +$ cd vfztvnjm +$ ls +139863 hlvpfw +138410 hmqfdht +$ cd .. +$ cd zgdsgh +$ ls +194820 dhp.tgt +dir hlvpfw +dir sdllphqd +dir zcgrgff +$ cd hlvpfw +$ ls +44509 hmqfdht +$ cd .. +$ cd sdllphqd +$ ls +47133 mpq.cdn +$ cd .. +$ cd zcgrgff +$ ls +186613 jrrpljrc +$ cd .. +$ cd .. +$ cd .. +$ cd snwqjgj +$ ls +dir slzdbm +dir zcgrgff +dir zldscsc +$ cd slzdbm +$ ls +21422 dplgjzvs.nrn +175310 zcgrgff.dfq +$ cd .. +$ cd zcgrgff +$ ls +dir rrfhvjf +275455 vwnvj.nhb +dir zcgrgff +$ cd rrfhvjf +$ ls +69149 mqmwv.jmr +$ cd .. +$ cd zcgrgff +$ ls +dir zcgrgff +$ cd zcgrgff +$ ls +183398 hmqfdht +93968 sdhmwd +$ cd .. +$ cd .. +$ cd .. +$ cd zldscsc +$ ls +dir fmzvccvg +299187 mpq.cdn +324288 mzsfcvgv.srz +dir prdfldrf +dir sgpdqw +289150 ssssrhwz +3330 vwwj +133537 wbb.fdl +dir wjdpws +$ cd fmzvccvg +$ ls +dir brrlg +dir crm +dir mzsfcvgv +$ cd brrlg +$ ls +17776 jnwr.qqz +$ cd .. +$ cd crm +$ ls +220545 mltrj +177044 mzsfcvgv.thj +$ cd .. +$ cd mzsfcvgv +$ ls +51223 pdnbml.qpg +$ cd .. +$ cd .. +$ cd prdfldrf +$ ls +213872 ftw +$ cd .. +$ cd sgpdqw +$ ls +205684 whrfvw.dph +$ cd .. +$ cd wjdpws +$ ls +dir hlvpfw +$ cd hlvpfw +$ ls +324522 zbdp.gqb +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd zddrb +$ ls +238213 dhrdjfzl.npj +28938 hlvpfw +313900 hlvpfw.bwd +dir pgbgpn +132967 rrhsr +dir slzdbm +142210 wlvpwjjz +dir zdhcp +$ cd pgbgpn +$ ls +dir jpmvrvt +154268 mpq.cdn +dir mzsfcvgv +dir vvmwgngv +$ cd jpmvrvt +$ ls +150157 ghcvqm +$ cd .. +$ cd mzsfcvgv +$ ls +93810 mjglpwbc.tvt +dir slzdbm +$ cd slzdbm +$ ls +dir jnwr +174522 slzdbm.ncl +$ cd jnwr +$ ls +183686 rpwjvc +$ cd .. +$ cd .. +$ cd .. +$ cd vvmwgngv +$ ls +dir bqc +dir mzsfcvgv +dir qgj +dir wfjzls +$ cd bqc +$ ls +191442 bqsn +dir lmnvtg +278861 mpq.cdn +191779 mthgd.mjp +dir mzsfcvgv +dir twzq +$ cd lmnvtg +$ ls +dir dzdd +7920 hmqfdht +dir rnlctfm +dir slzdbm +213184 zcgrgff.vln +$ cd dzdd +$ ls +dir jnwr +$ cd jnwr +$ ls +71772 hlvpfw +$ cd .. +$ cd .. +$ cd rnlctfm +$ ls +282289 jvnmblr.mdc +24454 ssssrhwz +$ cd .. +$ cd slzdbm +$ ls +316131 mzsfcvgv.czz +$ cd .. +$ cd .. +$ cd mzsfcvgv +$ ls +dir nsvn +dir plj +dir tvmv +$ cd nsvn +$ ls +dir bcmd +dir jcjsp +dir jnwr +$ cd bcmd +$ ls +206778 cpljbvm.vws +86096 lfgjnzhw.rtm +$ cd .. +$ cd jcjsp +$ ls +188389 zbdp.gqb +$ cd .. +$ cd jnwr +$ ls +293633 jhh.wtj +$ cd .. +$ cd .. +$ cd plj +$ ls +323119 qgs +221100 ssssrhwz +264549 zbdp.gqb +$ cd .. +$ cd tvmv +$ ls +198197 mpq.cdn +$ cd .. +$ cd .. +$ cd twzq +$ ls +dir hwgndwpj +$ cd hwgndwpj +$ ls +dir srdzqqf +$ cd srdzqqf +$ ls +101738 slzdbm +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd mzsfcvgv +$ ls +dir hlvpfw +dir vbdw +$ cd hlvpfw +$ ls +270309 wncrt +$ cd .. +$ cd vbdw +$ ls +dir csw +$ cd csw +$ ls +231750 dcjr.jgb +297504 mpq.cdn +215564 plm.rtl +$ cd .. +$ cd .. +$ cd .. +$ cd qgj +$ ls +192181 hmqfdht +dir lmp +250495 mpq.cdn +dir slzdbm +253262 ssssrhwz +dir tzth +$ cd lmp +$ ls +dir jnwr +$ cd jnwr +$ ls +284951 zcgrgff.slq +$ cd .. +$ cd .. +$ cd slzdbm +$ ls +266715 hzbq.plc +dir jnwr +11379 mzsfcvgv.rbw +dir slzdbm +$ cd jnwr +$ ls +108636 mpq.cdn +324035 zzvmlrj.rrl +$ cd .. +$ cd slzdbm +$ ls +68393 zbdp.gqb +$ cd .. +$ cd .. +$ cd tzth +$ ls +12884 hlvpfw.gwl +146470 jnwr +$ cd .. +$ cd .. +$ cd wfjzls +$ ls +191088 hlvpfw.prw +64712 mpq.cdn +103828 pjhg.qmc +dir qvmdt +$ cd qvmdt +$ ls +244001 ssssrhwz +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd slzdbm +$ ls +dir hsvbbbp +dir jdtrdgqs +dir lrldsqcr +194137 mzsfcvgv.hnv +dir nzcbqzdz +$ cd hsvbbbp +$ ls +104752 rcfpnh.vlr +185473 slzdbm.dbr +dir vpwf +dir zhngz +$ cd vpwf +$ ls +266988 frhvp.ltf +82931 mpq.cdn +$ cd .. +$ cd zhngz +$ ls +181282 drtfhrhp +$ cd .. +$ cd .. +$ cd jdtrdgqs +$ ls +37106 hdjl.rrr +$ cd .. +$ cd lrldsqcr +$ ls +dir brwcprn +dir hlvpfw +dir jnwr +dir slzdbm +dir wrmr +dir zjrdgf +dir zrpqf +$ cd brwcprn +$ ls +dir bmjwts +$ cd bmjwts +$ ls +157148 jwbd +251396 qtgc +$ cd .. +$ cd .. +$ cd hlvpfw +$ ls +121723 zbdp.gqb +$ cd .. +$ cd jnwr +$ ls +240747 gfrrtdh +$ cd .. +$ cd slzdbm +$ ls +176832 jnwr +36125 ltwmzw.fdl +132059 plqmwhr.hhv +85540 slzdbm.wzm +23459 zhbwh.cds +$ cd .. +$ cd wrmr +$ ls +90357 zbdp.gqb +$ cd .. +$ cd zjrdgf +$ ls +301679 qbmt.vhh +12942 slfdb.bqt +$ cd .. +$ cd zrpqf +$ ls +241851 pnsdlbs.brw +$ cd .. +$ cd .. +$ cd nzcbqzdz +$ ls +182963 qgg.zsc +dir qwjgb +301344 slfdb.bqt +299029 zbdp.gqb +$ cd qwjgb +$ ls +223978 rprrjp.hfd +164106 wlq.rcq +$ cd .. +$ cd .. +$ cd .. +$ cd zdhcp +$ ls +dir hbggp +dir mzsfcvgv +dir zdsvth +$ cd hbggp +$ ls +302339 qcmfdhvm +112806 rpb.vfl +$ cd .. +$ cd mzsfcvgv +$ ls +dir gpz +dir slzdbm +dir zvjv +$ cd gpz +$ ls +290264 fdl +158548 slfdb.bqt +$ cd .. +$ cd slzdbm +$ ls +dir hlvpfw +dir mzsfcvgv +dir zdcthssc +$ cd hlvpfw +$ ls +49287 zbdp.gqb +$ cd .. +$ cd mzsfcvgv +$ ls +dir gnmtggs +103244 jnwr.gtn +263736 slfdb.bqt +$ cd gnmtggs +$ ls +31665 qhthp.lfh +$ cd .. +$ cd .. +$ cd zdcthssc +$ ls +64408 cgbnzc.cgn +$ cd .. +$ cd .. +$ cd zvjv +$ ls +6088 gnpsb.dml +145405 llp.cbm +dir mgcg +dir nwl +dir rqznjmt +128194 zbdp.gqb +$ cd mgcg +$ ls +dir ngwvm +dir slzdbm +dir smd +dir smr +dir zcgrgff +$ cd ngwvm +$ ls +49186 hmqfdht +$ cd .. +$ cd slzdbm +$ ls +44434 rdcb +$ cd .. +$ cd smd +$ ls +dir fjd +dir rscdvnwt +dir wbhp +318166 zbdp.gqb +$ cd fjd +$ ls +14084 hlvpfw.ghn +$ cd .. +$ cd rscdvnwt +$ ls +6432 fzwpmjm.ntl +$ cd .. +$ cd wbhp +$ ls +dir czv +217474 dnq.cpq +36009 jnwr.zdv +32123 mpq.cdn +27607 mrm.sgs +107593 zbdp.gqb +$ cd czv +$ ls +60750 zcgrgff.mnr +$ cd .. +$ cd .. +$ cd .. +$ cd smr +$ ls +47204 zcgrgff.vsl +$ cd .. +$ cd zcgrgff +$ ls +317050 hjtfb +110272 jrbcbvjw +290867 ltfj.dvl +dir mzsfcvgv +130694 wnc.rnr +206448 zbdp.gqb +$ cd mzsfcvgv +$ ls +dir jnwr +$ cd jnwr +$ ls +20405 bjpvssjt +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd nwl +$ ls +254439 dlv +193910 hlvpfw +13603 hnsdntn.trz +2990 mpq.cdn +$ cd .. +$ cd rqznjmt +$ ls +250114 hlvpfw +189732 mzsfcvgv.vqv +144688 zcgrgff +$ cd .. +$ cd .. +$ cd .. +$ cd zdsvth +$ ls +150609 jnwr.rtr +173402 nftm.nwd +dir njhjrgmf +$ cd njhjrgmf +$ ls +295762 nchztlh.lcs diff --git a/2022/day07/main.go b/2022/day07/main.go new file mode 100644 index 0000000..7262d50 --- /dev/null +++ b/2022/day07/main.go @@ -0,0 +1,212 @@ +package main + +import ( + "errors" + "fmt" + "log" + "sort" + "strings" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToStringSlice() + part1(inp) + fmt.Println("") + part2(inp) +} + +func buildFileSystem(inp []string) *dir { + root := NewDir(nil, []string{}, "/") + cwd := root + for i := range inp { + if i == 0 { + // We've already done this + continue + } + pts := strings.Fields(inp[i]) + switch pts[0] { + case "$": + if pts[1] == "cd" { + if pts[2] == ".." { + cwd = cwd.Parent() + } else { + ch, err := cwd.ChangeDir(pts[2]) + if err != nil { + log.Fatalf("Failed to change directories: %s/%s, %s", strings.Join(cwd.Path(), "/"), pts[2], err.Error()) + } + cwd = ch + } + } + case "dir": + cwd.AddDir(pts[1]) + default: + cwd.AddFile(pts[1], h.Atoi(pts[0])) + } + } + return root +} + +func part1(inp []string) { + fmt.Println("# Part 1") + root := buildFileSystem(inp) + smallDirs := root.FindDirectoriesMaxSize(100000) + var sum int + for i := range smallDirs { + sum += smallDirs[i].Size() + } + fmt.Printf("Naive Size of Small Dirs: %d\n", sum) +} + +func part2(inp []string) { + fmt.Println("# Part 2") + root := buildFileSystem(inp) + total := 70000000 + required := 30000000 + used := root.Size() + needed := required - (total - used) + dir := root.FindSmallestDirectoryAtLeast(needed) + if dir == nil { + log.Fatal("No suitable directories found") + } + fmt.Printf("Disk Space %d / %d. Need %d more for update.\n", (total - used), total, needed) + fmt.Println("Auto-deleting smallest directory that will permit update... Don't panic.") + fmt.Printf("Freed space by deleting %s: %d\n", dir.FullPath(), dir.Size()) +} + +const ( + TpFile = iota + TpDir +) + +type node interface { + Parent() *dir + Path() []string + Name() string + Type() int + Size() int + FullPath() []string + Print(depth int) +} + +type file struct { + parent *dir + path []string + name string + size int +} + +func NewFile(parent *dir, path []string, nm string, size int) *file { + return &file{ + parent: parent, + path: path, + name: nm, + size: size, + } +} +func (f file) Parent() *dir { return f.parent } +func (f file) Path() []string { return f.path } +func (f file) Name() string { return f.name } +func (f file) Type() int { return TpFile } +func (f file) Size() int { return f.size } +func (f file) FullPath() []string { return append(f.path, f.name) } +func (f file) Print(depth int) { + fmt.Printf("%s- %s (file, size=%d)\n", strings.Repeat(" ", depth), f.Name(), f.Size()) +} + +type dir struct { + parent *dir + path []string + name string + contents map[string]node + contentsList []string +} + +func NewDir(parent *dir, path []string, name string) *dir { + return &dir{ + parent: parent, + path: path, + name: name, + contents: make(map[string]node), + } +} +func (d dir) Parent() *dir { return d.parent } +func (d dir) Path() []string { return d.path } +func (d dir) Name() string { return d.name } +func (d dir) Type() int { return TpDir } +func (d dir) Size() int { + var size int + for i := range d.contents { + size += d.contents[i].Size() + } + return size +} +func (d dir) FullPath() []string { return append(d.path, d.name) } +func (d *dir) ChangeDir(to string) (*dir, error) { + if v, ok := d.contents[to]; !ok { + return nil, errors.New("Directory not found") + } else { + switch d := v.(type) { + case *dir: + return d, nil + default: + return nil, errors.New("Not a directory") + } + } +} +func (d *dir) AddFile(nm string, size int) { + d.contents[nm] = NewFile(d, d.FullPath(), nm, size) + d.contentsList = append(d.contentsList, nm) + sort.Strings(d.contentsList) +} +func (d *dir) AddDir(nm string) { + d.contents[nm] = NewDir(d, d.FullPath(), nm) + d.contentsList = append(d.contentsList, nm) + sort.Strings(d.contentsList) +} +func (d dir) Print(depth int) { + fmt.Printf("%s- %s (dir)\n", strings.Repeat(" ", depth), d.Name()) + for _, nm := range d.contentsList { + n, ok := d.contents[nm] + if !ok { + log.Fatalf("Error printing directory %s: %s not found.", d.FullPath(), nm) + } + n.Print(depth + 1) + } +} +func (d *dir) FreeSpace(driveSize int) int { return driveSize - d.Size() } + +func (d *dir) FindDirectoriesMaxSize(size int) []*dir { + var ret []*dir + for _, node := range d.contents { + switch child := node.(type) { + case *dir: + if child.Size() <= size { + ret = append(ret, child) + } + ret = append(ret, child.FindDirectoriesMaxSize(size)...) + } + } + return ret +} +func (d *dir) FindSmallestDirectoryAtLeast(needed int) *dir { + var ret *dir + retSize := d.Size() + for _, node := range d.contents { + switch child := node.(type) { + case *dir: + sz := child.Size() + if sz >= needed && sz < retSize { + ret = child + retSize = sz + rec := child.FindSmallestDirectoryAtLeast(needed) + if rec != nil { + ret = rec + retSize = rec.Size() + } + } + } + } + return ret +} diff --git a/2022/day07/problem b/2022/day07/problem new file mode 100644 index 0000000..cb4a255 --- /dev/null +++ b/2022/day07/problem @@ -0,0 +1,151 @@ +Advent of Code +br0xen (AoC++) 14* + +--- Day 7: No Space Left On Device --- + + You can hear birds chirping and raindrops hitting leaves as the expedition proceeds. Occasionally, you can even hear + much louder sounds in the distance; how big do the animals get out here, anyway? + + The device the Elves gave you has problems with more than just its communication system. You try to run a system update: + + $ system-update --please --pretty-please-with-sugar-on-top + Error: No space left on device + + Perhaps you can delete some files to make space for the update? + + You browse around the filesystem to assess the situation and save the resulting terminal output (your puzzle input). For + example: + + $ cd / + $ ls + dir a + 14848514 b.txt + 8504156 c.dat + dir d + $ cd a + $ ls + dir e + 29116 f + 2557 g + 62596 h.lst + $ cd e + $ ls + 584 i + $ cd .. + $ cd .. + $ cd d + $ ls + 4060174 j + 8033020 d.log + 5626152 d.ext + 7214296 k + + The filesystem consists of a tree of files (plain data) and directories (which can contain other directories or files). + The outermost directory is called /. You can navigate around the filesystem, moving into or out of directories and + listing the contents of the directory you're currently in. + + Within the terminal output, lines that begin with $ are commands you executed, very much like some modern computers: + + • cd means change directory. This changes which directory is the current directory, but the specific result depends on + the argument: + + • cd x moves in one level: it looks in the current directory for the directory named x and makes it the current + directory. + • cd .. moves out one level: it finds the directory that contains the current directory, then makes that + directory the current directory. + • cd / switches the current directory to the outermost directory, /. + + • ls means list. It prints out all of the files and directories immediately contained by the current directory: + + • 123 abc means that the current directory contains a file named abc with size 123. + • dir xyz means that the current directory contains a directory named xyz. + + Given the commands and output in the example above, you can determine that the filesystem looks visually like this: + + - / (dir) + - a (dir) + - e (dir) + - i (file, size=584) + - f (file, size=29116) + - g (file, size=2557) + - h.lst (file, size=62596) + - b.txt (file, size=14848514) + - c.dat (file, size=8504156) + - d (dir) + - j (file, size=4060174) + - d.log (file, size=8033020) + - d.ext (file, size=5626152) + - k (file, size=7214296) + + Here, there are four directories: / (the outermost directory), a and d (which are in /), and e (which is in a). These + directories also contain files of various sizes. + + Since the disk is full, your first step should probably be to find directories that are good candidates for deletion. To + do this, you need to determine the total size of each directory. The total size of a directory is the sum of the sizes + of the files it contains, directly or indirectly. (Directories themselves do not count as having any intrinsic size.) + + The total sizes of the directories above can be found as follows: + + • The total size of directory e is 584 because it contains a single file i of size 584 and no other directories. + • The directory a has total size 94853 because it contains files f (size 29116), g (size 2557), and h.lst (size + 62596), plus file i indirectly (a contains e which contains i). + • Directory d has total size 24933642. + • As the outermost directory, / contains every file. Its total size is 48381165, the sum of the size of every file. + + To begin, find all of the directories with a total size of at most 100000, then calculate the sum of their total sizes. + In the example above, these directories are a and e; the sum of their total sizes is 95437 (94853 + 584). (As in this + example, this process can count files more than once!) + + Find all of the directories with a total size of at most 100000. What is the sum of the total sizes of those + directories? + + Your puzzle answer was 1642503. + +--- Part Two --- + + Now, you're ready to choose a directory to delete. + + The total disk space available to the filesystem is 70000000. To run the update, you need unused space of at least + 30000000. You need to find a directory you can delete that will free up enough space to run the update. + + In the example above, the total size of the outermost directory (and thus the total amount of used space) is 48381165; + this means that the size of the unused space must currently be 21618835, which isn't quite the 30000000 required by the + update. Therefore, the update still requires a directory with total size of at least 8381165 to be deleted before it can + run. + + To achieve this, you have the following options: + + • Delete directory e, which would increase unused space by 584. + • Delete directory a, which would increase unused space by 94853. + • Delete directory d, which would increase unused space by 24933642. + • Delete directory /, which would increase unused space by 48381165. + + Directories e and a are both too small; deleting them would not free up enough space. However, directories d and / are + both big enough! Between these, choose the smallest: d, increasing unused space by 24933642. + + Find the smallest directory that, if deleted, would free up enough space on the filesystem to run the update. What is + the total size of that directory? + + Your puzzle answer was 6999588. + + Both parts of this puzzle are complete! They provide two gold stars: ** + +References + + Visible links + . https://adventofcode.com/ + . https://adventofcode.com/2022/about + . https://adventofcode.com/2022/events + . https://adventofcode.com/2022/settings + . https://adventofcode.com/2022/auth/logout + . Advent of Code Supporter + https://adventofcode.com/2022/support + . https://adventofcode.com/2022 + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/support + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022/leaderboard + . https://adventofcode.com/2022/stats + . https://adventofcode.com/2022/sponsors + . https://adventofcode.com/2022 + . https://adventofcode.com/2022/day/7/input diff --git a/2022/day07/testinput b/2022/day07/testinput new file mode 100644 index 0000000..09a921e --- /dev/null +++ b/2022/day07/testinput @@ -0,0 +1,23 @@ +$ cd / +$ ls +dir a +14848514 b.txt +8504156 c.dat +dir d +$ cd a +$ ls +dir e +29116 f +2557 g +62596 h.lst +$ cd e +$ ls +584 i +$ cd .. +$ cd .. +$ cd d +$ ls +4060174 j +8033020 d.log +5626152 d.ext +7214296 k