advent-of-code

advent of code attempts
git clone git://bvnf.space/advent-of-code.git
Log | Files | Refs

commit 7a8e830deb588bf096f2decdb017d7ab78dc4124
parent 48d2de6074473bc08bb44a1e16b5c1075c1bf7c7
Author: aabacchus <ben@bvnf.space>
Date:   Fri,  2 Dec 2022 15:30:13 +0000

22.1 in sh

Diffstat:
A2022/01/count.sh | 30++++++++++++++++++++++++++++++
A2022/01/count_2.sh | 44++++++++++++++++++++++++++++++++++++++++++++
A2022/01/example | 14++++++++++++++
A2022/01/input | 2237+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 2325 insertions(+), 0 deletions(-)

diff --git a/2022/01/count.sh b/2022/01/count.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +[ "$#" = 1 ] || { + printf "usage: %s inputfile\n" "$0" >&2 + exit 1 +} + +max=0 +cur=0 +while read -r line; do + case "$line" in '') + [ "$cur" -gt "$max" ] && max="$cur" + cur=0 + ;; + [0-9]*) + printf "%d\n" "$line" >/dev/null 2>&1 || { + printf "%s is not a number\n" "$line" >&2 + exit 1 + } + cur=$((cur + line)) + ;; + *) + printf "%s is not a number\n" "$line" >&2 + exit 1 + ;; + esac +done < "$1" +[ "$cur" -gt "$max" ] && max="$cur" + +printf "%d\n" "$max" diff --git a/2022/01/count_2.sh b/2022/01/count_2.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +[ "$#" = 1 ] || { + printf "usage: %s inputfile\n" "$0" >&2 + exit 1 +} +update () { + if [ "$cur" -gt "$max1" ]; then + max3=$max2 + max2=$max1 + max1="$cur" + elif [ "$cur" -gt "$max2" ]; then + max3=$max2 + max2="$cur" + elif [ "$cur" -gt "$max3" ]; then + max3="$cur" + fi +} + +max1=0 +max2=0 +max3=0 +cur=0 +while read -r line; do + case "$line" in '') + update + cur=0 + ;; + [0-9]*) + printf "%d\n" "$line" >/dev/null 2>&1 || { + printf "%s is not a number\n" "$line" >&2 + exit 1 + } + cur=$((cur + line)) + ;; + *) + printf "%s is not a number\n" "$line" >&2 + exit 1 + ;; + esac +done < "$1" +update + +printf "%d\n" "$((max1 + max2 + max3))" diff --git a/2022/01/example b/2022/01/example @@ -0,0 +1,14 @@ +1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000 diff --git a/2022/01/input b/2022/01/input @@ -0,0 +1,2237 @@ +7896 +4992 +1382 +2920 +7533 +2709 +6020 +5321 +2698 +6806 +8008 + +1340 +1472 +7147 +2707 +5491 +7003 +2337 +1401 +5309 +4385 +2805 + +6019 +1924 +8917 +6303 +9358 +3640 +1563 +1902 + +10946 +10333 +8504 +6110 +10157 + +4578 +1711 +3343 +6159 +4045 +3487 +3070 +5663 +3518 +5839 +5911 +4970 +4852 +4512 + +4277 +3324 +6172 +8272 +2707 +3292 +6599 +1204 +7030 +3075 + +6907 +5595 +10251 +8654 +4036 +11545 + +16787 +11035 +12217 + +2196 +1519 +5810 +6837 +1193 +6480 +1237 +1659 +4323 +2896 +3878 +2894 + +15886 +20356 +23636 + +8795 +7986 +14228 +15738 +13503 + +6598 +17951 +17508 +2446 + +1382 +3232 +6467 +2791 +6250 +2704 +3898 +5569 +8676 + +2582 +8767 +3195 +7957 +6614 + +24737 +34912 + +28868 +34308 + +2703 +20947 + +5548 +5930 +6705 +4227 +6120 +8723 +4597 + +5877 +1223 +5789 +2207 +3488 +5210 +3056 +4300 +3880 +1826 +5366 +4531 +2016 +5304 + +4226 +5314 +6437 +1737 +1229 +3757 +5128 +1058 +5940 +3344 +5188 +4963 +1403 +5498 + +4969 +3096 +7035 +2695 +4747 +5109 +6294 +7990 +1539 +2608 +2944 + +14127 +9751 +4842 +1106 +2779 + +11896 +6643 +15874 +10487 +4141 + +4696 +6644 +6285 +4321 +4080 +6888 +5213 +5048 +6545 +5848 +1690 +5351 +2560 + +17296 +4277 +8327 +7931 + +8374 +3794 +5435 +6968 +4768 +3458 + +5090 +5614 +9448 +10331 +1311 +12604 + +5126 +4860 +1299 +6934 +11746 +2628 +12132 + +6648 +8567 +10219 +2385 +3642 +10478 +7662 + +9206 +2176 +6472 +12314 + +7006 +9478 +2742 +12074 +11993 +3221 + +2458 +4271 +6417 +13749 +5411 + +7826 +4566 +10845 +4535 +5673 +8305 + +8264 +11302 +7040 +9481 +9935 +6624 +8376 + +10460 +20936 + +3456 +3498 +6808 +7408 +5543 +3673 +6672 +6650 +7560 +2477 +6505 + +6943 +3217 +6235 +5079 +1386 +3453 +1736 +4569 +1422 +2804 +5807 + +2241 +1925 +3348 +4805 +2575 +3656 +1379 +5628 +2348 +4652 +5052 +5788 +4128 +2160 + +4839 +3854 +3192 +4055 +1892 +5418 +6415 +1645 +1609 +3844 +3097 +2117 +4043 + +6996 +16021 +23549 + +5493 +5824 +7101 +5017 +8221 +5407 +1963 +6083 + +4896 +18916 +17584 +19464 + +2897 +1198 +1847 +4416 +3086 +2006 +1743 +1387 +3390 +1416 +4713 +3831 +2789 +5146 +2220 + +9452 +8265 +6453 +2831 +3803 +1928 +1047 +5087 +9454 + +2885 +1518 +5218 +2629 +5204 +3715 +4468 +4399 +3020 +5194 +5361 +4566 +5875 +3995 +3081 + +5435 +3159 +1378 +1333 +4491 +5405 +4858 +3744 +5468 +2313 +3014 +2236 + +7027 +5112 +6675 +1149 +5519 +7197 +5210 +3811 +1259 +3794 +2700 +6518 + +6066 +2040 +1948 +2972 +3816 +1477 +4477 +3085 +4169 +1245 +5008 +2016 +4449 +1544 +1511 + +5909 +3378 +12050 +6988 +11093 +8034 +2552 + +5647 +7225 +1416 +4531 +2148 +5176 +1086 +1268 +3907 + +8824 +12672 +6094 +4105 + +9982 +1255 +5102 +2060 +8348 +8610 +9019 + +6442 +8353 +2849 +6823 +5061 +8540 + +1020 +4819 +2371 +6452 +2589 +2140 +3018 +6422 +2079 +1049 +4183 +1959 +6889 + +3370 +20341 +6283 + +3568 +8914 +2474 +1840 +1092 +2901 +4619 + +5489 +5048 +2151 +1275 +4555 +6105 +6393 +5439 +1175 +3143 +1039 +6159 +4280 + +25302 +11104 + +16342 +19486 +6818 +5872 + +4287 +7300 +5106 +6009 +5397 +4743 +8786 +5374 +7723 +3342 + +7830 +4687 +3639 +5942 +8019 +7531 +4763 +8086 + +2928 +12662 +1729 +15599 +7031 + +4504 +8351 +3310 +2860 +7474 +1052 +7088 +7300 +7653 + +3800 +3285 +2244 +6146 +1527 +2496 +3373 +2935 +4073 +2708 +5854 +4532 +4265 + +38782 + +3895 +2886 +3397 +10665 +7954 +5994 + +3830 +4381 +4042 +3631 +2109 +2742 +2748 +1117 +2772 +1921 +4357 +2960 +4504 +6021 +2300 + +5684 +30508 + +5467 +4827 +7991 +4299 +4152 +7070 +1911 +1345 +5607 +6490 +5631 + +2288 +4534 +1402 +2221 +2137 +4623 +5745 +1848 +1638 +2562 +1095 +2539 +4090 +3929 +4330 + +3776 +11693 +1189 +2039 +2662 +11224 +9212 + +3778 +1619 +4008 +1706 +1926 +3844 +5194 +3554 +6272 +2988 +4779 +5481 +1443 +6297 + +1712 +6076 +7332 +5267 +6685 +2555 +4517 +8692 +1819 + +23640 +10894 +25482 + +10592 +9277 +1228 +1197 +9162 +4838 +3783 +2691 + +15579 +16090 +5228 +4273 +5288 + +4044 +10911 +4767 +8658 +5775 +9369 +5332 + +8063 +4322 +5109 +6744 +5653 +9544 +2610 +2241 + +3885 +1140 +10508 +11910 +6096 + +7234 +15371 +10892 +15338 +12191 + +3698 +3413 +3783 +3362 +1828 +1302 +3426 +3147 +5558 +2644 +3636 +5842 +5261 +3312 +3164 + +3088 +1303 +2194 +5841 +5330 +5986 +4108 +4571 +7161 +6276 +5920 +5011 + +6546 +30555 + +5922 +2401 +4792 +7175 +7942 +5040 +3601 +2213 +6802 +2244 +6891 + +2694 +7905 +6046 +3782 +5591 +3665 +4195 +4579 +4300 +1822 + +6308 +2993 +5663 +4780 +6638 +6503 +6307 +4682 +7281 +4580 +7441 +5611 + +9706 +4619 +2108 +8345 +2422 +12140 +9146 + +4984 +10121 +4062 +3797 +5130 +1641 +11492 + +7592 +9412 +5474 +7809 +8073 +2056 +3839 +3557 + +7893 +3556 +9427 +2836 +10256 + +4410 +3041 +2124 +5830 +4200 +4102 +5146 +3355 +4318 +5422 +4992 +1979 +2696 +5277 +4058 + +13134 +35366 + +5363 +1706 +4925 +5967 +8514 +3362 +1424 +4427 +8906 + +2891 +4388 +10112 +3409 +2477 +1138 +3790 +4712 + +9130 +4622 +9723 +4660 +2778 +1083 +2326 +9254 + +3221 +4739 +3752 +1220 +10337 +1159 +2367 +1900 + +2038 +5545 +5904 +5378 +4334 +2897 +5745 +3670 +4773 +3087 +5760 +4026 +3719 +3084 + +8674 +8656 +4162 +5125 +4183 +3496 +7379 +6150 +5225 +8014 + +10321 +16081 +6163 +2030 + +31755 +18352 + +1666 +15493 +8858 +15689 + +1903 +7006 +9002 +5067 +9397 +8703 +7534 +8188 +4983 + +4398 +12055 +6820 +2412 +10308 +11231 + +5914 +9582 +4568 +7679 +5867 +5798 +2955 +7834 +1833 + +2554 +1886 +4590 +3753 +3161 +4039 +2435 +1172 +2690 +4564 +5160 +3715 +2834 +6074 +1251 + +9837 +4501 +3669 +7682 +2762 +6072 +8731 +2324 + +7030 +6956 +3040 +2185 +4717 +2907 +5255 +1194 +1309 +5100 +5630 +5164 + +18808 +5780 +13062 +16131 + +5436 +13758 +12390 +14884 + +5344 +3178 +1907 +6945 +6435 +3985 +3637 +6984 +2108 +2282 + +6870 +3774 +4149 +3361 +3208 +3696 +4265 +2295 +7068 +4365 +6729 + +9828 +3819 +7654 +2391 +11354 +6751 + +5409 +6025 +6772 +4005 +6894 +2723 +2485 +5866 +5744 +1804 +2509 +3285 +5663 + +6630 +7966 +6366 +2854 +3478 +6566 +3790 +4047 +8471 +5911 + +5930 +4813 +10365 +1430 + +13119 +11915 +4732 +9949 +13699 +9790 + +3413 +3027 +5513 +3320 +4421 +2507 +5781 +2622 +5472 +6590 +2021 +2164 +4106 + +49386 + +3656 +7422 +6157 +5982 +3944 +5726 +2628 +6618 +6138 +2186 +4744 + +33805 + +9976 +4213 +4359 +3723 + +4106 +1423 +3334 +5115 +3819 +1308 +2652 +5954 +4439 +2188 +3415 +1104 +2973 +1681 +4704 + +64085 + +1097 +4369 +3803 +3247 +5135 +6928 +3419 +2418 +5130 +2555 +3043 + +4831 +2425 +2023 +1667 +6410 +6422 +5851 +4966 +6721 +5312 +3792 +6700 +1545 + +1742 +5176 +8587 +9261 +15254 + +3097 +6016 +5558 +3004 +4372 +1986 +5576 +6105 +1709 +1326 +4997 +5528 +2823 +3072 + +1228 +2891 +3056 +5874 +2267 +2232 +1754 +3979 +1881 +6633 +1889 +5506 +4377 + +3703 +6310 +1020 +4891 +4911 +2913 +3888 +4642 +1963 +3716 +2222 +4528 +1030 +6081 + +10172 +1472 +6212 +9125 +9365 +7866 +3525 +4752 + +2546 +2326 +5739 +1010 +4724 +5324 +2495 +2999 +5272 +1937 +4396 +6333 +3632 + +2944 +1285 +3457 +1980 +2346 +5712 +5088 +3718 +2036 +6725 + +4335 +5577 +4533 +3275 +4297 +2774 +5029 + +1396 +5993 +4058 +1095 +4388 +1843 +1643 +6192 +2801 +2583 +4286 +5483 +2308 +1577 + +1584 +7552 +8133 +9503 +1989 + +4584 +7691 +4707 +5757 +2519 +2097 +1460 +6651 +3569 +1159 + +9366 +3998 +2020 +2598 +2166 +3298 +6533 +1323 + +10007 +2282 +10952 +3217 +8819 +7164 + +3095 +1126 +1893 +1540 +3172 +2310 +2566 +2438 +4431 +3423 +6675 + +4131 +9513 +11678 +5248 +7769 +3887 +3494 + +5382 +1013 +4021 +7366 +12330 +13746 + +3536 +4407 +1205 +6210 +1388 +6202 +5314 +3286 +6888 +3049 +3946 +3684 +4187 + +1934 +1285 +3262 +4136 +5790 +1340 +2597 +2992 +3008 +5698 +3688 +3086 +2459 +2413 +4769 + +2150 +1030 +3068 +3747 +5417 +4237 +3311 +5081 +4846 +5555 +4650 +3830 +2209 +3069 + +9935 +9564 +15110 + +3038 +2079 +1059 +4905 +4104 +3502 +6338 +1366 +5990 +6073 +4692 +4706 +3474 +3469 + +5845 +1176 +5553 +4578 +3868 +6154 +4799 +5079 +5927 +4185 +1806 +4449 +6248 + +1280 +2823 +1372 +5899 +2547 +5738 +1545 +1046 +2917 +4931 +6094 +3690 +5021 +4657 +1214 + +3046 +4952 +1138 +2373 +1412 +4848 +5772 +4750 +4741 +5752 +5977 +5270 +5526 +3509 +1793 + +3228 +9849 +11815 +6507 +10144 +4756 + +5119 +1764 +1718 +4813 +3662 +4731 +2755 +1315 +1975 +5716 +4859 +4748 +4809 +1296 +1689 + +2909 +7209 +6124 +3235 +4089 +1271 +6220 +10328 + +5630 +10237 +5572 +1065 +2126 +7181 + +32487 +2379 + +2718 +4228 +7834 +6711 +7619 +6321 +1080 +8584 +6860 +6542 + +5106 +8514 +6109 +1204 +5159 +7935 +7292 +8114 + +5898 +4837 +6825 +4587 +1021 +5713 +4862 +3864 +2022 +1129 +4444 +6439 +4369 + +8875 +7916 +2177 +2085 +8103 +7908 +6266 +9099 + +23274 +30650 + +5537 +21092 +21841 + +5852 +9025 +4459 +4883 +2577 +4679 +5673 +1548 +6726 + +4034 +2542 +15179 +6499 +3472 + +2228 +5558 +7863 +5080 +6441 +2064 +1676 +8473 + +18854 +5610 +18471 + +1196 +3063 +13221 +19006 + +37369 +24756 + +4271 +6806 +6381 +6363 +5221 +5729 +3829 +7832 +1150 +3352 +3210 + +1422 +2606 +6070 +4950 +4300 +4023 +1862 +5027 +5668 +5058 +3969 +2359 +5394 +6001 + +12165 +13318 +11945 +12507 +11398 + +9539 +8607 +7451 +11189 +11056 +3209 + +5845 +2759 +4046 +3838 +2768 +1168 +1237 +6370 +3384 +3938 +3946 +5028 +2603 + +20671 +8067 +7232 + +7376 +3530 +3343 +4917 +6712 +5080 +5846 +2774 +3020 +5738 +5500 + +5185 +2455 +6887 +7349 +1917 +2435 +2458 +3676 +1783 +8567 + +5585 +3750 +2664 +6867 +1506 +6830 +1279 +7877 +2757 +4091 +2731 + +11132 + +6128 +2421 +5519 +4390 +6457 +2769 +1410 +3365 +5682 +5685 +1502 +3245 + +1265 +7559 +8923 +1805 +9738 +3780 +9131 + +3052 +5440 +1672 +3462 +1053 +2902 +2137 +5053 +4905 +3544 +4374 +2718 +5799 + +24868 +18500 +13495 + +4653 +5142 +2117 +2908 +2324 +4335 +1096 +6733 +2380 +5352 +1830 +1893 +2491 + +3142 +4111 +4577 +6019 +1075 +2596 +4950 +5814 +5880 +5573 +3672 +2623 +5602 +1032 +5599 + +7365 +2959 +6303 +6111 +4607 +6530 +4873 +4367 +3776 + +16700 +7439 +4758 +6160 + +4203 +1817 +2941 +5662 +1387 +1698 +3031 +3718 +6087 +4971 +5592 +4460 +5271 +3867 +4998 + +22671 +4704 +23657 + +5028 +5059 +4212 +1200 +2284 +6082 +4589 +4383 +4682 +1243 +6449 +1380 +4515 + +10431 +11132 +13078 +3070 +8963 +1329 + +3931 +6924 +5760 +2448 +4709 +13742 + +4493 +4759 +5130 +5004 +7898 +8508 +6718 +2769 +5103 +4254 + +2261 +4383 +1602 +3767 +4634 +3704 +4242 +6316 +5351 +3531 +3470 +3904 + +3541 +2879 +1596 +4477 +1209 +2089 +4365 +4813 +1830 +1069 +2994 +6076 +3379 +4130 +4102 + +11774 +16285 +15432 + +1364 +3558 +5162 +4115 +2730 +3464 +2673 +4541 +5020 +5299 +3199 +3221 +4372 + +2696 +2080 +4206 +1901 +6091 +4955 +2674 +2184 +4977 +4339 +1011 +3766 +5911 +5316 +3703 + +21030 + +6714 +3093 +1168 +1507 +5134 +6516 +1572 +8383 + +5080 +7055 +6559 +4514 +7036 +7348 +5836 +2223 +1996 +4888 +3666 + +25117 +18822 + +2855 +4165 +4812 +8068 +6471 +4447 +4482 +4775 +1002 + +5999 +5674 +4022 +7403 +5593 +6164 +5109 +6856 +3449 +1689 +3727 +2115 + +5781 +4639 +3684 +4010 +4018 +1004 +3081 +1003 +1702 +1457 +1301 +2122 +2014 +5790 + +6373 +1849 +4389 +5772 +4888 +7981 +4238 +1476 +5550 +2922 + +1513 +8603 +5489 +6664 +4505 +7378 +4185 +8087 +6799 + +6482 +3622 +5516 +6214 +6243 +6214 +4711 +3038 +3398 +5483 +3145 +3536 + +9125 +5549 +8576 +5240 +6032 +7952 +5140 +7580 + +6079 +2048 +4407 +5706 +2535 +4588 +5182 +3204 +5287 +5221 +2457 +6932 +4174 + +5505 +1576 +13849 +5436 +2535 +3865 + +2178 +5420 +1013 +6435 +3810 +2903 +5079 +4332 +6257 +1344 +4511 +3127 +6464 + +3805 +2215 +1614 +2501 +1067 +1874 +6199 +1733 +2146 +6581 +3514 +1175 +1099 + +6473 +3376 +4934 +5773 +4970 +7229 +5716 +1014 +7507 +6012 + +3636 +3377 +5729 +2413 +6252 +3314 +2928 +2317 +1157 +2788 +3842 +3906 +4650 +5338 + +5103 +2724 +3794 +1431 +5838 +3971 +2107 +6475 +1746 +5986 +3736 +6345 +4124 +5664 + +3774 +2420 +1478 +2100 +2608 +1168 +1584 +1266 +1346 +1262 +6217 +6392 +2148 +4525 + +3294 +14112 +2438 +13482 +4287 + +10170 +4078 +4238 +3724 +8472 +9110 +5386 +3743 + +10397 +11155 +4476 +7990 +8374 +3340 +4575 + +27723 + +7777 +9699 +8470 +1721 +7728 +1288 +4458 +3428 + +12000 +5191 +8549 +9184 +3081 +11587 +9430 + +13626 +2596 +12534 +7672 +5161 +1160 + +7830 +3505 +7940 +4756 +6977 +3085 +2639 +6439 +4919 +1421 +5196 + +2714 +1424 +7020 +8593 +1436 +7652 +1146 +4168 +2069 +5958 + +38215 + +1436 +6327 +10725 +4280 +4509 +10301 +5183 +5166 + +6068 +8243 +6171 +5575 +9093 +6123 +2831 +5664 +6278 + +4093 +4619 +2578 +5902 +1131 +3288 +4886 +4994 +6088 +6377 +1852 +4254 +1419 +1504 + +7127 +8649 +2523 +8023 +3063 +2677 +1759 +8632 +7805 +2999 + +3419 +1111 +5599 +1055 +3407 +4964 +3556 +7249 +1100 +7148 +1852 +1549 + +5414 +11474 +1685 +8818 +10288 +6138 +1983 + +23129 +2195 + +3104 +1599 +2327 +3640 +2230 +2791 +2344 +1035 +1046 +3399 +5096 +1067 +1987 +5786 +1395 + +32647 +10609 + +6020 +2279 +8718 +3103 +7022 +6464 +6180 +3968 +3275 + +3221 +5381 +6110 +1860 +4557 +4705 +3658 +4172 +5002 +5578 +1355 +4114 +3501 +4821 + +1312 +1921 +2644 +5044 +3336 +4520 +1253 +3184 +3732 +6754 +2139 +