From 7e00d10b04eccd7aa56080f7d241ba8f13c644e2 Mon Sep 17 00:00:00 2001 From: deckelmouck Date: Wed, 29 Nov 2023 20:56:45 +0100 Subject: [PATCH] solving 2022 day 01 part 1 and 2 --- 2022/Day01/input | 2262 ++++++++++++++++++++++++++++++++++++++++ 2022/Day01/solution.cs | 41 + Helper.cs | 0 Program.cs | 24 +- 4 files changed, 2323 insertions(+), 4 deletions(-) create mode 100644 2022/Day01/input create mode 100644 Helper.cs diff --git a/2022/Day01/input b/2022/Day01/input new file mode 100644 index 0000000..89622fa --- /dev/null +++ b/2022/Day01/input @@ -0,0 +1,2262 @@ +5916 +7281 +1715 +3853 +10283 +1455 +7807 +6117 + +33711 +6672 + +3988 +6947 +1674 +1928 +6128 +6361 +3817 +6141 +3301 +5473 +2609 +4262 +6105 + +2725 +7430 +7415 +6997 +4542 +2703 +7148 +2710 +5660 +7372 +2539 +7162 + +5377 +4274 +2793 +2911 +2113 +1077 +4115 +5871 +1079 +4336 +4894 +2088 +5408 +5535 +1982 + +3270 +1347 +4884 +2986 +6067 +5567 +5093 +4421 +2772 +4935 +6153 +1235 +3824 +6460 + +4131 +5183 +5329 +8021 +6096 +6053 +4352 +2016 +5055 +3031 +3379 + +1846 +3964 +16169 +10061 +16400 + +1519 +5378 +6590 +6782 +7072 +4011 +6581 +5871 +6112 +6836 + +3894 +5621 +6342 +6746 +1955 +3348 +5651 +1468 +7232 +3240 +3435 +4566 + +8079 +4170 +5034 + +7439 +1078 +4537 +7020 +2013 +2796 +1627 +1171 +3472 +2611 +3701 +1570 + +2874 +13468 +4739 +16126 +11847 + +37266 +25445 + +9722 +12162 +9507 +5369 + +10547 +5064 +10328 +7331 +2829 +7218 +2094 +8963 + +9828 +4878 +1582 +3494 +8656 + +4271 +8332 +1579 +6029 +13927 +5572 + +6709 +5200 +2009 +7145 +3739 +4750 +7173 +6257 +2520 +4878 +3730 +5773 + +3367 +11772 +4282 +9184 +6947 +2471 + +1112 +1186 +2178 +5993 +2098 +5243 +5223 +1709 +2290 +6327 + +8571 +4827 +4630 +2496 +6101 +10967 +9712 + +5730 +2663 +6857 +3517 +7938 +5069 +1825 +6498 +2716 +6798 +6394 + +2154 +5746 +3630 +4056 +6257 +6249 +4872 +1769 +8320 +1294 + +1469 +6784 +6869 +3459 +6487 +1003 +7296 +8054 +3027 +8338 + +1156 +5197 +6307 +3935 +4874 +2021 +2001 +2077 +3755 +4507 +4116 +1742 +1341 + +2602 +6117 +1059 +4689 +4430 +1216 +4126 +4810 +6270 +2819 +6013 +1589 +4496 +5670 + +5739 +8341 +9572 +6860 +5805 +6627 +3291 +5664 +1907 + +5359 +26291 + +2503 +8306 +6709 +4770 +7460 +5028 +6586 +1286 +4120 +4381 + +1049 +17368 + +5170 +1955 +6256 +2513 +2666 +2571 +1274 +4515 +2359 +5327 +6325 +1141 +5883 + +9948 +18400 +10491 +16743 + +1531 +2231 +3614 +6706 +3516 +5629 +1745 +2780 +2899 +2916 +3928 +4085 + +10012 +12228 +15603 +4551 +3922 + +12264 +13387 +6562 +6050 +12784 +11921 + +34920 +20549 + +4990 +5935 +4252 +4079 +1354 +9274 +3232 +1527 +5978 + +65379 + +1216 +5983 +12805 +6875 +2671 +2381 + +4320 +5687 +6760 +2023 +4263 +1892 +2926 + +3192 +10623 +10169 +12098 +1307 +11324 +2156 + +3749 +2564 +3627 +4701 +5104 +1052 +5035 +3742 +5456 +2150 +2042 +4326 +3053 +5006 +5142 + +5984 + +13641 +30009 + +13225 +5744 +8472 +8526 +5427 + +4593 +6409 +7212 +6755 + +4285 +8123 +6604 +1812 +4145 +9072 +7456 +9813 + +8572 +3737 +9989 +17372 + +3522 +11158 +11713 +1160 +10425 +9709 +7731 + +6503 +3369 +3225 +3899 + +31458 +29242 + +27980 +17901 + +3361 +2869 +1654 +5350 +6317 +8273 +6526 +2723 + +5186 +31304 + +12989 +11754 +11012 +5487 +3127 + +1627 +3229 +2818 +6410 +10184 +6946 +3349 +2976 + +4656 +4290 +3066 +5230 +3503 +1444 +3154 +3748 +2392 +2435 +2211 +2093 +3835 +2402 +1698 + +1311 +6276 + +3748 +4996 +6338 +8906 +11219 +1797 +6467 + +4241 +3011 +6574 +3945 +5947 +6398 +1505 +4799 +5325 +5559 +1735 + +13793 +9236 +9335 + +1031 +7087 +1933 +14085 +12694 + +2019 +2371 + +6900 +6067 +5355 +7415 +3735 +3616 +5010 +4661 +7376 +3971 +2233 +6296 + +7738 +2032 +2170 +6164 +6861 +2420 +5351 +2794 +9647 + +5785 +1391 +2213 +12440 + +2136 +1308 +3209 +3353 +3791 +5916 +5124 +1003 +2489 +5370 +3041 +4007 +2782 +2946 +5378 + +5848 +8012 +5443 +3056 +2550 +8199 +9613 +6809 +2623 + +16460 +1618 + +12239 + +3005 +1728 +7292 +7379 +3241 +5232 +8567 +5880 +4743 +8582 + +9983 +5730 +2346 +7669 +3723 +3102 +10038 +3634 + +5996 +7330 +1061 +5321 +3113 +3533 +6219 +4449 +1353 +5978 +1035 + +2951 +2249 +6361 +1322 +3363 +4667 +4494 +6531 +1530 +2968 +2552 +2249 +5052 + +4376 +13988 + +5472 +3797 +8451 +5091 +5804 +9664 +9061 +1726 +7215 + +2922 +4700 +6062 +5747 +4578 +2098 +1192 +1245 +4752 +1098 +1591 +4644 +5028 + +25366 + +5026 +1139 +6338 +1321 +5559 +3270 +6123 +2535 +1758 +1290 +4424 +3760 +3754 +5044 + +5414 +3035 +5760 +3894 +6727 +2297 +3800 +3285 +3127 +4110 +5435 +1321 + +1363 +5566 +3084 +6064 +1968 +2954 +5078 +5649 +5761 +1265 +5368 +2584 +1814 +4855 +4670 + +4580 +3174 +1343 +4299 +2930 +2209 +4883 +4404 +2899 +4431 +2433 +3444 +2183 +3816 + +2301 +3278 +6603 +5907 +6658 +3429 +3206 +5091 +4527 +3467 +4731 +2694 + +14883 +3132 +16229 +13353 + +4339 +4088 +4244 +1947 +2691 +6081 +1013 +3078 +1197 + +4565 +5429 +19061 +7019 + +5028 +1657 +5177 +1768 +3641 +3897 +3675 +1885 +1966 +1724 +6106 +5721 +5394 +1562 +3637 + +5590 +5469 +4382 +5375 +1656 +3496 +1553 +4737 +5521 +2951 +5633 +6099 +2365 + +3451 +6892 +4327 +6207 +6468 +1638 +6676 +3366 +6793 + +7999 +3815 +2828 +7726 +4747 +6494 +3227 +5024 +7550 + +10475 +24156 +1946 + +61232 + +3562 +11518 +5489 +13618 +8886 +4331 + +5068 +6620 +1899 +1742 +4183 +4792 +3300 +1636 +3644 +1716 +2247 + +21547 +25323 +17987 + +10463 +11220 +7134 +10719 +1274 +11774 + +22985 +19754 + +16499 +24689 + +2529 +4751 +2572 +4097 +6163 +5281 +3617 +3757 +3927 +3603 +3093 +6143 +4730 +3650 + +6393 +1523 +5956 +6591 +2063 +6414 +6834 +6649 +3808 +1286 +4953 +5087 +2796 + +3296 +2685 +5141 +3415 +7132 +4397 +4098 +6860 +5815 +4552 +2464 + +15557 + +1863 +1041 +4563 +1798 +3402 +1270 +3457 +1379 +5354 +2330 +6010 +3812 +2823 +6076 +4226 + +2619 +3202 +3298 +5199 +5356 +2239 +1567 +2088 +3106 +1639 +7116 +6917 + +1569 +7017 +4686 +8636 +8174 +1685 +5343 +4403 +1187 +3285 + +2886 +5763 +1469 +11516 +10773 +2282 +11137 + +10923 +8429 +11772 +8319 +4256 +6490 +2616 + +3491 +28517 + +15778 +16609 +25152 + +4645 +5384 +6744 +4612 +4405 +5450 +3678 +3894 +2232 +7232 +2377 +7056 + +4331 +2122 +4624 +1423 +6583 +5137 +1426 +1919 +2101 +4315 +4855 +6865 +1114 + +7694 +8630 +6754 +5894 +7170 +8178 +8646 +6369 +6162 +5627 + +8027 +1885 +6581 +2173 +3920 +7931 +1907 +6362 +6774 +5027 + +3841 +8648 +5530 +2754 +13794 +8974 + +1363 +5452 +6499 +5721 +2430 +2766 +6536 +1606 +5189 +1008 +6126 +2875 +5931 + +7517 +8727 +3495 +7647 +10130 +8585 +1435 + +3909 +6342 +5378 +11006 +6483 +6426 +4300 + +7358 +4616 +9891 +2965 +11555 +13437 + +6332 +3010 +7403 +1795 +7359 +5017 +6471 +2495 +2589 +7223 + +5359 +10446 +12714 +1727 +8024 + +11690 +3529 +6145 +8147 +15083 + +5461 +4939 +1905 +3342 +3385 +3920 +5609 +3524 +5645 +6882 +4355 +2263 +3464 + +67422 + +2437 +6392 +1206 +1253 +3402 +4722 +2867 +6304 +3139 +2120 +4953 +5095 +3647 + +16783 + +9717 +25377 +17887 + +6852 +8926 +10395 +2107 +8228 +7462 +5239 +10085 + +22658 +18276 +12253 + +3488 +4976 +4196 +3427 +4603 +1579 +6785 +6656 +5143 +1109 +5507 + +14794 +28617 + +2296 +2367 +1865 +9975 +1988 +3950 +7755 +3008 + +8090 +8620 +11016 +11153 +5513 +2683 +4080 + +10557 +2744 +11379 +8339 +1908 +3088 + +8659 +9142 +1838 +10380 +7386 +4599 +9768 +3718 + +2941 +9112 +6492 +2847 +1562 +8956 + +7867 +4589 +9354 +3953 +7557 +2528 +8845 +8845 +1468 + +7065 +10043 +7109 +4063 +2987 + +11800 +5009 +5108 +4783 +12570 + +61504 + +5512 +1432 +6118 +6389 +2752 +5032 +1688 +5662 +6690 +4760 +6248 +3515 +6122 + +4127 +1192 +3521 +4583 +3060 +5306 +2783 +1949 +3633 +5486 +4799 +2056 +2800 +5770 + +19956 +11717 +16021 +3566 + +2387 +4083 +5811 +3849 +3496 +2213 +4107 +4588 +1995 +1228 +5055 +6133 +1759 + +33909 + +4517 +2866 +1068 +4227 +1063 +4361 +3775 +1875 +1073 +3639 +3237 +4783 +5372 +4323 +3275 + +13452 +14869 +23151 + +12595 +9113 +9304 +5185 +5235 +3787 + +6269 +1291 +2735 +3495 +2070 +5552 +4185 +3574 +4856 +4845 +1211 +4071 +5889 +3287 + +4307 +1452 +2411 +8024 +2614 +7541 +5120 +3104 +3937 +2592 + +37000 +12395 + +4725 +8239 +3949 +9498 +9488 +6151 +5996 + +1748 +3706 +6210 +5673 +3791 +5378 +6384 +2993 +4521 +1687 +2437 +3063 +4262 + +10776 + +1329 +2732 +4136 +3270 +7983 +6004 +4285 +7196 +7543 +7826 + +5324 +15037 +11331 +14308 +13527 + +1542 +4771 +4065 +3939 +5925 +6740 +5121 +6854 +1797 +2246 +2036 +5105 +5555 + +9669 +8993 +7817 +5442 +10974 +7509 +8967 + +46998 + +8151 +8919 +5590 +1172 +12588 +12730 + +1584 +7654 + +25613 + +10908 +3168 +6477 +2079 +1440 +6280 + +7201 +5717 +8338 +1740 +2479 +1984 +1751 +8594 +7637 +1089 + +14411 +3771 +7202 +3251 +2650 + +5964 +3451 +1718 +1723 +2658 +2163 +3113 +6200 +2399 +5498 +1571 +5872 +2842 +6443 + +2611 +3129 +3150 +4293 +3362 +5035 +5682 +1950 +4556 +6069 +1061 +3628 +5222 +2266 +2326 + +3979 +3488 +4876 +2074 +5871 +3413 +3968 +4870 +4654 +3475 +3151 +3581 +4218 +1086 + +1521 +3326 +3537 +3223 +2599 +2264 +3004 +2885 +6521 +4096 +3015 +2034 + +9175 +10101 +6721 +5683 +8376 +3584 + +8994 +12517 +5524 +8860 +1700 + +5976 +5345 +1916 +1376 +4610 +4637 +1222 +1823 +5969 +4598 +1266 +3058 +3274 +3196 +2533 + +4151 +4606 +2939 +7433 +7934 +1433 +7226 +3391 +6444 +3292 +3707 + +13678 +1900 +1316 +2999 +4739 + +10131 +8655 +3662 +6570 +9957 +2535 +3312 + +3632 +1192 +6521 +7333 +1874 +6379 +6505 +3737 +5705 +6127 +3099 +5289 + +13342 +10976 +7459 +17656 + +4441 +2033 +4373 +6988 +5037 +3301 +4940 +5675 +1654 +2206 +6505 +1171 + +23804 +22215 + +5917 +1679 +5720 +2327 +2111 +1479 +5369 +1455 +4047 +2609 +4059 +5461 +3726 +5245 +4617 + +3832 + +30019 +36074 + +2301 +2878 +2284 +2359 +6149 +5411 +4323 +2135 +3423 +5649 +5302 +2837 +4670 +5240 + +2535 +3698 +4005 +4530 +3483 +3840 +5770 +6032 +2261 +4189 +4715 +6289 +3112 +5324 + +5734 +4573 +2286 +1328 +5187 +6665 +5591 +2782 +4429 +5214 +7126 + +4378 +1546 +5909 +5252 +12837 +9857 + +6943 +7103 +6885 +2216 +2277 +5110 +3147 +1669 +2405 + +9766 +2431 +8424 +3505 +4371 + +7819 +3429 +2003 +7906 +4196 +4966 +6544 +2194 +5282 +3391 + +5196 +7087 +5152 +4841 +1323 +8180 +8375 +2274 +9193 + +2455 +9393 +3353 +3473 +6684 +8779 +8869 +1379 +6049 + +10423 +7768 +7405 +8893 +6566 +1104 +2981 +6618 + +2320 + +5330 +4166 +6922 +3242 +4383 +7546 +7715 +7988 +8012 +1877 + +10491 +3303 +2681 +2093 +4378 +6167 +2854 +5345 + +3312 +12989 +13062 +7486 +13302 +1205 + +58470 + +13413 +4298 +3133 +7842 +9040 + +4374 +7227 +10320 +2654 +5348 +12005 + +13208 +7384 +11355 +11780 +7356 +1871 + +1615 +6191 +1367 +1969 +4694 +1704 +6816 +3502 +5382 +4902 +4140 +3525 +5102 + +7778 +5765 +3407 +1334 +8488 +4870 +5197 +5158 +7332 +6025 + +3114 +15591 +23604 + +25210 +12504 +22559 + +1906 +6500 +1781 +2858 +4947 +3217 +3577 +4332 +1509 +6900 +1180 +5648 +3821 + +3982 +4400 +4655 +2599 +2430 +1743 +1817 +1626 +1880 +2769 + +9617 +7677 +3341 +4398 +8994 +10662 +5805 + +2984 +4321 +1939 +4864 +10130 +1227 +7189 + +3586 +4161 +3089 +2857 +2931 +8877 +3311 +5180 +4607 + +2539 +4289 +1168 +6262 +4551 +1731 +1292 +2442 +1423 +1619 +6126 +5220 +5577 + +1769 +4044 +1064 +1380 +2814 +7936 +2928 +3053 +3109 +2695 + +3502 +3521 +4581 +2917 +7040 +1876 +4819 +6214 +2779 +2169 +4885 +5352 + +9675 +13851 +9906 +1245 + +7934 +2860 +17685 + +4982 +3620 +2583 +1264 +2218 +6499 +4028 +9082 +2112 + +3761 +3665 +3717 +1112 +9380 +3463 +9677 +5469 +4111 + +6450 +14269 +17362 +1469 + +9305 +1360 +2214 +1625 +6197 +1322 +7217 +1076 +9466 + +2572 +6102 +7582 +13444 +8038 +1523 + +2212 +7180 +6025 +5842 +2433 +5261 +6975 +8067 +1247 +2153 +3311 + +1770 +5359 +6076 +5750 +4681 +8009 +5273 +3051 +7465 +6530 + +3373 +5040 +4365 +4906 +3988 +2941 +4778 +5635 +4277 +5298 +3161 +4611 +3880 +2808 +5151 + +15491 +3325 +4869 +12203 + +20880 +27057 + +5023 +7729 +7517 +6546 +1217 +7548 +8017 +7453 +6909 +7762 + +16756 + +1104 +2160 +4999 +2256 +2061 +2899 +1677 +1202 +4950 +6408 +2614 +1029 +6114 +3983 + +1676 +22625 +24638 + +6252 +6116 +6544 +4736 +4360 +6578 +2026 +8438 +4904 +5071 + +6250 +1604 +5152 +4034 +4210 +2452 +1982 +1462 +1338 +2083 +1618 +4563 +4859 + +1970 +7309 +2481 +7603 +7395 +6379 +6398 +6117 +7246 +2876 +3027 + +5903 +1822 +5861 +4894 +6005 +4571 +4555 +6531 +5464 +3609 +6464 +7134 + +1225 +21041 +7411 + +6970 +7008 +2951 +2131 +5453 +4772 +3154 +6810 +6825 +4469 +1413 + +1056 +5979 +7996 +11013 +4330 +12024 +10085 + +5270 +2532 +2411 +1372 +2690 +5956 +2638 +3667 +4929 +4946 +4141 +1727 +3957 +3987 +5032 + +11710 +2443 +8104 +9459 +5216 +4656 +9892 + +6455 +7683 +6891 +3883 +5618 +3631 +8120 +4878 +3746 + +8872 +14142 +7663 +14581 +7294 + +3656 +7094 +4543 +7459 +4517 +4732 +4501 +3358 +4838 +4205 +2077 +4579 + +7562 +2081 +8129 +6791 +10059 +2783 +4002 +5055 + +3431 +4855 +6062 +7023 +2386 +4158 +6753 +9088 +3315 + +1011 +3354 +5796 +9625 +3172 +5466 +2276 +8053 +4692 + +4232 +5937 +4857 +4515 +3142 +4902 +2726 +1425 +4999 +3980 +3225 +3083 +3054 +5380 +2547 + +1161 +5732 +5773 +1553 +1317 +3005 +1882 +7352 + +7392 +1908 +6482 +3445 +7074 +8522 +9787 +6791 + +3421 +5673 +5874 +4044 +4264 +2367 +4127 +1186 +4172 +5972 +3405 +2272 +1702 +5672 +4004 + +25299 +34008 + +4160 +6041 +8263 +4164 +2317 +2395 +9046 +5315 +7069 + +5362 +7912 +5760 +6799 +1462 +2520 +9667 +6333 +1055 + +35513 +6387 + +10814 +4122 +11320 +6445 +11264 +5322 +7651 + +5518 +3507 +6489 +11057 +7094 +2014 +3874 + +17936 + +2573 +7532 +1617 +5007 +4781 +4238 +5023 +7946 +7218 +6051 +6517 + +5524 +9035 +2723 +10089 +8048 +7010 +3673 + +11048 +4936 +11979 +4390 +2639 +9910 + +50344 + +5440 +5049 +7437 +2658 +8751 +3995 +1955 +4056 +7203 +3175 \ No newline at end of file diff --git a/2022/Day01/solution.cs b/2022/Day01/solution.cs index 4c91ed5..ce1f815 100644 --- a/2022/Day01/solution.cs +++ b/2022/Day01/solution.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using adventofcode; namespace aoc2022; @@ -9,14 +11,53 @@ public void Solve() Console.WriteLine("solve test"); } + List snackCarries = new(); + public void SolvePart1() { Console.WriteLine("try to solve first part"); + + solutionBase sb = new(); + var input = sb.getInputLines(@"2022\Day01\input"); + + var most = 0; + var actual = 0; + List mosts = new(); + + foreach (var item in input) + { + //Console.WriteLine($"{item}"); + if(item != "") + { + actual += Convert.ToInt32(item); + } + else + { + if(actual > most) + { + most = actual; + } + mosts.Add(actual); + actual = 0; + } + } + Console.WriteLine($"Mosts.Max: {mosts.Max()} - Mosts.Count: {mosts.Count}"); + Console.WriteLine($"Most: {most}"); + + snackCarries.AddRange(mosts); } public void SolvePart2() { Console.WriteLine("try to solve second part"); + SolvePart1(); + Console.WriteLine($"snackCarries.Count: {snackCarries.Count}"); + + List topThree = snackCarries.OrderByDescending(x => x).Take(3).ToList(); + + Console.WriteLine($"top three elves carry {topThree.Sum()} calories"); } + + } diff --git a/Helper.cs b/Helper.cs new file mode 100644 index 0000000..e69de29 diff --git a/Program.cs b/Program.cs index 8d857e0..9560705 100644 --- a/Program.cs +++ b/Program.cs @@ -32,11 +32,23 @@ static void Main(string[] args) } else { + // for testing + var today = new DateTime(2022, 12, 1); + + if(start.Month == 12 && start.Day < 26) + { + today = start; + } + + Console.WriteLine($"set today for testing to {today.ToShortDateString()}"); + + solve(today.Year, today.Day); + //solutionDay1 sd1 = new solutionDay1(2); //solutionday02 sd2 = new solutionday02(2); //solutionday03 sd3 = new solutionday03(2); //solutionday04 sd4 = new solutionday04(1); - solutionday05 sd5 = new solutionday05(2); + //solutionday05 sd5 = new solutionday05(2); } TimeSpan timeSpan = DateTime.Now - start; @@ -61,11 +73,10 @@ static void solve(int year, int day, int part) { //Assembly assembly = Assembly.LoadFrom(@"C:\dev\adventofcode\bin\debug\net7.0\adventofcode.dll"); Assembly assembly = Assembly.GetExecutingAssembly(); - - Console.WriteLine("{0}", assembly.FullName); + //Console.WriteLine("{0}", assembly.FullName); var solution = $"aoc{year.ToString("D4")}.solutionDay{day.ToString("D2")}"; - Console.WriteLine(solution); + //Console.WriteLine(solution); Type type = assembly.GetType("aoc2022.solutionDay01"); object instance = Activator.CreateInstance(type); @@ -77,6 +88,11 @@ static void solve(int year, int day, int part) Console.WriteLine("solved..."); } + if(year == 2021) + { + Console.WriteLine("not yet implemented"); + } + if(year == 2020) { switch (day)