diff --git a/aoc b/aoc new file mode 100755 index 0000000..9392077 --- /dev/null +++ b/aoc @@ -0,0 +1,9 @@ +#!/usr/bin/env zsh +setopt extendedglob + +cd "day$1" + +# Handle deno days +if [[ -n *.ts(#qN) ]]; then + deno eval --ext=ts "await import('./part$2.ts').then(m => m.solve()).then(s => console.log('The solution is', s))" +fi \ No newline at end of file diff --git a/day1/input.txt b/day1/input.txt deleted file mode 100644 index 1d943ca..0000000 --- a/day1/input.txt +++ /dev/null @@ -1,1000 +0,0 @@ -27484 55634 -67560 75018 -43926 95501 -86974 55714 -71747 78366 -28088 62509 -34772 15990 -29824 96324 -29947 57910 -98288 14717 -65056 92495 -51274 95004 -77249 83538 -47027 63476 -38391 61559 -70732 87324 -48005 31948 -78366 18349 -61139 70973 -73910 47466 -20206 14717 -22102 96393 -88580 13914 -54397 95954 -49998 14239 -61967 34634 -12345 14607 -41314 78200 -21798 23855 -98407 80316 -86141 19452 -73311 49491 -81862 87593 -95566 96160 -87351 52582 -15848 49491 -51788 65164 -35997 33641 -47658 55714 -81744 95501 -47851 18884 -43111 83702 -11414 70973 -40636 52220 -27695 93149 -81110 96694 -44831 48192 -58200 15065 -88294 41889 -16039 63631 -59282 62165 -69211 62894 -52748 27053 -52668 47769 -43520 76755 -28943 80470 -24548 55714 -67129 34601 -53243 55790 -65561 78366 -82182 95501 -49274 74658 -15952 33194 -60418 12345 -27775 46593 -73493 43900 -52098 95501 -27121 31096 -81056 12550 -28121 83702 -30348 52220 -56433 39771 -25161 81388 -83995 60545 -57450 58448 -52600 91287 -77850 36836 -37216 41677 -98526 41677 -90655 95125 -45217 42384 -69053 36037 -13539 17117 -89360 26136 -84311 49087 -87153 25849 -24300 76566 -23519 84695 -28852 42384 -53355 42384 -42582 47375 -26552 14607 -75913 44442 -53485 31831 -34601 42384 -76249 90670 -94920 28575 -72323 55714 -69403 83702 -95672 99168 -26935 30972 -87512 41677 -61615 46189 -74695 65158 -20200 84691 -19304 14239 -68077 52722 -10582 52930 -27335 49491 -37584 63132 -73196 54501 -16502 26753 -91474 69512 -54822 56271 -71321 89918 -41518 27775 -87096 95501 -21202 18798 -93142 56489 -38047 52220 -24517 96289 -44312 85343 -33144 41677 -77684 45037 -80588 14717 -67107 15065 -54896 28328 -51770 49491 -45857 46189 -46481 98951 -47496 99168 -28125 33812 -14980 41468 -51789 36618 -12986 27053 -25765 53516 -74251 12345 -78770 55714 -55011 12550 -29165 61671 -17728 27121 -33981 25499 -36823 91585 -39673 86789 -91903 32719 -19472 75443 -26800 98823 -37852 56489 -14040 10534 -55052 81862 -65668 21798 -89327 53241 -76888 55541 -70948 94956 -12472 29025 -14831 18426 -22665 35540 -22214 83730 -89577 78366 -81023 15782 -84429 46189 -75394 30972 -42076 37915 -68351 56261 -62000 83702 -17132 55865 -41051 15065 -76577 14898 -72700 62031 -21580 17436 -20635 61587 -62682 99808 -96847 51695 -79918 86863 -80975 14717 -72024 49491 -29236 66208 -82592 52603 -40379 26136 -22464 78366 -53246 78366 -92362 15065 -67933 96790 -83285 20525 -32355 46189 -72419 26136 -54766 27053 -44778 79069 -97706 14239 -14239 30166 -61196 80805 -49491 52600 -14607 56489 -54850 52600 -71449 56271 -27968 72844 -33242 79185 -44321 58952 -97596 10417 -82906 39771 -14319 76755 -46189 41677 -49649 30451 -24148 27053 -34109 27542 -81217 26136 -25414 30869 -75794 52220 -15200 34601 -95299 40426 -39732 95501 -87884 56489 -15317 14607 -21193 45220 -15090 54970 -21390 47973 -21698 96819 -56575 39771 -84593 52529 -83880 67718 -36664 17626 -42212 29641 -27053 62894 -84601 68684 -77818 89330 -44608 80231 -56932 44013 -93674 27002 -79048 58758 -88828 14239 -11883 94737 -36014 64083 -12590 56489 -76559 14717 -39043 14308 -82003 50086 -20407 11695 -10048 97014 -31281 56489 -28063 14607 -45813 20651 -18006 26237 -95040 39721 -62587 12345 -28094 39855 -29580 62165 -72853 56271 -39380 70973 -50190 84946 -86034 27121 -26295 33303 -22364 89399 -73757 35446 -45106 39771 -91186 49491 -30056 16061 -91866 44972 -89436 70973 -73210 98851 -62546 21798 -40469 71876 -55116 39771 -11849 25343 -77677 26646 -61244 28328 -26136 47460 -81481 96095 -72429 95501 -76056 43102 -35895 81862 -68089 70973 -18171 10254 -63514 47079 -97499 46286 -75403 42053 -36977 66988 -96237 27121 -29452 14239 -98034 62087 -42417 42384 -57358 96303 -60023 70973 -72118 21798 -85974 52179 -80417 48291 -13977 95222 -71082 81166 -44648 78723 -72171 22884 -70404 39721 -54381 22466 -72013 98147 -51192 41677 -14717 27121 -23855 76432 -48675 52568 -83605 56271 -31420 39046 -83753 82417 -10437 85385 -58483 41819 -69788 22488 -81921 76901 -56676 16456 -42129 70973 -21405 72092 -54273 69258 -63042 15363 -11660 33440 -64263 78366 -11027 45210 -47012 95501 -94401 24684 -27499 52220 -70973 77153 -47772 65651 -35646 22660 -16154 21798 -91790 46189 -50094 39771 -80579 12550 -49745 11236 -18137 39771 -79817 28328 -18437 34601 -46949 86449 -60816 14607 -35903 78067 -17915 83702 -57636 65003 -97265 11452 -54184 36155 -72211 25782 -50122 47994 -98895 41013 -83261 20279 -61814 34534 -41074 36291 -25545 85422 -69677 52406 -32198 70431 -90218 81862 -32063 64251 -26348 10652 -23459 14607 -19924 34601 -12755 49937 -75332 60524 -20426 52220 -33510 30972 -32520 12550 -50821 55735 -45619 34202 -30651 23203 -23288 68443 -26097 47344 -35967 99640 -13374 95501 -35414 42860 -67278 72844 -34100 78366 -26440 86108 -55848 60623 -60238 81862 -11578 44985 -53675 90447 -95139 81862 -53655 62281 -75061 94900 -25717 73969 -96718 42384 -60846 30964 -31991 28328 -41677 24873 -81456 52220 -62569 17266 -14572 74256 -47381 75269 -84958 52000 -85437 55316 -12693 33934 -56021 32349 -55744 36104 -68582 35349 -15330 58662 -94099 74304 -89771 38629 -52313 91593 -56489 36751 -50298 14607 -74104 30972 -29286 95154 -24482 52890 -82812 73820 -13182 48739 -15225 56489 -78417 14559 -83094 75319 -26751 52220 -92253 92873 -34340 21675 -73732 99240 -91045 78366 -52416 21810 -13671 28234 -33612 63254 -56971 78620 -40346 14469 -72844 42239 -94947 15446 -86520 52600 -75495 35748 -87108 76509 -61901 15436 -85022 76755 -51692 23336 -97087 12550 -17780 59480 -78024 78380 -82627 27053 -86867 57333 -14770 76094 -99690 91971 -37970 95357 -38091 81688 -93808 49007 -19623 75999 -62514 70973 -39354 66691 -18731 23385 -20182 14768 -96893 48182 -93703 90234 -32281 27775 -44738 57322 -34416 58353 -99168 14717 -60552 14239 -62143 34601 -34660 63426 -11505 83250 -24137 98026 -69957 63990 -32792 53572 -55146 25974 -24998 11925 -45008 72844 -55840 25161 -56271 73804 -51951 78366 -23366 79173 -94193 85825 -67623 15313 -35037 64946 -13330 52600 -31163 28328 -87613 70973 -40427 47478 -90416 95501 -81180 46847 -82377 30972 -64803 15065 -62137 76755 -28226 40028 -12419 81544 -14256 56271 -74284 56489 -63856 49491 -12114 42384 -23305 80995 -99115 65077 -38426 21798 -87398 52600 -92158 56086 -39006 62303 -17021 34601 -11701 27121 -31448 12345 -78513 48079 -85920 55714 -93843 56271 -30287 92370 -78384 23855 -41990 56271 -11317 33003 -30841 14239 -10135 21798 -85875 25747 -65006 60774 -19493 56489 -29916 52220 -12137 74754 -13493 14239 -36868 52600 -19718 41677 -73983 27775 -79278 20613 -70849 27053 -43543 49191 -69664 81862 -36211 80089 -69076 82040 -50555 34022 -16277 85672 -86854 14607 -18173 35936 -15367 11444 -87778 81574 -85537 55714 -29202 48397 -65597 74632 -94036 70973 -40995 29041 -57002 72844 -31037 96364 -62138 77922 -23493 35039 -32543 89711 -13649 14616 -45082 62165 -39931 65090 -54328 86139 -90435 46008 -98509 44592 -40846 62165 -12273 72080 -70078 27412 -69792 72844 -71552 42384 -43202 76147 -23140 21798 -26364 65427 -34210 99168 -47040 70973 -29563 70973 -35773 12443 -52323 51861 -37176 51073 -97815 30972 -43884 61678 -94682 91679 -82836 72844 -89878 24424 -39807 26674 -42368 70973 -13016 79932 -89249 37967 -65121 52600 -20487 99240 -24970 42384 -30802 56489 -65040 86672 -28328 62894 -52220 32030 -26818 52770 -65282 14717 -78164 11443 -46968 93881 -78981 80725 -18980 60551 -30648 49335 -51633 72639 -31442 62165 -63174 50347 -44998 39721 -60294 34601 -33509 52600 -28215 65043 -76076 78196 -64908 72844 -17601 36315 -33308 86175 -79813 43976 -89994 14239 -35315 42384 -67669 42384 -73099 92031 -25168 12345 -71490 10167 -58441 86468 -28299 60466 -64607 48514 -34983 11600 -96817 99168 -13045 49648 -71656 90046 -26886 28328 -60587 23855 -75130 15065 -86187 55320 -85198 76755 -33243 35621 -43027 56271 -38691 62908 -49403 32551 -45353 26068 -18425 49491 -18026 65599 -39076 14316 -28212 85487 -18907 54021 -71135 42384 -13958 12513 -53937 52594 -12712 19297 -63297 32234 -50764 31236 -95321 94041 -97757 21838 -72342 37352 -62894 14717 -71239 78366 -77659 96018 -63198 97837 -84364 19753 -61075 62165 -51222 70973 -24995 44001 -16599 41677 -86925 21798 -99048 64924 -13542 43682 -12591 34601 -25905 70973 -32208 34954 -22133 23030 -41575 28240 -59604 56374 -16836 95558 -31682 81033 -69364 30518 -82188 70973 -41914 62165 -45576 15065 -25079 64408 -81537 28328 -46462 34601 -66551 66708 -26591 27053 -77328 39771 -33985 34601 -33418 34601 -91080 82492 -61568 42887 -57867 74914 -84472 28817 -12654 85938 -70565 40779 -42550 78366 -51259 32921 -13169 59335 -65905 99168 -15805 12345 -90109 34718 -76980 82815 -57913 76636 -72381 30945 -70281 34601 -78134 37240 -37955 81295 -93173 33484 -74086 67805 -58167 49073 -40765 80068 -23790 18371 -33592 17145 -78454 80589 -15430 90417 -67945 94168 -64241 39721 -83702 93602 -46375 21798 -26342 46958 -34863 41677 -19482 95501 -34284 35957 -38000 37717 -98157 49491 -15930 52600 -64693 52600 -12550 89557 -51953 21798 -77269 61755 -13652 15065 -86840 26806 -52314 98399 -98333 81977 -40687 56489 -35046 65010 -59975 62507 -72833 24038 -14044 34601 -71828 34601 -40577 40279 -51481 76591 -80118 21709 -55714 52220 -24410 59302 -99412 94355 -35437 38777 -48548 75281 -84964 25359 -75235 47933 -21303 61504 -83551 28328 -52760 23895 -85000 12345 -56259 27053 -42764 49491 -11312 27053 -24461 46255 -27237 56271 -58802 96584 -55301 52220 -74259 14607 -56046 33277 -19866 75075 -73679 72844 -33891 70345 -45639 56271 -54195 23454 -95097 30972 -57914 29726 -59298 51050 -89370 21638 -76504 78721 -56108 27053 -29130 52600 -33712 55714 -25154 39018 -96503 95501 -98909 52220 -40872 43009 -82776 25161 -63510 34743 -26533 41677 -56079 42554 -39398 28328 -47768 29475 -20341 63539 -99994 66314 -10110 52220 -57700 30972 -30209 18563 -94995 51083 -44918 49491 -66796 81231 -51995 27053 -77354 77076 -93013 11025 -54620 14607 -92444 97003 -93849 95582 -49161 37280 -28949 27053 -37715 56489 -23904 95501 -73156 31922 -42384 62165 -17773 83547 -58155 64695 -54490 41677 -56486 95501 -97223 42384 -32955 28233 -25281 32491 -15737 61928 -35697 87569 -18244 21823 -42515 15065 -40947 14886 -93475 32452 -14131 27775 -67547 56489 -95089 27728 -43557 26309 -11037 53226 -34322 15776 -22250 98902 -71266 70973 -89572 87812 -90169 84461 -17372 14607 -65790 34601 -27576 83702 -37101 90585 -73468 52600 -39721 67883 -65682 78366 -47073 30972 -90895 18187 -43637 60451 -78516 28328 -21073 62894 -92011 18396 -46069 30730 -26851 52072 -47448 71619 -65439 52600 -29023 52220 -51855 41677 -65553 25161 -80536 65615 -16678 56489 -90651 70973 -19633 34601 -93746 80330 -70591 52600 -94422 96655 -33657 77648 -52974 25161 -13630 51573 -69196 94233 -79490 56271 -32250 81862 -66530 60802 -32790 54374 -17127 34741 -92015 62894 -28249 55714 -65102 52600 -91455 20887 -64033 28328 -24017 56271 -45651 14607 -60117 86054 -96785 27053 -50649 95501 -15436 22503 -65914 69007 -36166 56271 -78692 67504 -91558 15065 -49051 73240 -66543 55714 -95701 85539 -38010 18771 -45785 95501 -64305 84004 -47125 66585 -66807 64152 -53798 26097 -39771 71764 -31704 30702 -62165 37200 -65163 52600 -29324 29029 -60646 39771 -91668 65672 -70470 15065 -49620 14247 -73173 18620 -50390 36512 -89026 99202 -81234 82629 -45456 62894 -39896 27600 -56209 95501 -48104 40539 -62372 99003 -39333 56271 -79867 72035 -95279 47366 -52605 28328 -75787 88930 -84796 49491 -38805 27053 -45963 11986 -27579 34906 -90333 76755 -32386 99055 -14026 43550 -19291 72844 -77541 70973 -99587 55340 -31439 95942 -42133 16863 -44755 99168 -85828 46189 -42114 40119 -59161 91883 -43113 52600 -19801 59337 -99100 42384 -65884 14239 -54308 26731 -65747 22856 -29500 78366 -41826 25161 -85615 62894 -70557 28328 -95815 45495 -87262 70230 -83658 88861 -81087 95501 -90172 15065 -89905 83702 -76914 99725 -97931 27736 -33944 78366 -12857 13437 -31425 18052 -47737 52600 -54370 88914 -30972 52220 -95939 93458 -65658 14144 -56393 13271 -19853 65648 -88897 76222 -82340 34601 -84119 49301 -56333 76755 -63170 41677 -46323 41823 -25888 46298 -93367 11280 -63331 44705 -16400 60268 -54046 56271 -47922 97212 -32747 76755 -29791 21741 -71231 42384 -57799 52220 -89922 16019 -58351 15436 -49144 46189 -44735 27121 -48818 49491 -73875 56271 -88792 56489 -95437 24568 -16461 39771 -47343 31753 -12386 76932 -91444 37078 -89445 12345 -24720 27053 -76245 67447 -53193 52600 -81174 78366 -62085 31757 -63488 42384 -25099 34473 -45860 46189 -59677 27053 -85517 52654 -38418 98942 -95501 24726 -21940 98584 -88869 11941 -15733 45484 -28860 21798 -65805 78366 -92611 30972 -73443 30972 -68225 77281 -59098 74187 -94473 49491 -45560 34601 -14714 47592 -72384 41677 -16713 14239 -59990 69119 -10894 76150 -32150 12345 -91101 92795 -87562 14607 -86572 57058 -15065 19835 -83303 56887 -96607 49491 -36622 76755 -52276 25566 -99240 99330 -46404 52220 -62733 83417 -67070 28328 -36323 76755 -14422 29889 -76755 52600 -76212 77863 -68464 62165 -69048 21798 -78830 89470 -92884 52220 -73029 72758 -73783 30562 -20321 27053 -23224 54765 -16276 28328 -10461 36193 -17913 18463 -28947 27143 -23436 56489 -18265 42384 -72046 30416 -61316 42384 -70861 52220 \ No newline at end of file diff --git a/day1/part1.ts b/day1/part1.ts index 8993ac6..d91ca53 100644 --- a/day1/part1.ts +++ b/day1/part1.ts @@ -1,16 +1,18 @@ -const input = await Deno.readTextFile("./input.txt").then( - (f) => - f.split("\n").reduce<[number[], number[]]>( - ( - acc, - cur, - ) => [[...acc[0], +cur.split(" ")[0]], [ - ...acc[1], - +cur.split(" ")[1], - ]], - [[], []], - ), -).then(([first, second]) => [first.toSorted(), second.toSorted()]).then(( - [first, second], -) => first.reduce((acc, cur, i) => acc + Math.abs(cur - second[i]), 0)); -console.log("Answer = " + input); +export async function solve() { + return await Deno.readTextFile("./input.txt").then( + (f) => + f.split("\n").reduce<[number[], number[]]>( + ( + acc, + cur, + ) => [ + [...acc[0], +cur.split(" ")[0]], + [...acc[1], +cur.split(" ")[1]], + ], + [[], []], + ), + ).then(([first, second]) => [first.toSorted(), second.toSorted()]).then( + ([first, second]) => + first.reduce((acc, cur, i) => acc + Math.abs(cur - second[i]), 0), + ); +} diff --git a/day1/part2.ts b/day1/part2.ts index 39446c3..cd21658 100644 --- a/day1/part2.ts +++ b/day1/part2.ts @@ -1,24 +1,25 @@ -const input = await Deno.readTextFile("./input.txt").then( - (f) => - f.split("\n").reduce<[number[], number[]]>( - ( - acc, - cur, - ) => [[...acc[0], +cur.split(" ")[0]], [ - ...acc[1], - +cur.split(" ")[1], - ]], - [[], []], - ), -).then(([first, second]) => [ - first, - second.reduce((acc, cur) => { - if (acc[cur] !== undefined) acc[cur]++; - else acc[cur] = 1; +export async function solve() { + return await Deno.readTextFile("./input.txt").then( + (f) => + f.split("\n").reduce<[number[], number[]]>( + ( + acc, + cur, + ) => [ + [...acc[0], +cur.split(" ")[0]], + [...acc[1], +cur.split(" ")[1]], + ], + [[], []], + ), + ).then(([first, second]) => [ + first, + second.reduce((acc, cur) => { + if (acc[cur] !== undefined) acc[cur]++; + else acc[cur] = 1; - return acc; - }, {} as Record), -]).then(([first, map]) => - first.reduce((acc, cur) => acc + ((map[cur] ?? 0) * cur), 0) -); -console.log("Answer = " + input); + return acc; + }, {} as Record), + ] as const).then(([first, map]) => + first.reduce((acc, cur) => acc + ((map[cur] ?? 0) * cur), 0) + ); +}