advent2022

Advent of Code 2022 Solutions
git clone git://bsandro.tech/advent2022
Log | Files | Refs | README | LICENSE

commit 0974eb0a9c6d18408e62da44ee240e9c3884887d
Author: bsandro <email@bsandro.tech>
Date:   Thu,  1 Dec 2022 06:03:06 +0000

day 01 part1

Diffstat:
ALICENSE | 24++++++++++++++++++++++++
AREADME | 3+++
Aday01/.main.go.swp | 0
Aday01/day01 | 0
Aday01/day01_1.txt | 2270+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aday01/main.go | 42++++++++++++++++++++++++++++++++++++++++++
Ago.mod | 3+++
7 files changed, 2342 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,24 @@ +BSD 2-Clause License + +Copyright (c) 2022, bsandro. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README b/README @@ -0,0 +1,3 @@ +Advent of Code year 2022 solutions - https://adventofcode.com/2022 + +BSD 2-clause license. diff --git a/day01/.main.go.swp b/day01/.main.go.swp Binary files differ. diff --git a/day01/day01 b/day01/day01 Binary files differ. diff --git a/day01/day01_1.txt b/day01/day01_1.txt @@ -0,0 +1,2270 @@ +9195 +5496 +2732 +8364 +3703 +3199 +7177 +1659 + +7307 +2177 +1011 +8678 +14080 + +6465 +6922 +3733 +8573 +6749 +1704 +6429 +8774 +1296 +2536 + +22456 + +11642 +10162 +10997 +6963 +3076 +5859 +1280 + +5285 +7498 +8540 +7360 +6822 +8042 +6798 +6398 +4495 +8043 + +60304 + +2947 +24880 +21239 + +8441 +1034 +2591 +8993 +10366 +1313 +10497 + +3404 +5018 +5377 +4783 +6441 +5110 +5688 +3371 +1220 +4949 +2945 +6041 +2852 +2379 + +15514 +13699 +10357 +9769 + +11464 +2001 +2847 +9933 +2706 +8621 +2064 + +5478 +2981 +6540 +2303 +4607 +5284 +4762 +3936 +3194 +4371 +2925 +3124 +4491 + +8542 +7605 +3773 +8575 +3405 +4720 +7857 +7427 +5182 +3977 + +9405 +16048 +4142 +9101 +16303 + +6102 +1795 +1053 +2091 +5774 +6053 +4997 +2109 +1019 +3830 +6057 +4772 +3344 + +11299 +16115 +11748 +14944 + +4477 +6292 +8257 +9583 +10416 +2730 +2153 +5887 + +4790 +1198 +2184 +3604 +4004 +1543 +5017 +5409 +3489 +4731 +3302 +3046 +1056 + +2260 +3028 +7305 +4516 +11415 +4855 +4297 + +1669 +4175 +6403 +4004 +1711 +8509 +4874 +3756 +6893 +8463 + +6333 +1576 +4576 +4288 +3764 + +1831 +1336 +1579 +3704 +3215 +4702 +5798 +2714 +2917 +1616 +5564 +5061 +3188 +4473 +3457 + +4140 +3428 +4274 +6158 +4641 +3009 +6576 +6065 +1912 +6539 +6603 +6519 +1765 + +9606 +4903 +3424 +8196 +5996 +8874 +3223 + +1220 +1823 +10789 + +1268 +9582 +18617 +9647 + +5024 +8920 +7746 +1641 +8120 + +2531 +6027 +2332 +1138 +1623 +5812 +5445 +3289 +5476 +4366 +2108 +1557 +3495 +6402 + +9408 +9279 +7150 +10907 +1672 + +5314 +4022 +1005 +2246 +2362 +6739 +2988 +3694 +3827 +7027 +6688 + +5328 +1002 +6230 +3178 +3214 +1388 +1377 +4036 +1138 +3142 +4432 +6435 +1004 +3330 + +7157 +4529 +6804 +2866 +8358 +5096 +6279 +2843 +4766 + +5901 +3567 +5658 +2691 +1274 +5522 +5166 +3121 +4019 +4943 +3075 +6363 +1481 +2265 + +3859 +2225 +8342 +5976 +5027 +8056 +2568 +9185 +4977 + +10439 +23445 +22928 + +19540 +2027 +13612 +11009 + +5729 +2779 +3998 +5445 +5873 +6582 +7603 +4737 +7269 +1552 +6875 + +1281 +14848 +9048 +11497 +5727 + +17791 +13209 +18978 + +5137 +4552 +1608 +2501 +2700 +5797 +5238 +1814 +5319 +2401 +4549 +5636 +3334 +1848 +3434 + +1844 +6371 +6522 +4006 +1587 +3280 +2227 +3655 +1463 +7113 +6222 +1535 + +4030 +7221 +2228 +8901 +3291 +5507 +9136 + +6160 +2512 +4825 +7461 +1360 +5137 +5950 +4281 +6156 +6455 +3709 +6824 + +4851 +3122 +8946 +8309 +2777 +8658 +2167 +4599 + +13020 +11487 +4852 +4141 +10771 + +7617 +1953 +2917 +1490 +11333 +8366 +3536 + +2129 +3570 +3584 +1128 +5877 +6076 +1131 +4300 +4587 +3900 +2032 +6108 +3500 +5816 +2367 + +2321 +9945 +7736 +15720 + +4709 +5471 +4445 +1162 +5062 +4576 +3316 +3568 +4556 +4169 +5592 +2290 +1301 +4286 + +6357 +2925 +3527 +6451 +4206 +3113 +3371 +5688 +5965 +5569 +2426 +3498 + +4785 +3391 +4721 +3860 +4591 +3316 +3906 +4096 +3114 +3084 +5587 +2387 +4083 +3156 +5375 + +18007 +13252 +8010 +11758 + +4133 +4727 +6565 +2361 +4219 +6926 +7563 +2415 +1503 +2280 + +2590 +4700 +6754 +3719 +1385 +6642 +5342 +6977 +6863 +5943 +5963 + +9743 +5874 +2287 +1349 +9400 + +1833 +3455 +4682 +5001 +1194 +4009 +6100 +2669 +2387 +3677 +5969 +5675 +5043 +2851 +1510 + +6344 +7947 +4455 +11855 +12264 + +7307 +5381 +2683 +5690 +3800 +7294 +6155 +3818 +2147 +6822 +1791 +6219 + +5720 +7820 +1697 +8666 +4561 +2786 + +5502 +3231 +2121 +6771 +5496 +4354 +2459 +5300 +1012 +4840 +2244 +2257 +5116 + +6483 +5654 +2132 +1533 +3053 +2037 +2813 +3266 +1113 +3421 +4371 +3298 +1083 +3178 + +5702 +5532 +3500 +10461 +1388 +10833 + +3275 +2980 +7734 +3164 +4787 +9609 +2479 +3653 +6775 + +32754 + +10713 +2913 +2073 +2390 +4035 +5313 + +2154 +2932 +3665 +2209 +4770 +5509 +4867 +1077 +1042 +5075 +1468 +2559 +5969 +4421 +3097 + +10940 + +1790 +3782 +5620 +3929 +8752 +3616 +4303 +5242 +4985 +3153 + +2056 +5738 +6082 +2290 +4491 +3540 +4606 +5400 +1950 +4392 +3358 +3965 +1015 +4747 +4146 + +6837 +1403 +7490 +9041 +1880 +7983 +7951 +3991 + +3812 +8432 +5534 +10149 +6927 +5737 +7757 +6755 + +24486 +17671 +3275 + +5835 +5716 +3114 +4794 +6131 +3155 +5121 +4263 +2172 +1250 +4699 +3474 +2422 +1112 + +2228 +3141 +8939 +2339 +1934 +5567 +4386 +4608 +4715 + +5667 +4951 +1903 +3770 +3604 +3358 +3431 +5347 +1549 +6035 +1213 +2966 +5881 +2159 +5931 + +1855 +2610 +3721 +1186 +1476 +5566 +5896 +5461 +2244 +6439 +2996 +4877 + +3605 +8024 +1015 +2396 +6499 +5491 +6897 +1527 +3023 +3733 +1569 + +4818 +5057 + +5425 +4529 +1806 +4492 +3824 +6389 +2425 +1938 +6364 +3319 +2590 +3288 +3213 +6375 + +19548 +2710 + +2339 +6807 +4818 +6364 +1582 +4337 +2672 +2010 +2158 +4945 +4497 +6038 +6384 + +6358 +24928 + +2269 +7157 +7539 +4229 +5439 +7720 +5840 +5121 + +1874 +4557 +1240 + +20698 +32960 + +6631 +6168 +7092 +3064 +1584 +4665 +7038 +5025 +4993 +4444 +3237 +6476 + +9475 +8971 +8493 +12321 +8494 +13681 + +5753 +3191 +3239 +2583 +1752 +6646 +2353 +9605 +9421 + +6201 +2996 +5305 +3353 +4674 +6344 +3090 +7267 +7553 +3036 + +4230 +1261 +4167 +7900 +7309 +1072 +2156 +7061 +1072 +3936 +5478 + +2149 +5822 +6544 +4842 +3460 +6259 +3309 +6826 +8189 + +5224 +9962 +8680 +8700 +5705 +9423 +9132 + +10634 +5810 +7278 +7563 +4692 +9359 +10970 + +2265 +5518 +4578 +2087 +5530 +2822 +3506 +5354 +3795 +6447 +7721 + +5983 +4123 +11142 +5380 +9873 + +6575 +3055 +1253 +3073 +3428 +5034 +5026 +2078 +2305 +1243 +1741 +1905 +3417 + +7507 +3916 +12542 +3336 +13205 +9414 + +2572 +3152 +4829 +4925 +2805 +2109 +2479 +5310 +2369 +3676 +3808 +2061 +2103 +3846 + +2228 +2731 +3042 +7005 +2663 +5092 +5604 +5128 +2481 +6335 +6596 +1590 + +17388 + +1907 +9742 +2574 +5867 +1944 +9382 +7215 +4615 + +7022 +17033 +18410 +9549 + +12399 +14254 +7540 +14639 + +6076 +1520 +5371 +6776 +3480 +2872 +2754 +3560 +4076 +7127 +4847 + +28413 +29243 + +6331 + +1295 +7963 +7819 +8935 +4932 +2119 +8965 + +4020 +1815 +4975 +4252 +3814 +3944 +4046 +5322 +4492 +6798 +7873 + +22718 +15596 +3783 + +2540 +1228 +6529 +8255 +8380 +7381 +5272 +4335 +9079 + +13674 + +4654 +14973 + +9742 +7320 +6104 +10643 +2218 +3849 +1554 +6240 + +5883 + +2947 +3960 +3137 +3545 +4086 +3281 +2125 +2187 +2672 +6083 +6348 +5979 + +3978 +13338 +6730 +11223 + +10774 +8045 +3517 +5539 + +3497 +3723 +5012 +2253 +6525 +6164 +5048 +3048 +3572 +4049 +4332 + +10141 +5326 +1095 +2973 +5927 +2007 +2050 + +3706 +2393 +7466 +6424 +3406 +6692 +6659 +5887 +2430 +1710 + +2477 +10590 +7756 +6758 +7119 +2697 +7582 +2818 + +7797 +3364 +12741 +13118 +8536 +11425 + +1233 +7736 +7864 +9042 +1637 +10294 + +24161 +9656 +18425 + +5990 +2101 +5653 +2884 +3039 +4797 +5843 +5247 +1273 +5886 +6625 +6674 + +6329 +18772 +2093 +17934 + +4887 +6312 +3128 +3886 +3463 +4255 +3756 +3983 +3426 +1431 +2698 +6393 +1005 +4468 + +5205 +33136 + +6347 +4976 +1837 +2668 +1958 +2844 +1832 +5159 +6743 +5235 +2063 +6345 +5435 + +8099 +7958 +1005 +6197 +5256 +5473 +5305 +6725 +8345 +7710 + +3872 +6145 +9624 +2956 +8435 +10422 + +3327 +8232 +3193 +10317 +8307 +3668 +1460 + +1846 + +8278 +3383 +2806 +8824 +2203 +7408 +8406 +9472 + +4239 +4975 +2739 +5971 +6296 +1441 +3258 +4039 +1250 +6148 +4268 +1029 +4749 + +13122 +16097 +24603 + +16731 + +9483 +5982 +1713 +3420 +8734 +3700 +7331 +6766 +8751 + +8615 +5515 +2095 +6447 +2271 +5116 +4192 +2466 +6024 +7381 + +5890 +1229 +5991 +6171 +1006 +8052 +1047 +2854 +6775 + +2707 +4168 +3672 +5598 +6167 +1829 +1057 +4637 +4838 +1436 +3420 + +11809 +3398 +5077 +7486 +8465 +13335 + +7603 +2418 +5080 +6220 +11293 +3620 +2269 + +3091 +1168 +6766 +1451 +5970 +6730 +4050 +4668 +1481 +5796 +1761 +2176 +6819 + +11912 +11768 +10317 +7266 +7893 +5171 +10226 + +3050 +16374 +8289 +10976 +5718 + +6761 +7838 +13450 +7109 +4241 + +5966 +10730 +10359 +1504 +7420 +5282 +8409 +3601 + +12221 +9545 +19251 + +8255 +13820 + +2603 +2664 +6910 +3057 +3028 +3978 +5942 +1761 +7094 +4810 +6613 +3734 + +1682 +6879 +4558 +5580 +7138 +1357 +6509 +1608 + +10454 +6353 +9343 +5446 +10576 +4785 +10603 +10093 + +4608 +5849 +5198 +6198 +6657 +4876 +4557 +4176 +4300 +2296 +6147 +5391 +2029 + +57604 + +9413 +8063 +7537 +6320 +1097 +6122 +1355 +4272 + +3874 +17796 +15560 +14745 + +2035 +7677 +3549 +7187 +5545 +8078 +7619 +1164 +4781 +1537 +1300 + +4958 +3527 +5457 +2429 +4177 +3722 +2678 +2858 +3860 +2757 +1652 +3601 +1271 +5064 +4825 + +1451 +5344 +9505 +3578 +5125 +3601 +7753 +9647 +5199 + +1023 +2994 +3314 +2984 +1823 +1049 +1451 +4002 +1982 +1991 +5607 +2280 +2637 + +10085 +1558 +4129 +16879 + +4014 +1850 +1953 +1210 +6063 +1152 +1155 +5688 +2564 +2601 +4987 +3243 +5028 +3031 +4566 + +5269 +3381 +6856 +3425 +4686 +7142 +3527 +5679 +1170 +1974 +5245 + +3188 +2577 +5091 +4836 +8051 +9506 +4796 +6060 +2312 + +1174 +2702 +2957 +2060 +2298 +3065 +4107 +5288 +8035 +1408 +1220 + +7531 +28620 + +5642 +9226 +4661 +8001 +3130 +2765 +8861 +5388 +8664 + +38986 + +5940 +1905 +2903 +4936 +1631 +3601 +3904 +5472 +4605 +4450 +1924 +5819 +5595 +2620 +4949 + +2678 +4645 +7836 +9040 +6883 +5728 + +30287 + +7177 +8034 +9715 +5392 +2758 +3528 +2237 +3861 + +3185 +4171 +2020 +4715 +7052 +2755 +1914 +7742 + +1707 +1676 +5745 +4143 +4923 +5895 +4430 +3479 +5577 +4055 +5398 +3686 +3102 + +2210 +7100 +7893 +18459 + +10383 +36815 + +5724 +7580 +5795 +2420 +6769 +2653 +11300 + +64590 + +1458 +2116 +2482 +1405 +5244 +2676 +3142 +5465 +1204 +3386 +2346 +5280 +4419 +5141 +1792 + +15148 +9248 +10159 +15310 +10409 + +6717 +8383 +3815 +4003 +3628 +1330 +3935 +7421 +8104 +6368 + +4427 +12621 +4678 + +8039 +2837 +3527 +7261 +1895 +1730 +2425 +9351 +4956 + +4754 +3919 +7834 +1825 +9221 +2448 +6332 +6027 + +2762 +8800 +2052 +6914 +4855 +5555 +5457 +7150 + +4929 +9391 +2475 +3274 +11392 +6243 +10749 + +9936 +2900 +11200 +8301 +8740 +1807 +9313 + +7654 +6957 +3503 +1388 +3461 +8003 +8540 +8588 +6578 +5105 + +2375 +2789 +4492 +9766 +6242 +8573 +7746 +2312 + +18293 +7456 +12739 +14503 + +4591 +5244 +2190 +1492 +3205 +4797 +4072 +5747 +2280 +3726 +2871 +2903 +3336 +2136 +4352 + +1198 +7124 +7138 +1289 +7137 +3365 +3758 +3462 +1829 +5959 +4767 +5007 + +61923 + +35790 +17566 + +61494 + +6184 +1939 +4155 +6792 +4221 +5606 +5012 +2653 +6955 +4262 +7482 + +8406 +8532 +17249 +14475 + +2836 +5515 +1600 +5230 +2379 +1581 +2792 +4921 +1706 +5905 +4341 +4541 +2423 +1089 +3865 + +10178 +7282 +4389 +1368 +6403 +4864 +9894 +1600 + +14638 +17362 +1290 +13364 + +9732 +4333 +6164 +3377 +10073 + +3421 +5867 +4088 +3939 +2340 +1172 +5329 +1353 +1760 +2609 +2241 +3184 +4067 +3187 + +1251 +10075 +5029 +11495 +16420 + +9941 +1159 +6581 +5359 +5091 +9709 +6879 +1480 + +8735 +7340 +7533 +7967 +3090 +4415 +8030 +2024 +7643 +1020 + +3683 +1827 +4572 +4920 +5321 +6344 +7409 +6644 +5261 +5461 +4746 +2427 + +1933 +3844 +4152 +7816 +4841 +9773 +8031 +4562 + +5859 +5820 +2404 +4008 +6263 +5126 +6608 +4376 +1742 +4257 +3698 +6355 +6830 + +12023 + +13405 +17282 +4233 + +1854 +3016 +5622 +4353 +4201 +1603 +6425 +5189 +5954 +4672 +4166 +6254 +2946 +5488 + +25849 + +5724 +1798 +4680 +3686 + +2487 + +4242 +6224 +5721 +4919 +6956 +2243 +2558 +5831 +4442 +5899 +5110 +3296 +3166 + +8097 +6087 +3812 +8427 +2519 +2596 +8032 +5217 +5404 +1761 + +1051 +8900 +3355 +8481 +10567 +9593 +9889 +1111 + +2421 +7635 +1078 +10224 +3394 +8259 +6023 + +1746 +3725 +5398 +1283 +6522 +5172 +2666 +4207 +3608 +4554 +3320 +3092 + +12151 +2380 +2379 +9460 +2103 +2719 + +4111 +4047 +5566 +1533 +3013 +1914 +6732 +3081 +3039 +2544 +1602 + +1944 +7139 +1270 +3971 +1754 +5539 +7134 +2383 +7875 +6814 +3154 + +6658 +6937 +5130 +12523 +2510 +13475 + +8220 +14140 +16575 +17834 + +30821 +27376 + +6988 +1239 +3428 +9314 +12372 +6311 + +1230 +7470 +5818 +2628 +2076 +4683 +6782 +6631 +5341 +3207 +2733 + +3007 +4564 +3184 +7193 +6232 +6808 +1125 +1167 +5083 +5500 +1501 + +12528 +6660 +5956 +4124 +15907 + +4341 +3095 +5140 +2053 +2632 +4026 +6882 +1575 +2699 +1134 +6729 +3741 +1965 + +40377 + +7974 +32804 + +6933 +17986 + +3950 +8994 +5969 +5927 +9676 +4722 +2511 +3924 + +8550 +5279 +4462 +1898 +4285 +8152 +7672 +6239 +7171 +6077 + +4648 +3574 +3766 +1602 +5875 +2697 +2112 +2269 +5661 +5173 +5412 +3064 +2152 +2421 +3606 + +19130 +24395 +6811 + +14914 +5386 +17927 + +57004 + +6847 +2293 +3144 +6966 +3591 +6579 +6282 +7983 +2019 +5166 + +25773 +21289 +3985 + +18580 +10900 +12012 + +20434 + +6523 +17040 +7830 + +15328 +3273 +17137 +14101 + +25430 + +5245 +1411 +3633 +1296 +4017 +4795 +3146 +6096 +3424 + +2996 + +3496 +12598 +7602 +6914 +2027 +1459 + +5307 +4932 +8654 +5673 +8580 +3054 +7353 +6379 + +5347 +5969 +8241 +8710 +1345 +5500 +2640 +1101 + +10640 +5177 +6497 +5013 +6210 +8109 +9250 +1643 + +23753 +1998 +16905 + +34219 +25863 + +5926 +8576 +4565 +2605 +11086 +10217 +3411 + +4970 +1205 +3186 +5837 +3119 +7356 +4392 +5270 +2521 +2452 +5271 +2905 + +4054 +8657 +9202 +6213 +4409 +4695 + +3198 +7002 +15731 +5099 +16321 + +14542 + +39972 + +10785 +17115 +22811 + +7214 +7178 +5198 +2157 +6985 +1686 +8037 +7559 +2410 +5211 +6477 + +1496 +3607 +2326 +5342 +5777 +6182 +5528 +6324 +2023 +2944 +2175 +5035 +1424 +2154 + +5224 +4172 +1295 +7929 +4386 +2421 +6034 +2895 +3881 +2464 diff --git a/day01/main.go b/day01/main.go @@ -0,0 +1,42 @@ +package main + +import ( + "os" + "fmt" + "log" + "bufio" + "strconv" +) + +func main() { + if (len(os.Args) > 1) { + day0102(os.Args[1]) + } +} + +func day0102(input_file string) { + fmt.Printf("day 01 input filename: %s\n", input_file) + input, err := os.Open(input_file) + if err != nil { log.Fatal(err) } + defer input.Close() + scanner := bufio.NewScanner(input) + max_load := 0 + cur_load := 0 + for scanner.Scan() { + if len(scanner.Text()) > 0 { + load, err := strconv.Atoi(scanner.Text()) + if err != nil { log.Fatal(err) } + cur_load += load + } else { + if cur_load > max_load { + max_load = cur_load + } + cur_load = 0 + } + } + if err = scanner.Err(); err != nil { + log.Fatal(err) + } + + fmt.Printf("Max load: %d\n", max_load) +} diff --git a/go.mod b/go.mod @@ -0,0 +1,3 @@ +module advent2022 + +go 1.19