From 0340f23360ec59daa0c423407a266499c26092e8 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Thu, 1 Dec 2022 09:46:04 -0500 Subject: [PATCH] Day 1 solution --- flake.lock | 8 +- problems/data/day1a.txt | 2265 ++++++++++++++++++++++++++++++++++++++- problems/src/day1.rs | 111 +- problems/src/main.rs | 7 +- 4 files changed, 2355 insertions(+), 36 deletions(-) diff --git a/flake.lock b/flake.lock index f6af3c8..4fd5a02 100644 --- a/flake.lock +++ b/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1669418739, - "narHash": "sha256-T86oFvcUIRwHWBWUt7WjaP4BP/3lDGbv5AppQSI1FkI=", + "lastModified": 1669764884, + "narHash": "sha256-1qWR/5+WtqxSedrFbUbM3zPMO7Ec2CGWaxtK4z4DdvY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "695b3515251873e0a7e2021add4bba643c56cde3", + "rev": "0244e143dc943bcf661fdaf581f01eb0f5000fcf", "type": "github" }, "original": { @@ -52,7 +52,7 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "narHash": "sha256-xMOq9ifVo63/aBA1VIHQQ4riuRJGyup7F1orjekAwpk=", + "narHash": "sha256-/ar+cbAKAxd2Ng9b7EhrIMz9CP353RbmLecvyOidyUM=", "type": "tarball", "url": "https://github.com/oxalica/rust-overlay/archive/master.tar.gz" }, diff --git a/problems/data/day1a.txt b/problems/data/day1a.txt index 167e291..ff31e85 100644 --- a/problems/data/day1a.txt +++ b/problems/data/day1a.txt @@ -1,10 +1,2255 @@ -199 -200 -208 -210 -200 -207 -240 -269 -260 -263 +5324 +5176 +2197 +2701 +6185 +3901 +5392 +2065 +6467 +6085 +5062 +1841 +1197 +1318 + +4901 +3443 +1403 +5570 +4336 +5672 +2532 +5627 +6038 +1099 +4305 +2317 +1382 +3226 +4427 + +2612 +15638 + +4118 +4687 +2243 +3532 +2089 +3937 +1146 +5069 +5728 +2962 +3099 +5882 +5448 +6064 + +2642 +7996 +5334 +10384 +1106 +2742 + +3064 +3506 +2566 +5241 +2705 +5973 +5482 +1689 +1797 +6098 +3964 +2592 +2700 +5569 +4305 + +1307 +2204 +3618 +4795 +7853 +6103 +5248 +5989 +1451 +5524 +2572 + +7207 +5428 +8504 +3861 +1025 +3600 +2850 +3363 +4283 +3695 + +21536 +34998 + +7332 +7390 +4755 +1006 +6221 +2081 +4894 +6376 +3893 +2797 +4448 +2961 + +6544 +13080 +9331 +4452 +11569 + +8130 +7731 +4130 +2905 +5849 +3086 +1386 +8160 +4405 +4456 + +1673 +5591 +6628 +3577 +2097 +2540 +4884 +3704 +4340 +5609 +5671 +2386 + +1454 +2458 +2099 +2123 +3529 +1500 +2574 +1414 +1570 +5540 +4674 +2596 +5112 +4553 +3538 + +3089 +20620 +8662 + +7318 +6430 +3187 +4619 +7214 +7950 +5435 +1408 +4418 +6811 +6619 + +14465 +13716 +4698 +18846 + +3262 +3532 +3052 +8765 +7883 +4037 +3531 +1275 +1699 + +7331 +1567 +1820 +2593 +3537 +2140 +6760 +5755 +4144 +2073 +4602 +4128 + +6104 +8972 +19892 + +17252 +21573 +9351 + +67201 + +4294 +7766 + +19774 + +11565 +11046 +2842 +8393 + +7017 +9675 +6745 +13481 +13556 +4249 + +2107 +5225 +4963 +1119 +1573 +7933 +5257 +6803 +3414 +6156 +2593 + +3598 +2420 +2557 +2910 +6750 +2253 +5729 +6724 +6355 +1731 +4128 +4827 +6062 + +5367 +1916 +4804 +5871 +1210 +2265 +3945 +6557 +5711 +6611 +2373 + +10064 + +9038 +27653 + +2574 +6005 +11713 +2748 +10206 + +3404 +3885 +6447 +6270 +3738 +6098 +4455 +4285 +3386 +2148 +6238 +2457 +3971 +5009 + +1964 +7018 +3023 +13938 +2509 +9362 + +5570 +5928 +7596 +7327 +3867 +2127 +2473 +6631 +2514 +5685 + +17379 +5566 +7377 +11680 + +11618 +9050 +4052 +6359 +9340 +10670 +2206 + +3801 +7994 +1783 +8331 +8378 +8567 +6575 +6466 +6327 +7675 + +1727 +4854 +13316 +2277 +1002 + +11508 + +1466 +2783 +1248 +6891 +5062 +4676 +5392 + +2309 +4345 +4061 +2291 +6176 +2020 +1352 +4323 +5949 +3386 +1453 +6271 +2406 +3702 + +9874 +9051 +11016 +5825 +8846 +1554 +7739 + +23528 + +1043 +8194 +3368 +9066 +9089 +8174 + +10746 +9730 +11740 +10055 +7193 +13904 + +6215 +1885 +5229 +6669 +6959 +4974 +2120 +1298 +1430 +6121 + +14723 +32715 + +5783 +1098 +5175 +4285 +4773 +3161 +5007 +2226 +5436 +6077 +4460 +4532 +2250 +4365 +2067 + +6400 +2528 +2425 +3648 +2881 +3142 +6677 +5898 +2358 +6551 +2718 +1068 + +26003 +35903 + +5639 +2631 +5958 +5768 +1598 +2399 +2034 +5312 +5296 +2416 +4102 +5487 +4703 + +2570 +8366 +5181 +2445 +5162 +7602 +7173 +7287 +5544 + +7471 +1860 +6054 +4806 +8003 +7528 +1229 +8685 +7621 +8658 + +2772 +3368 +2152 +5375 +2609 +8107 +6980 +4483 +5277 +2887 + +5247 +2757 +5563 +2715 +1667 +1226 +5100 +5406 +3361 +1873 +1254 +1455 +5119 +6059 +5763 + +36308 + +10652 +2469 +5899 +3109 +9516 +1320 +5497 +8118 + +1633 +36728 + +15311 +15800 +2345 + +8798 +7581 +2277 +8154 +10875 +7322 +6145 + +9637 +3697 +4013 +3531 +10327 +7563 +9885 +2997 + +4043 +2569 +6039 +1967 +7443 +3359 +2323 +6144 +6260 +2931 +1316 + +4511 +10608 +16203 +5885 +5809 + +4708 +9406 +8620 +7918 +3530 +6432 +1294 +1129 + +5619 +2899 +1447 +4966 +2602 +4203 +1151 +4142 +5444 +1628 +2951 +3237 +2622 +1772 +4763 + +2587 +2284 +2831 +8008 +2176 +11829 +2512 + +13915 +13264 +10711 +5834 +8227 + +9012 +13250 +9137 +3782 +8746 +2746 + +3215 +2767 +1979 +3831 +5022 +1171 +1315 +4688 +2993 +1727 +1632 +2576 +1148 +3347 +5848 + +4528 +1066 +24591 + +1107 +5616 +6397 +3615 +1922 +7825 +4068 +2282 +4969 +4928 +1956 + +7563 +8015 +1599 +7393 +8540 +5662 +3296 +7456 +7456 +6788 + +8739 +3875 + +5167 +1477 +5247 +8143 +1505 +10220 +7960 +4732 + +16912 + +4976 +7525 +1736 +1008 +4977 +5674 +4444 +6232 +6049 +3639 +4522 + +22528 +23111 + +13556 +17076 +3627 +17255 + +1016 +1029 +3348 +5944 +5495 +2094 +4820 +2525 +4933 +5956 +2824 +3723 +5823 +6486 + +19290 +4670 +15993 +1076 + +9721 +7648 +17076 +7349 + +9628 +8035 +7244 +8595 + +29847 +31827 + +13167 +5522 +5306 +8929 +11649 +10464 + +4502 +3131 +1443 +5337 +9086 +4409 +6998 +4804 + +5638 +4221 +1322 +7392 +3318 +4711 +7797 +7945 + +5089 +2885 +1516 +6707 +4162 +2750 +3852 +4179 +4237 +1514 +3948 + +5584 +2739 +2969 +1821 +6459 +2524 +1315 +2437 +5509 +1931 +2268 +2997 + +5234 +2321 +4232 +5685 +3984 +2906 +1432 +4343 +3281 +2528 +2488 +1718 +5990 +3522 +4354 + +26195 +6781 + +5142 +4073 +5532 +7427 +7419 +1747 +3380 +6364 +6631 +3779 +4765 +5835 + +3705 +1536 +6790 +2033 +1455 +6505 +4919 +3024 +2474 +5873 +3471 +3505 +1316 + +6749 +4727 +3858 +5056 + +22223 + +17648 +4274 +12725 + +2280 +9924 + +15172 +7628 +7641 +7194 +1968 + +5982 +5614 +2452 +5362 +8434 +3174 +2176 +2698 +2412 +2189 + +13340 +12621 +14111 +14941 +13566 + +1361 +5862 +4128 +6746 +4467 +1838 +2139 +2664 +5443 +6834 +4677 +1098 +6784 + +10515 +2760 +10711 +5115 +12137 +2781 + +5049 +6241 +2530 +5856 +2433 +4728 +5363 +6403 +3327 +4275 +4158 +3801 +2371 +6359 + +29965 +8489 + +56825 + +11312 +9212 +1929 +14504 + +6465 +9629 +10359 +5838 +9425 +3058 +9753 +5888 + +5406 +13482 +3204 +2628 +9957 +10256 + +6179 +4133 +5327 +2896 +5640 +6104 +2780 +7809 +3987 +1638 +2541 + +33667 +14175 + +6110 +11612 +2695 +9999 + +5704 +6108 +2967 +1017 +1635 +3585 +6748 +1582 +6924 +1444 +3855 +1401 +2205 + +6732 +1197 +6953 +2207 +5612 +4231 +7347 +5711 +7897 + +13701 +10913 +16370 +19244 + +2674 +7112 +6486 +7851 +4414 +5481 +6726 +6598 +2871 +6893 +1811 + +1943 +3602 +4825 +11299 +14128 + +3270 +5562 +4320 +1632 +2765 +5645 +4944 +5241 +5292 +8473 + +2052 +2661 +4128 +5271 +1213 +4609 +3655 +6794 +2479 +5906 +6116 +4915 + +13118 +3888 +4049 +14650 +8187 + +7607 +7667 +4020 +2573 +3144 +10783 +3750 + +3572 +1577 +5913 +1191 +2013 +5357 +1334 +4691 +4955 +3044 +3587 +4261 +1879 +5174 + +21378 + +3856 +7070 +6705 +8507 +9457 +9742 +2451 + +2451 +6025 +10161 +10060 +11159 +4572 + +6103 +14326 +18133 +15332 + +5227 +2699 +2870 +1360 +3827 +2691 +5508 +1526 +2144 +4458 +4799 +3028 +5663 +3352 +5890 + +6639 +12924 +5358 +9307 +1789 + +4548 +8584 +2044 +1171 +8894 +7690 +2456 +2225 +6462 + +17817 +18601 +22573 + +5232 +7406 +2372 +9508 +6245 +5918 +3184 +7341 +4055 + +5583 +6410 +2211 +1752 +5614 +6256 +3575 +5114 +5707 +5439 +6576 +6152 +4253 + +1588 +4856 +1078 +9837 +10431 +3509 +2755 +2086 + +4108 +1603 +5413 +3281 +2084 +4070 +5170 +6002 +2991 +5885 +2073 +5249 +5078 +2229 + +2486 +1600 +2956 +5086 +3521 +2302 +5989 +5187 +2070 +3637 +4734 +2812 +2929 +1017 +1030 + +2302 +3395 +8743 +10214 +9177 +11084 +11280 + +3789 +5462 +5929 +2823 +5276 +5236 +1262 +1046 +6508 +5734 +5138 +5299 +3707 + +18103 +23600 +9666 + +9572 +5689 +8247 +6325 +5766 +6474 +4341 +2272 + +11951 +3817 +9665 +9371 +11456 + +18948 + +5760 +4181 +5350 +4406 +3333 +1192 +3369 +1739 +1417 +2549 +6452 +5864 +3340 +2264 + +1353 +4974 +1110 +3219 +3022 +1763 +2457 +1242 +1015 +5118 +2844 +1289 +5798 +2370 +1328 + +2420 +3955 +5165 +6471 +1506 +7366 +2845 +7015 +3494 +3631 +3366 + +5595 +1173 +5367 +2745 +5405 +3846 +4318 +4974 +1798 +5729 +2531 +3837 +4751 +1773 + +2917 +16933 +3801 +1609 + +24309 +17327 +3185 + +3608 +5934 +10329 +13659 +8898 + +13593 + +34109 +14389 + +5060 +2976 +1252 +3496 +2184 +2118 +2705 +4575 +1960 +1399 +4248 +1096 +5987 + +22148 + +6872 +3921 +6311 +6941 +5690 +5889 +5491 +2539 +6307 +6881 +6341 +4722 +6489 + +1294 +4268 +5230 +4534 +4271 +3299 +5569 +2424 +1169 +3393 +2191 +4614 +3407 +6061 + +5949 +3315 +3465 +1766 +6758 +3424 +6719 +3146 +5540 +5761 +3082 +5684 + +2622 +5651 +5396 +6061 +1771 +1924 +5686 +5660 +1867 +5316 +5457 +6073 +2739 +5972 +5036 + +6479 +4340 +4935 +1261 +3876 +1382 +3676 +7756 +6854 +1713 +2231 + +4951 +9899 +5241 +6767 +1821 +7499 +10630 +2795 + +6056 +4547 +1637 +9041 +8543 +2658 +4432 +8485 +2344 + +13655 +9543 +10307 +13701 +7088 +3037 + +11024 +13887 +13483 +9086 +3240 + +25938 +5207 +12019 + +7149 +1287 +6648 +2064 +1192 +4329 +3562 +6906 +4932 +1275 +2770 +5506 + +3937 +2237 +3689 +1612 +5617 +5771 +1582 +4790 +2307 +5041 +2624 +2838 +2795 +2206 +1635 + +17589 +8653 +17117 + +4989 +4956 +5419 +6835 +2196 +7712 +2424 +4662 +1602 +3939 +1272 + +16436 +12889 +6171 +9114 +2522 + +7624 +7560 +2198 +9091 +4732 +4600 +5329 +6004 +1019 + +5856 +1678 +1413 +1159 +2087 +1688 +2705 +2914 +4541 +6192 +3899 + +5894 +7004 +6434 +7397 +1628 +10169 +10771 +2815 + +5066 +4856 +1640 +1711 +11255 + +4073 +1430 +3137 +4448 +6758 +6601 +5361 +1551 +1172 +6521 +1984 +6439 +6856 + +9142 +5332 +6587 +6221 +7395 +3916 +3028 +6746 + +1888 +4873 +4385 +1612 +2542 +5366 +4580 +4885 +5067 +2973 +3746 +2312 + +9887 +2252 +9326 +9370 +4463 +2315 +3341 +8055 + +2044 +2280 +7734 +3207 +7745 +7176 +4730 +2999 +1333 +5779 +7820 + +2176 +5977 +6915 +5025 +2534 +5837 +5051 +2789 +2710 +3725 +4542 +5014 +6533 + +5040 +7527 +7004 +6962 +2013 +7318 +1072 +1885 +5706 +2064 +2112 + +32698 +5926 + +7743 +4843 +6126 +6327 +4515 +5568 +7777 +5099 +5645 +5375 +4282 + +10281 +7177 +8041 +9502 +4617 +6776 +5955 +9100 + +13793 +5079 +11978 +9184 +5004 +6506 + +11597 +22056 +11123 + +1966 +2459 +6579 +4048 +4820 +3866 +7306 +3019 +4028 +3280 +1280 +6118 + +2629 +6241 +5263 +4006 +7169 +6295 +1916 +7067 +5163 +7417 +7183 + +5296 +1587 +6900 +7476 +2815 +6000 +5377 +5690 +6823 +6629 + +10444 +7392 +8982 +6994 +9345 +1164 + +4648 +18356 +5229 +18479 + +37019 + +1595 +14516 +11072 +12073 +10524 + +7074 +4499 +3528 +6918 +7634 +7018 +4064 +2346 +6254 +4557 +5201 + +1304 +4826 +7327 +7594 +5661 +6148 +8777 +4703 +3436 +4898 + +69863 + +8498 +10599 +9617 +8728 +9386 +1506 +2857 + +7081 +3260 +16812 + +1978 +5986 +5234 +6330 +5033 +3496 +6263 +7934 +8236 +3702 + +1453 +2526 +5851 +2084 +3092 +6085 +6055 +3543 +2803 +1552 +1021 +5182 +4564 +3912 +3854 + +1003 +6113 +5847 +1479 +3534 +1497 +2047 +6062 +3713 +3888 +1847 +1798 +3207 +2560 +3212 + +4904 +7090 +2494 +8864 +1494 +3313 +1009 +7531 +4235 + +3024 +7888 +3711 +7637 +4804 +10269 +4739 +3124 + +10068 +9428 +5562 +2721 + +6320 +6421 +2922 +3893 +3632 +5560 +3579 +5181 +1927 +3860 +1432 +4818 +2868 +2184 + +11927 +4764 +7755 +10159 +6954 +9559 + +8985 +5396 + +5821 +15081 +12926 +16298 +11228 + +2555 +4710 +5259 +5744 +2489 +2068 +1502 +4496 +3785 +3377 +2321 +3902 + +10993 +10833 +24463 + +4011 +1089 +2087 +5185 +3488 +3736 +4926 +4891 +3448 +3271 +4634 +3751 +5303 +1994 + +5919 +3347 +4708 +1965 +5606 +6273 +2042 +1773 +3026 +4585 +2239 +2520 +4567 +4964 + +11355 +11798 +7831 +7480 +8790 +6294 +11922 + +3780 +4205 +2006 +4419 +4193 +2482 +4835 +4758 +3600 +1117 +3185 +1808 +1233 +4082 +3326 + +43241 + +5617 +1489 +5975 +5619 +2877 +1722 +4756 +5164 +3192 +2945 +5610 +6021 +4883 +2218 + +1579 +3888 +8895 +3815 +11782 +7598 + +2480 +2152 +7361 +6604 +3773 +1116 +4720 +6142 +6743 +7900 +1503 + +8257 +6224 +5073 +5153 +6286 +5930 +2198 +7322 +1244 +3028 + +9040 +9861 +11717 + +1692 +2885 +9293 +6439 +6822 +4663 + +11327 +6426 +4039 +9769 +3730 +6972 +6462 + +6202 +2857 +3687 +4333 +3206 +5999 +3844 +4236 +3496 +7349 +1637 +5892 + +21290 +13265 +16574 + +1501 +8323 +2174 +7603 +1417 +5507 +3152 +8574 +6952 +6893 + +2057 +5770 +6945 +5910 +2066 +2373 +6613 +6703 +5795 +7033 +6063 +3443 + +10064 +12696 +1625 +1604 +8552 + +4518 +3559 +4612 +4990 +6122 +1829 +8607 +2051 +6314 +2596 + +1898 +8330 +6823 +14127 +4122 + +2494 +6727 +4587 +2321 +4617 +4813 +7347 +3794 +1446 +5291 +4913 + +15290 +9852 +5973 +7334 + +5995 +4539 +8371 +9076 +12656 +12625 + +2198 +1139 +4259 +3010 +9045 +2929 +8392 +4307 +5738 + +12958 +5954 + +2276 +6600 +5912 +1305 +6350 +5827 +2640 +6856 +7562 +7882 +3944 + +7186 +4975 +9015 +12599 +13902 + +55492 + +4832 +5290 +2044 +1011 +4110 +1236 +4706 +5218 +1300 +3238 +1836 +1309 +4742 +3964 +4682 + +5611 +3648 +8179 +9855 +2938 +8541 +9237 + +6779 +7885 +7768 +7979 +1604 +2719 +3879 +2771 +1197 + +2775 +12978 +7208 + +19188 +16982 +8339 + +12742 +18586 +18256 + +15946 +28794 + +5010 +1439 +1176 +5112 +6225 +11059 +1380 + +2636 +5109 +7016 +4966 +7277 +1646 +1209 +4458 +4147 +3169 + +18833 +18515 +8638 +6254 + +7158 +2439 +12116 +2417 +6262 +9579 +6050 + +7881 +8103 +6525 +5610 +4287 +7642 +2084 +8453 +1724 + +3535 +10683 +10350 +11645 +11293 +7447 +6324 + +17973 +11656 +19267 +18227 + +5568 +3346 +5735 +5136 +5528 +5605 +3106 +4635 +2530 +3111 +2916 +1510 +2617 + +6132 +1462 +2779 +4977 +1771 +8308 +2896 +6441 +3027 +1452 + +50057 + +1733 +4620 +5879 +3456 +3043 +1039 +5811 +3572 +1371 +4420 +5788 +1722 +1173 +5371 + +4890 +4902 +5587 +5794 +4689 +6264 +3451 +6440 +5713 +4760 +4073 +6571 +5257 + +2882 +1784 +4373 +4672 +3418 +5014 +3662 +1249 +5828 +5153 +5729 +3709 +5709 +3007 + +13324 +9643 +14954 +14195 + +4739 +5997 +2183 +3111 +6721 +8025 +1373 +4982 +2199 +6187 + +6561 +6690 +9276 +7602 +7353 +7961 +1247 +6694 +6641 + +6626 +5971 +6702 +1726 +3909 +2262 +6701 +4754 +4256 +5897 +3946 +1457 +4469 diff --git a/problems/src/day1.rs b/problems/src/day1.rs index 5afd767..1ab6a2b 100644 --- a/problems/src/day1.rs +++ b/problems/src/day1.rs @@ -1,25 +1,100 @@ const PART1: &str = include_str!("../data/day1a.txt"); pub fn part1() -> String { - let lines = PART1.lines(); - - let depths: Vec = lines.map(|l| l.parse::().unwrap()).collect(); - - let depths_a = depths.iter(); - let depths_b = depths.iter().skip(1); - let depth_cmp = depths_a.zip(depths_b); - - let increases = depth_cmp.fold(0, |cur, (a, b)| { - println!("{} < {}? {}", a, b, a < b); - if a < b { - cur + 1 - } else { - cur - } - }); - format!("{}", increases) + format!("{}", max_calories(sum_calories(input_data(PART1))).1) } pub fn part2() -> String { - "no response".to_owned() + format!("{}", max_three_calories(sum_calories(input_data(PART1)))) +} + +fn input_data(data: &str) -> Vec> { + data.lines() + .collect::>() + .split(|l| *l == "") + .map(|v| { + v.into_iter() + .map(|element| element.parse::().unwrap()) + .collect::>() + }) + .collect::>>() +} + +fn sum_calories(food_lists: Vec>) -> Vec<(usize, u32)> { + food_lists + .into_iter() + .map(|list| list.into_iter().fold(0, |cur, val| cur + val)) + .enumerate() + .collect::>() +} + +fn elf_with_most_calories(batch_calories: Vec<(usize, u32)>) -> usize { + let (idx, _) = max_calories(batch_calories); + // Elves are 1-indexed + return idx + 1; +} + +fn max_calories(mut batch_calories: Vec<(usize, u32)>) -> (usize, u32) { + batch_calories.sort_by(|(_, val1), (_, val2)| val1.cmp(val2)); + batch_calories.reverse(); + batch_calories[0] +} + +fn max_three_calories(mut batch_calories: Vec<(usize, u32)>) -> u32 { + batch_calories.sort_by(|(_, val1), (_, val2)| val1.cmp(val2)); + batch_calories.reverse(); + batch_calories + .into_iter() + .take(3) + .fold(0, |cur, (_, val)| cur + val) +} + +#[cfg(test)] +mod test { + use super::*; + + const TEST_DATA1: &str = "1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000"; + #[test] + fn find_most_elf() { + let input = input_data(TEST_DATA1); + let food_batches = sum_calories(input); + assert_eq!( + food_batches, + vec![6000, 4000, 11000, 24000, 10000] + .into_iter() + .enumerate() + .collect::>() + ); + + assert_eq!(elf_with_most_calories(food_batches.clone()), 4); + assert_eq!(max_calories(food_batches), (3, 24000)); + } + + #[test] + fn batch_with_one_element() { + let input = input_data("50057"); + let food_batches = sum_calories(input); + assert_eq!(food_batches, vec![(0, 50057)]); + } + + #[test] + fn find_max_three() { + assert_eq!( + max_three_calories(sum_calories(input_data(TEST_DATA1))), + 45000 + ); + } } diff --git a/problems/src/main.rs b/problems/src/main.rs index 1ca43ac..469b76f 100644 --- a/problems/src/main.rs +++ b/problems/src/main.rs @@ -2,13 +2,12 @@ mod day1; fn main() { let day = std::env::args().skip(1).next(); - println!("day: {:?}", day); let result = match day.as_ref().map(|v| v.as_ref()) { - Some("day1a") => day1::part1(), - Some("day1b") => day1::part2(), + Some("1a") => day1::part1(), + Some("1b") => day1::part2(), _ => panic!("unrecognized day"), }; - println!("{:?} Result: {}", day, result); + println!("[{}] {}", day.unwrap(), result); }