diff --git a/aoc/2022/day1/d1c1.js b/aoc/2022/day1/d1c1.js new file mode 100644 index 0000000..a1fa0fc --- /dev/null +++ b/aoc/2022/day1/d1c1.js @@ -0,0 +1,64 @@ +use = "strict"; + +const fs = require("fs"); +const inputText = fs.readFileSync("./input.txt").toString("utf-8"); +const splitInputText = inputText.split("\n"); + +const testData = `1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000 +`; + +const splitTestData = testData.split("\n"); +// console.log(splitInputText); +// console.log(splitTestData); + +function determineHighestCarriedCalories(input) { + let highestTotalCalories = 0; + let numberOfElves = 1; + let elfNumber = 1; + let currentTotalCalories = 0; + + input.forEach((line, curIndex, array) => { + if (line.length !== 0) { + currentElf = numberOfElves; + let num = Number.parseInt(line); + if (Number.isInteger(num)) { + // console.log( + // "current Calories: " + currentTotalCalories + " plus " + num + // ); + currentTotalCalories += num; + } + } else { + // console.log( + // `Current elf ${currentElf} has ${currentTotalCalories}` + // ); + numberOfElves += 1; + if (currentTotalCalories > highestTotalCalories) { + elfNumber = currentElf; + highestTotalCalories = currentTotalCalories; + } + currentTotalCalories = 0; + } + }); + + console.log( + `The most Calories carried by is Elf ${elfNumber} with ${highestTotalCalories} total calories` + ); + + return highestTotalCalories; +} + +determineHighestCarriedCalories(splitTestData); +determineHighestCarriedCalories(splitInputText); diff --git a/aoc/2022/day1/input.txt b/aoc/2022/day1/input.txt new file mode 100644 index 0000000..1de8ebe --- /dev/null +++ b/aoc/2022/day1/input.txt @@ -0,0 +1,2240 @@ +2991 +13880 +13279 +1514 +9507 + +6544 +9672 +13044 +4794 +6648 +8669 + +2790 +1196 +3619 +1692 +8727 +2342 +1099 +6083 +3834 +2008 + +2974 +4393 +1146 +4240 +1880 +3226 +2390 +5640 +2768 +1887 +4217 +3314 +5653 +2609 + +4473 +7306 +7909 +6862 +7413 +3738 +2102 +4269 +5966 +7491 +4851 + +10396 +24686 +9258 + +1299 +8539 +7570 +4888 +2209 +2720 +9275 +4843 +1884 + +2421 +1872 +4696 +14627 +7944 + +28659 +27933 + +3477 +3702 +9649 +3433 +3288 +5779 +3578 +5744 + +14516 +18228 +6351 + +23055 +35889 + +1539 +8880 +10443 +10688 +13205 + +1723 +10526 +5505 +6148 +7407 +1316 +1386 +1908 + +6350 +3394 +1405 +12681 +12249 +3342 + +3273 +4478 +1674 +3077 +3210 +4848 +5194 +6226 +1793 +6392 +2969 +3370 +6749 + +5323 +3818 +11179 +5699 +7426 +2055 + +7592 +4222 +1308 +3898 +1905 +5747 +3736 +8450 +4093 +5432 + +3650 +4915 +1762 +1643 +2548 +5160 +5841 +3552 +2407 +3754 +1112 +2095 +4010 + +4648 +4784 +7355 +6149 +3842 +5997 +9033 +8125 +2140 + +5701 +8717 +5937 +1369 +2407 +7081 +5603 +8224 +1719 + +7134 +18703 +12905 +9024 + +1136 +4968 +7603 +1796 +6299 +4692 +7288 +5035 +6056 +4214 +2163 + +5102 +5785 +2014 +5626 +1185 +5211 +5093 +1674 +1129 +2135 +5578 +3682 +2592 +1177 + +14148 +6970 +3442 +4661 +10454 + +7239 +17068 +20869 + +1314 +13042 +11732 +3313 + +16316 +36536 + +11462 +18906 +22733 + +5842 +1252 +2089 +6507 +5646 +3539 +1135 +3911 +3312 +3864 +1561 +1242 +1577 +4928 + +6484 +4452 +7637 +4278 +3223 +2596 +6958 +2926 +8398 +7834 + +42277 + +35666 +23962 + +66631 + +8607 +12209 +12140 +7439 +8233 +10780 + +1955 +4179 +3115 +2461 +4052 +1965 +4867 +2999 +4667 +6305 +2033 +2156 +2720 +5333 + +7146 +4223 +7494 +2463 +9438 +3799 +5983 +8810 +5352 + +6644 +6079 +3698 +5011 +8830 +7311 +5775 +1636 + +47417 + +3449 +4886 +5862 +1067 +6451 +6165 +6269 +4526 +2145 +3366 +2907 +6100 +3448 +1254 + +5486 +6003 +2304 +4297 +4993 +4572 +1397 +3608 +1043 +5773 +2267 +2790 +3298 +5842 + +12417 +4128 +10779 +13809 +4455 +12524 + +4907 +9170 +2300 +4787 +10507 +3252 +3017 + +5847 +1655 +3274 +1333 +1345 +2974 +1634 +5984 +2632 +3336 +3129 +5976 +4261 +5377 +2356 + +3298 +4185 +18840 +8294 + +1545 +9312 +1986 +7355 +4092 +2450 +5827 +9291 + +15323 +11402 +12265 +11203 +10405 + +6310 +7512 +3485 +1855 +5631 +5606 +6932 +5481 +2700 + +1586 +4820 +9274 +8570 +1569 +3103 +8255 +9864 + +11002 +2245 +10309 +4417 +14403 + +3846 +6671 +4086 +9903 +3295 +8426 +4783 +10343 + +3839 +2967 +4060 +5648 +2220 +2952 +5233 +5410 +5957 +1267 +5465 +5686 +1843 +5608 +2876 + +1869 +3328 +5657 +1292 +2594 +6721 +6816 +6180 +3233 +5446 +1196 +1126 +6370 + +7221 +5771 +1747 +2178 +2489 +2483 +8006 +1297 +7288 +2882 + +5109 +3769 +1916 +4030 +5064 +5091 +2593 +4580 +4883 +3898 +5093 +1462 +4974 +3315 +4750 + +4338 +8285 +1073 +1188 +7465 +6912 +1933 +9366 + +10301 +6604 +3170 +7569 +2109 +2540 +1869 + +8537 +9525 +6440 +6314 +7522 +7153 +3792 +4998 +8585 + +2261 +5367 +3569 +1653 +5889 +2656 +4559 +4336 +4047 +2517 +3163 +3464 +5707 +4080 +2922 + +31484 + +6284 +6371 +3846 +6099 +2447 +4024 +6457 +2455 +5285 +1982 +1048 +6029 +3168 +4278 + +4284 +4379 +4699 +5393 +3491 +4928 +2769 +4853 +3575 +5178 +2761 +5158 +5662 +3138 + +9471 +3142 +2990 +2640 +5344 +4397 +8037 +9150 +2463 + +3333 +12379 +1140 +6496 +12356 +10438 + +31049 + +6280 +6924 +4580 +5774 +1092 +1987 +5513 +1612 +3775 +6117 +2074 +1008 +2792 + +5978 +34312 + +15983 +7271 +10111 +10061 +1913 + +28704 +15277 + +24025 +23191 + +18306 +6711 +18537 +19324 + +6021 +4008 +7214 +3499 +3902 +4954 +2579 +3091 +3229 +5659 +4769 + +8220 +7006 +8314 +12372 +4550 +8244 + +3551 +2389 +6163 +5021 +1132 +4774 +1359 +4387 +3766 +5954 +3018 +2230 +1420 +4371 + +9525 +9526 +3372 +1658 +3881 +6444 +4351 +3509 +1460 + +8558 +7212 +6909 +10144 + +18406 +15594 + +2874 +5110 +3416 +3843 +4867 +2379 +5323 +3126 +2865 +1438 +5739 +5554 +2414 +2554 + +4077 +2048 +5488 +2691 +5089 +2188 +3358 +1680 +2924 +3096 +2104 +1717 +1833 +3019 + +11757 +4441 +7469 +3234 +4779 +8291 + +1996 +4223 +4867 +3717 +5649 +2668 +5702 +5023 +3901 +4406 +5510 +2661 +1533 +4191 +1400 + +7414 +1109 +3430 +1863 +5904 +7684 +3006 +6861 +2151 + +5424 +1766 +3046 +1493 +2287 +2836 +1791 +3799 +3946 +6174 +5000 +1012 +1078 +1054 + +6378 +4060 +24317 + +3422 +8186 +10230 +5610 +5148 +5640 +6697 +9931 + +4186 +1561 +5054 +1160 +9066 +1801 +3083 +1458 +6963 + +8939 +7912 +8916 +2111 +5217 +5919 +5273 +7538 +7372 + +10768 +1651 +7043 +1197 +10657 +3884 +4463 +4241 + +66810 + +19272 +18102 +10613 +3908 + +4643 +10608 +9358 +4072 +8940 +6360 +10068 +2116 + +4791 +5553 +4483 +5580 +4445 +3405 +2528 +4133 +5431 +4930 +3270 +5119 +3100 + +10323 +6834 +9322 +5292 +3729 +10536 + +4377 +5696 +1831 +2483 +2420 +1045 +1142 +5294 +3178 +4678 +5912 +4389 +2517 +5257 +3008 + +4125 +10399 +11897 +1295 +2459 +13275 + +33112 +5382 + +4577 +5342 +1546 +3935 +2972 +5917 +6807 +7051 +7018 +4855 +2378 +3974 + +6943 +3464 +4843 +5073 +1477 +8054 +6873 +3861 +4184 +7438 +6297 + +5298 +2153 +4410 +4572 +4580 +6756 +7076 +1043 +4894 +7722 + +6214 +2109 +3696 +1819 +1287 +3928 +1233 +6297 +5185 +1864 +3200 +3230 +6227 +2079 + +1536 +3380 +1856 +1853 +4504 +4101 +1167 +5046 +3233 +2522 +2409 +4679 +5718 +1044 +5828 + +2824 +3323 +5732 +1716 +4082 +1812 +6451 +5249 +4976 +6125 +1353 +5689 +6242 + +1084 +8644 +6344 +3049 +4275 +6275 +3450 +5792 +2225 +2435 + +3099 +5018 +4117 +4452 +10756 +7422 +3595 +5963 + +6311 +3908 +6596 +3238 +5050 +8033 +1455 +6736 +5930 +1928 +3276 + +1600 +1073 +4772 +9737 +9139 +8601 + +4916 +3294 +3356 +2203 +2782 +1691 +3605 +1710 +1499 +4469 +4907 +3151 +2876 +4872 +5376 + +9746 +4484 +6726 +6405 +6379 +6695 +1546 +6393 + +6285 +2133 +7112 +2655 +3135 +4494 +4720 +2529 +5476 +6704 + +9199 +10093 +11924 +13132 +10969 +8021 + +2266 +6407 +4116 +3708 +8866 +8118 +8493 +6382 +6414 + +14026 +15738 +11978 +16047 +4103 + +3333 +2774 +3092 +7997 +3844 +7916 +5528 +6319 +2317 +4643 + +19739 +3748 +5424 + +1039 +3224 +2868 +6107 +6976 +8538 +6323 + +16161 +2927 +8366 +11738 +7602 + +1370 +2592 +2054 +5152 +3537 +5643 +5293 +6632 +1418 +4779 +2883 +6204 + +10644 +12434 +12655 +12592 +2494 + +3389 +2619 +6847 +4510 +5306 +5385 + +1832 +4541 +10862 + +7395 +2103 +3849 +7964 +5105 +3605 +7695 +4921 +3646 +2566 +5996 + +3025 +10709 +6811 +9451 +1852 +2736 + +4548 +6752 +5880 +2428 +6486 +5284 +5820 + +6206 +1977 +6271 +1565 +2363 +6084 +1943 +5714 +4644 +4032 +1643 +2156 +4055 +4567 + +5165 +5035 +7605 +4427 +2647 +8011 +2908 +1168 +3266 +5529 +7711 + +23833 +10619 +15010 + +5060 +4907 +6624 +5395 +1016 +6929 +5380 +3764 +5532 +7831 +5329 + +7904 +2841 +1018 +1426 +4579 +4510 +3989 +1289 +8273 +4279 + +12736 +14190 +16883 + +32835 + +4317 +1193 +5184 +4546 +1694 +1196 +4373 +2347 +4049 +5666 +5698 +2817 +4678 +3980 + +22571 +5504 + +37209 + +4757 +4579 +6807 +1442 +1536 +6602 +3905 +6884 +7226 +3101 +1120 +3849 + +5590 +4892 +3081 +2536 +6082 +1532 +2318 +2777 +3641 +2864 +2505 +1679 +4880 +1163 +2077 + +3948 +3128 +3485 +1641 +3989 +5132 +6057 +5384 +5990 +6257 +6507 +3405 +3960 +3868 + +2939 +3711 +5743 +3425 +5965 +5620 +3055 +6930 +4500 +4733 +4011 +1553 + +8219 +20157 + +10494 +6572 +2011 +4950 +7388 +4958 +6701 +10093 + +5062 +6365 +2966 +4770 +6178 +4993 +5128 +1438 +6268 +5552 +3329 +3863 +4256 +3647 + +1580 +2151 +4323 +2744 +2838 +2084 +2356 +2912 +5797 +5836 +6001 +6283 +6956 + +5872 +5366 +1071 +3423 +7950 +5515 +7606 +4833 +4363 +6754 + +7304 +2085 +2765 +3046 +5378 +7258 +3930 +2047 +5211 +5948 +3480 + +9663 +6108 +7148 +9800 +10254 +9203 +7937 + +12218 +9139 +13622 +7696 +10329 +11172 + +9401 +9897 +10143 +6100 +9964 +2154 +7319 +7498 + +8780 +5117 +7036 +3037 +1706 +5242 +7249 +7284 +2078 +1728 + +17577 +7230 +10234 +18936 + +8416 +1185 +2396 +6979 +2992 +2253 +2917 +7305 +8488 +4622 + +6685 +5299 +4251 +2549 +3790 +5368 +7221 +5706 +7925 +6502 +7808 + +6241 +4351 +7552 +3775 +6773 +7225 +7567 +5820 + +3950 +3540 +1080 +7325 +3394 +4633 +1869 +6327 +3902 +1421 +3541 +7361 + +4850 +7359 +5156 +9779 +3045 +3741 +1889 +4935 + +3506 +3235 +2392 +2384 +1722 +1272 +1297 +3784 +1520 +4136 +4597 +6208 + +1713 +1735 +6325 +7553 +1611 +5346 +5266 +1007 +5645 + +22956 +18090 +2717 + +1498 +8912 +2860 +10065 +4102 +10195 +8619 +7174 + +2990 +3208 +7040 +14050 +1387 + +3086 +10540 +8999 +2483 + +16011 +14905 +5517 +9267 +9327 + +7848 +1954 +10323 +7195 +9807 +4464 +3234 +2104 + +2235 +4964 +3309 +2177 +5222 +4738 +2714 +5281 +3441 +4456 +4352 +1169 +2808 +3138 +3274 + +8877 +9811 +5627 +6382 +7521 +5837 + +5504 +4031 +6402 +3441 +6483 +5283 +1036 +1335 +5285 +4683 +5401 +7344 + +4169 +14771 +1896 +13377 + +6438 +3297 +7216 +5522 +1471 +2817 +5369 +6477 +3806 +6599 +5724 +6522 + +6076 +3239 +8915 +8080 +2812 + +1607 +5198 +5896 +3895 +1229 +2030 +5527 +4837 +5821 +3149 +3159 +1656 +6030 +2010 +4604 + +2844 +4604 +5741 +11440 +5163 +4355 + +1844 +5763 +4911 +2989 +5267 +6645 +4968 +4317 +3036 +1724 +1784 +5800 + +13575 +4117 +4728 +5783 +9013 +13240 + +13842 +15191 +3141 +4765 + +7938 +2898 +7974 +2035 +7803 +1909 +1098 +9097 +9291 + +6535 +1174 +4794 +1525 +5808 +7345 +2768 +7255 +2257 +5602 + +13575 +19965 +17232 +2750 + +35642 + +7697 +6719 +1812 +13584 + +26437 + +7606 +7892 +7526 +4920 +6775 +2129 +2548 +7524 +5114 +5294 + +4056 +17673 +13062 +14865 + +1487 +4138 +2188 +3584 +5151 +4029 +7213 +2313 +3330 +5396 +4269 + +6793 +7201 +7619 +9344 +9472 +5835 +2234 +2088 +8763 + +1631 +2291 +7526 +1090 +1009 +5730 +1354 +6865 +7140 +6000 +3380 + +10624 +17641 +2161 + +8172 +8971 +2217 +6300 +2777 +6061 +4855 +1749 +1893 + +2178 +8240 +8476 +2192 +9511 +8940 +8280 +4132 +5311 + +27950 +33583 + +2652 +4372 +6853 +1967 +6620 +4484 +3223 +4281 +5273 +1766 +6234 +5574 + +6828 +5915 +3458 +6806 +2814 +4145 +8642 +5397 +2549 +7984 + +6032 +5403 +3959 +5411 +4179 +5540 +1545 +4430 +2484 +1772 +3279 +5560 +1907 +2885 + +4832 +1221 +4133 +1614 +2348 +1641 +6835 +6891 +4221 +2430 +3820 +2499 + +5998 +4269 +3322 +1257 +7604 +3261 +8784 +5152 +6059 + +9655 +3995 +13638 +4250 +2830 +11687 + +6156 +1364 +2380 +2225 +9824 +1512 +6378 +6675 + +1571 +6937 +5199 +1593 +4612 +2487 +5548 +2038 +2591 +6347 +3044 +1079 +4688 + +5238 +7304 +4476 +2930 +3782 +7293 +3726 +1404 +1901 +4445 +7015 +6752 + +8419 + +6892 +6548 +2671 +1757 +4123 +3463 +2570 +7263 +5229 +5192 +7325 + +13782 +7314 +12677 +12477 +13486 +5230 + +13577 +3934 +10077 +9166 +4717 +7645 + +5358 +2198 +3312 +4801 +2527 +4034 +1999 +4764 +5788 +3458 +2843 +4598 +2322 +2422 +4872 + +3140 +1599 +1635 +8875 +9163 +4841 +10028 +5565 + +2464 +3454 +3594 +9524 +8722 +5689 +1560 +5812 +3010 + +6702 +15704 +22334 + +8121 +3272 +8232 +4521 +7689 +8203 +3491 +8651 +8999 + +1659 +6794 +8706 +8685 +9729 +2422 +7210 +10240 + +25308 +12582 +13844 + +5243 +5754 +4904 +3074 +2228 +2314 +6750 +8273 +7456 + +31763 +33698 + +11467 + +1057 +1163 +5868 +7365 +6298 +5522 +5083 +2607 +2640 +6784 +7421 +3097 + +1671 +6274 +3342 +7291 +1221 +7314 +3739 +4931 +3184 +4064 +2119 +1381 + +5228 +10244 +8153 +11913 +10240 +12109 +10580 + +61792 + +10208 +4324 +5583 +11389 +9223 + +4904 +6100 +5521 +1951 +14505 + +2267 +13080 +14058 +7587 +11313 + +5089 +3437 +2229 +4505 +6358 +7240 +7977 +4973 +1308 +6776 +2254 + +7189 +5182 + +2620 +2814 +3095 +4199 +1173 +2148 +1367 +6002 +5100 +6194 +3338 +1169 +4422 +1599 + +2098 +3218 +3992 +3373 +7069 +4080 +6550 +4385 +5412 +4140 + +7124 +2473 +6789 +1286 +7079 +4559 +1459 +6747 +3849 +5240 +3090 +2784 + +17116 +18851 +22020 + +6834 +3351 +3681 +2709 +4499 +5769 +7705 +5554 +4324 +5470 +5946 + +1775 +7411 +4045 +7449 +1652 +5962 +7406 +1113 +6763 +6892 +4421 +1151 + +3725 +6326 +1296 +5944 +1223 +1111 +4446 +1905 +9251 + +8153 +12814 +3302 +1661 +11623 + +3386 +4242 +3179 +7596 +1099 +1223 +6241 +1020 +4869 +4247 +4906 + +5208 +2362 +5365 +5656 +5553 +2689 +2832 +2248 +2565 +4027 +3744 +4494 +3262 + +2013 +3397 +2712 +2766 +1050 +6780 +2011 +5529 +6836 +7063 +2265 + +10758 +6733 +13823 +10328 +11961 +2488 + +1908 +3576 +2367 +2913 +7258 +6005 +6231 +2573 +2938 +4048 +5005 +5973 + +4602 +2148 +1414 +1018 +5080 +1286 +7079 +2476 +5975 +3865 +7153 +3292 + +5474 +2200 +1666 +5834 +6504 +4983 +4229 +5689 +5358 +5298 +4968 +3762 +6038 +6140 + +8424 +4933 +2202 +8871 +9421 +1163 +10520 +2527 + +6145 +1123 +3662 +5987 +7112 +8320 +7502 +2351 + +4890 +2668 +5522 +4488 +1494 +5735 +2009 +5489 +3132 +2789 +1876 +5855 +1277 + +1597 +3115 +5153 +5194 +5268 +1057 +1302 +4087 +4640 +2687 +1436 +3447 +5824 + +1836 +7952 +3379 +6602 +10400 +7891 +7102 +6127 + +6646 +6790 +6513 +4780 +4377 +5911 +2832 +6423 +2909 +4189 +1711 +4975 + +8072 +5304 +12460 +12406 +7023 +5993 + +6462 +1631 +6429 +2025 +3339 +7157 +8182 +4927 +3654 +4273 + +16156 + +8008 +2078 +2961 +2709 +7088 +2669 +6653 +6788 + +6810 +3227 +8499 +9527 +3141 +2629 +1326 +2026 +8875 diff --git a/aoc/2022/day1/testdata.txt b/aoc/2022/day1/testdata.txt new file mode 100644 index 0000000..444e241 --- /dev/null +++ b/aoc/2022/day1/testdata.txt @@ -0,0 +1,14 @@ +1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000 \ No newline at end of file