From feaea693afbbf6a14a1b74a8bc83da1801a697c1 Mon Sep 17 00:00:00 2001 From: godu Date: Mon, 2 Dec 2024 21:18:55 +0100 Subject: [PATCH] Year2024.Day01 --- .github/workflows/ci.yml | 36 +- app/Inputs/Year2024/Day01.txt | 1000 +++++++++++++++++++++++ app/Inputs/Year2024/DayXX.txt | 0 app/Year2024.hs | 162 ++++ hie.yaml | 24 + package.yaml | 11 + src/AdventOfCode/Year2023/Day03.hs | 9 +- src/AdventOfCode/Year2024/Day01.hs | 40 + src/AdventOfCode/Year2024/DayXX.hs | 17 + stack.yaml | 2 +- stack.yaml.lock | 8 +- test/AdventOfCode/Year2024/Day01Spec.hs | 42 + test/AdventOfCode/Year2024/DayXXSpec.hs | 22 + 13 files changed, 1346 insertions(+), 27 deletions(-) create mode 100644 app/Inputs/Year2024/Day01.txt create mode 100644 app/Inputs/Year2024/DayXX.txt create mode 100644 app/Year2024.hs create mode 100644 src/AdventOfCode/Year2024/Day01.hs create mode 100644 src/AdventOfCode/Year2024/DayXX.hs create mode 100644 test/AdventOfCode/Year2024/Day01Spec.hs create mode 100644 test/AdventOfCode/Year2024/DayXXSpec.hs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 61acf1e..fce627a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,15 +4,15 @@ on: [push] jobs: lint: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout source 📡 - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: 'Install HLint 📡' uses: haskell-actions/hlint-setup@v2 with: - version: '3.6.1' + version: '3.8' - name: 'Run HLint 📝' uses: haskell-actions/hlint-run@v2 @@ -21,31 +21,31 @@ jobs: fail-on: warning style: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout source 📡 - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Styling 💅 - uses: haskell-actions/run-ormolu@v14 + uses: haskell-actions/run-ormolu@v16 with: - version: '0.7.3.0' + version: '0.7.7.0' test: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout source 📡 - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Cache ~/.stack 📦 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.stack key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }} restore-keys: | ${{ runner.os }}-stack-global- - name: Cache .stack-work 📦 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: .stack-work key: ${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('**/*.hs') }} @@ -55,7 +55,7 @@ jobs: - name: Install Stack 📡 uses: haskell-actions/setup@v2 with: - ghc-version: 9.4.7 + ghc-version: 9.6.6 enable-stack: true stack-version: "latest" @@ -67,23 +67,23 @@ jobs: run: needs: [lint, style, test] - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 strategy: matrix: - year: [2023, 2021, 2020] + year: [2024, 2023, 2021, 2020] steps: - name: Checkout source 📡 - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Cache ~/.stack 📦 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.stack key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }} restore-keys: | ${{ runner.os }}-stack-global- - name: Cache .stack-work 📦 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: .stack-work key: ${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('**/*.hs') }} @@ -93,7 +93,7 @@ jobs: - name: Install Stack 📡 uses: haskell-actions/setup@v2 with: - ghc-version: 9.4.7 + ghc-version: 9.6.6 enable-stack: true stack-version: "latest" diff --git a/app/Inputs/Year2024/Day01.txt b/app/Inputs/Year2024/Day01.txt new file mode 100644 index 0000000..e4fcaaa --- /dev/null +++ b/app/Inputs/Year2024/Day01.txt @@ -0,0 +1,1000 @@ +80784 47731 +81682 36089 +22289 41038 +79525 17481 +62156 70590 +87975 21561 +54635 59542 +43393 99451 +45310 59542 +18324 92078 +36887 79481 +35723 48782 +78420 35875 +93307 52649 +77342 80601 +69125 47895 +37292 20025 +45553 59542 +27412 30010 +67708 70822 +92078 91109 +48367 87581 +26852 30538 +42123 17859 +20067 87581 +20239 32262 +50660 73585 +46240 45533 +29502 46131 +77080 36089 +64180 14043 +74942 72085 +73979 22860 +47999 41397 +36014 35101 +39827 32262 +81418 86581 +47467 14538 +65923 46584 +95054 17500 +59680 37730 +94609 19539 +33451 39467 +69173 12422 +31769 34255 +85180 29056 +82104 52296 +90955 38171 +83927 70590 +59455 17306 +28681 86581 +54107 13789 +79824 21386 +53890 46519 +94883 87581 +12797 46584 +66809 24306 +78327 24086 +19780 43234 +55623 38171 +10937 42288 +24262 74556 +92076 77080 +69179 15029 +13764 52214 +92187 63803 +91328 94609 +24356 36089 +82974 84225 +55924 70822 +65439 55383 +78097 82069 +58045 12422 +72087 37730 +70822 32262 +78511 48368 +39251 54157 +74623 59542 +32104 74623 +69499 17481 +97919 33260 +37778 74623 +56977 14684 +19100 98708 +29453 34463 +18839 87581 +75434 75839 +58303 84225 +84924 24108 +99813 37730 +99218 93749 +54262 38470 +61773 94274 +67034 56935 +71788 74556 +83455 22604 +76089 84225 +11003 85999 +80814 62471 +41928 56000 +52541 71034 +37488 53519 +78475 33260 +57117 32449 +54543 54732 +19050 52775 +80967 76950 +71045 29497 +61189 43136 +75055 38171 +91573 46131 +50100 70590 +46554 24973 +25154 99579 +19853 77080 +11807 20266 +40158 24315 +92543 38171 +93300 87581 +79628 68978 +19164 51702 +53719 96515 +38074 46503 +25693 53188 +79321 17481 +25108 21108 +38398 72487 +22073 59542 +98191 39605 +80619 66029 +99138 74556 +49897 33260 +84225 10112 +14331 66948 +94603 36089 +33642 75862 +14314 89669 +12998 48362 +10989 21312 +68074 46131 +10531 47636 +32312 70590 +66844 38171 +73563 77034 +33099 65439 +93734 71747 +56538 35101 +55501 82069 +19974 94609 +21308 23592 +37062 36089 +99908 59542 +92651 94321 +81371 84225 +96268 35101 +58685 25444 +37191 86819 +71956 87899 +28341 70822 +11995 64983 +92426 70590 +30515 57117 +72193 37685 +82150 77080 +19292 73860 +52076 53020 +26135 78522 +49482 79269 +56103 81747 +62006 66781 +41905 24906 +23782 10112 +39865 41627 +80074 91781 +84213 70822 +19586 43155 +87133 70822 +67811 65439 +60019 23478 +29057 70590 +77349 16491 +32372 13789 +93055 65439 +82209 30330 +75731 60775 +91276 79848 +90330 37730 +41180 59542 +81204 95937 +36092 11620 +13033 38171 +34488 51306 +71770 81668 +37630 57117 +87608 69809 +90593 59542 +52792 39467 +33508 46226 +78150 29434 +18072 84225 +11205 63803 +28801 39467 +89617 47552 +91269 77080 +50829 15405 +96387 68582 +44407 46131 +17491 74556 +77464 57117 +67053 71830 +67048 20722 +15369 76996 +71812 74803 +96980 35466 +39993 82069 +65498 59148 +88138 79430 +16497 54357 +75624 46131 +84028 39464 +82572 39122 +14297 36089 +33805 85723 +44778 74556 +14498 87581 +71384 17116 +47173 82069 +60652 82069 +67241 46316 +73276 80192 +46786 68313 +88795 97650 +95120 23939 +53010 82069 +40256 82069 +26913 71782 +44746 88309 +49866 86581 +50951 97892 +80832 30492 +22643 70822 +84334 86581 +96028 70590 +39816 56848 +78427 63379 +27147 92078 +35658 12422 +76747 47552 +32896 59542 +98898 12422 +45166 37081 +38602 27009 +17507 82069 +75567 74623 +71921 29970 +11800 90710 +23973 68582 +80315 68252 +86659 13782 +23014 71633 +33041 57117 +93351 65439 +69088 46584 +71994 91050 +61532 98835 +98790 76392 +62890 75035 +37723 36089 +56136 20455 +91663 84225 +76413 87581 +89223 11659 +33477 47973 +34541 16506 +82603 59542 +37730 75791 +25272 98835 +86703 82248 +56755 54948 +74556 92078 +11337 36089 +52534 27174 +60327 87581 +84554 89264 +11381 59542 +99601 81999 +20139 33278 +25530 59558 +97414 74906 +11269 70822 +66500 13789 +23195 68582 +22872 53300 +94937 51202 +12273 55687 +63364 71074 +14160 15554 +57473 39467 +19091 87899 +43286 16810 +25975 33571 +57319 39467 +61075 66766 +95980 98826 +47190 55086 +82297 87581 +24071 53175 +85766 82069 +48467 36089 +16301 77080 +89176 48368 +76512 29182 +61987 37730 +10252 83226 +42503 12203 +75498 71010 +56685 98679 +22338 48368 +40666 86581 +88276 32262 +69493 94854 +75435 22046 +91561 48368 +99202 42878 +90978 38171 +89712 77080 +48877 36148 +31528 92078 +15135 36258 +47468 10112 +23557 10112 +46381 98492 +95007 57390 +31053 95937 +26099 27278 +34939 75494 +44252 59542 +54945 73875 +26328 38171 +73116 46131 +16168 13789 +28518 28323 +25310 28056 +63436 27589 +77562 37730 +80614 82409 +76421 63235 +24521 53590 +17937 86492 +80687 56569 +56076 10767 +64810 74623 +73278 26540 +58083 46584 +90208 32262 +17793 65461 +92155 47552 +47982 91242 +82069 77080 +39226 87581 +34622 42348 +99735 46584 +22264 37730 +46131 70590 +90426 18162 +75148 63803 +98835 70822 +80373 30652 +62705 46131 +95974 32262 +54882 36453 +50578 71111 +30132 39798 +22527 35101 +41027 91852 +69013 46238 +79152 69190 +89330 61021 +85358 13789 +15086 54357 +50002 39467 +42579 42483 +11717 87581 +43825 24664 +50771 87581 +89105 45839 +84561 92078 +42692 38899 +20001 94609 +40205 38051 +13295 20519 +96020 10112 +47293 87899 +94929 10112 +24422 82448 +62066 59975 +52303 86581 +79329 72343 +69417 16516 +13062 47552 +41201 84658 +92635 62180 +19834 91848 +34343 18222 +18208 30134 +82611 63803 +12207 74511 +93804 53502 +51066 33260 +28374 66275 +34107 10112 +13223 80233 +97959 94470 +51054 57117 +82951 30540 +61626 32898 +52816 16045 +67095 46131 +96825 70590 +34307 77500 +98853 35083 +76437 65439 +71489 77080 +46520 16597 +15288 54357 +34660 63199 +65053 65439 +99414 57117 +85660 83055 +10245 32262 +12775 67705 +57298 65439 +64105 36878 +36104 12422 +89241 56000 +41045 87764 +16506 88026 +53044 44649 +17425 84939 +56000 69714 +63575 92078 +50418 19328 +39915 10112 +97542 66182 +97468 16506 +74779 94609 +90120 17677 +91404 87581 +83440 31253 +80583 16585 +16542 82069 +34305 48368 +95455 30383 +56639 87581 +33983 12422 +36565 47552 +63737 32262 +60378 37730 +80067 95189 +45068 61725 +20720 74180 +24918 94609 +18264 86581 +43293 57117 +67279 38551 +75286 95937 +19582 71378 +62806 12497 +48345 96497 +45026 68499 +97371 36028 +80754 74761 +97543 54357 +51110 12422 +23427 24635 +44698 68582 +84624 28102 +74813 12960 +94691 82069 +68498 93943 +30492 52810 +65243 34777 +12244 82069 +14525 65439 +75430 98694 +73494 87567 +97587 67336 +59739 59542 +38047 30492 +35519 43518 +64167 92078 +52460 72101 +49707 81573 +86581 24885 +93340 69244 +91249 13789 +35632 52637 +78007 56318 +86640 46131 +84853 30492 +69589 55403 +87840 94609 +15931 65439 +87788 94609 +36704 39467 +56849 92199 +23845 70822 +58771 59306 +15094 72864 +78669 38116 +67290 30492 +30809 12422 +60616 82069 +99946 86597 +57245 10112 +14346 59022 +95083 79436 +57974 65334 +22448 86581 +89557 42455 +72735 70224 +80323 28694 +19558 59542 +66100 67968 +29557 54357 +75549 48368 +47979 65120 +81370 26550 +99542 80446 +92151 48368 +60693 60658 +70590 36856 +93811 95439 +50263 78334 +51728 74556 +48629 23585 +63500 35242 +98688 74623 +50638 39467 +39320 57117 +85601 48368 +86749 63803 +84452 24596 +40346 33260 +56693 59543 +96450 10429 +46319 50421 +88183 63450 +47057 56000 +99066 65734 +95736 95937 +49970 77187 +76310 86581 +72960 21713 +61234 33798 +20364 70590 +89304 82069 +90141 11734 +11708 88748 +67064 10112 +51923 71970 +47055 36089 +45990 28498 +89727 87581 +92801 71911 +39807 46584 +72390 35136 +16446 62868 +77863 56000 +42686 13789 +28678 75289 +84858 67442 +64404 84225 +77138 70822 +48368 33260 +89589 10112 +92469 43286 +66906 19599 +96794 74623 +98997 15262 +32791 74556 +86217 36089 +23368 31640 +88661 19276 +72933 85540 +22703 30492 +71905 65439 +58050 40461 +29588 95734 +39243 55933 +83527 17481 +15249 58026 +77033 47662 +47552 86581 +57262 69752 +20061 18772 +81279 43751 +58632 70157 +13683 94609 +21964 74556 +95224 59604 +83465 88283 +81225 36089 +16585 17481 +15766 15653 +50261 57292 +82233 54937 +60140 94609 +52750 31767 +20808 56000 +57243 92469 +43252 32262 +60198 86581 +18620 55678 +44051 50219 +15210 39162 +60005 36089 +66217 74556 +13853 70822 +63803 70822 +35040 65079 +65842 38038 +39316 20720 +87663 65984 +20060 68582 +25890 48796 +16116 82639 +31571 70822 +43980 84152 +53704 11951 +79055 42179 +57231 22127 +88376 85408 +59541 95959 +92556 53432 +88194 16317 +34727 30904 +16387 57117 +96730 10644 +65083 36089 +15228 16506 +81423 59542 +87899 17481 +90911 85798 +17159 83599 +50392 77080 +22864 43286 +37528 94609 +21429 59542 +28265 46877 +46764 37608 +91323 65439 +83391 35269 +74503 39369 +93683 63803 +31047 38528 +53705 33260 +74884 86581 +54241 99733 +45641 73338 +64783 94609 +36885 76835 +94878 70590 +95560 21274 +61985 67119 +65075 74623 +32813 86204 +36749 72304 +78654 50542 +86690 74556 +70019 32262 +20641 60329 +77752 57117 +60383 20123 +90352 74623 +24141 71761 +65390 10350 +47054 38708 +39003 57915 +38161 92078 +38171 32262 +84400 10112 +15341 70822 +39428 16506 +13942 13789 +96936 70483 +93060 50175 +38192 67104 +46944 64882 +10846 12422 +35101 35801 +91104 20720 +13040 13789 +32161 31456 +97253 86581 +70362 70590 +53579 26550 +32295 56680 +77624 74556 +19453 38171 +11458 82069 +39312 94596 +68109 81118 +63009 59542 +96761 33260 +42532 96201 +42166 87800 +87613 44967 +69532 34024 +48387 83207 +54987 28919 +20342 84225 +23664 56000 +46174 10112 +72309 12474 +72157 73250 +28932 14632 +36882 84225 +23261 38171 +99849 41962 +95036 44159 +67696 12422 +58158 12422 +99688 84696 +95937 56267 +67472 28880 +32262 78595 +39793 31505 +53311 87581 +28411 51506 +53156 88986 +97772 95152 +27795 70590 +25013 30223 +14528 72611 +76358 11601 +46584 32226 +45091 53888 +78740 82069 +28185 56000 +86150 33260 +12422 13789 +49946 36089 +39558 91418 +12969 78072 +30758 23674 +30625 72335 +29062 46065 +51088 61952 +88725 61869 +94002 74556 +35800 29768 +43599 95937 +65922 82638 +52159 91936 +96552 48368 +29575 38995 +51418 82069 +39467 36420 +76259 15058 +52506 24873 +34793 68305 +36089 94116 +25337 69496 +46924 86581 +62992 82069 +62236 95937 +50926 25384 +72595 74556 +53666 67031 +44374 15724 +44629 51188 +80493 95937 +76680 59202 +96833 95937 +96740 86581 +90400 65439 +41922 10112 +10333 23762 +13789 94609 +79941 85091 +34855 55865 +87532 37140 +85678 46584 +34735 74556 +27059 28517 +62170 92078 +59542 84972 +44107 46131 +62531 86581 +36662 56000 +36292 59542 +76115 57037 +39296 41740 +34919 10743 +74948 86439 +50539 59294 +85056 31471 +28116 65439 +39085 38176 +84409 95937 +57138 46131 +72483 57117 +32395 72441 +95005 74883 +87581 51660 +28602 28664 +34996 46131 +96430 56339 +77226 70822 +93760 10112 +40364 94609 +40141 39467 +68490 40042 +48192 93216 +68068 70590 +73633 15355 +83619 47552 +81572 73873 +25924 70822 +29554 63803 +19515 26687 +61203 65439 +66108 77080 +34039 33260 +54877 35542 +38583 96489 +90667 42450 +84938 10487 +46965 59542 +54823 74069 +71321 73685 +19154 57117 +73217 30492 +76105 13647 +39670 12422 +30004 64951 +21400 16931 +58732 46131 +46185 57117 +35140 97447 +21937 32262 +29766 37730 +97110 17481 +37622 70822 +10481 46131 +89082 37730 +37941 74556 +14004 13789 +75256 31754 +91586 98835 +70127 84728 +27519 76800 +30742 29667 +40956 72181 +38337 85286 +93338 32262 +17167 48368 +90586 87581 +77695 72650 +78449 10112 +14007 92469 +44816 56000 +92128 12422 +70434 89508 +46495 17481 +86412 57117 +12915 29947 +31239 98835 +25873 62842 +18560 54357 +56101 27741 +85775 70590 +36475 51980 +80038 10112 +98826 30492 +41315 82816 +11389 82624 +11947 75881 +26407 10112 +30869 41026 +87026 44676 +41060 77177 +27239 32212 +50309 47552 +28120 35101 +52772 87899 +50851 13789 +52738 67642 +73374 61276 +29063 83110 +75283 77080 +91345 33260 +14809 19229 +82519 27777 +92688 65439 +10526 48368 +59702 92469 +35688 48965 +87590 24828 +40206 75331 +36194 74556 +43336 12746 +26034 29117 +23466 47552 +33234 19772 +17481 11383 +68582 54357 +36038 20809 +33704 98835 +87642 46131 +37947 38171 +17577 54357 +13994 48368 +70913 45734 +11985 23504 +82269 84225 +83126 70590 +47981 50609 +71785 10112 +38305 87857 +59774 78056 +62970 82069 +21547 84225 +63443 87640 +74676 92894 +54357 35752 +88456 38171 +80643 40334 +78727 73557 +86551 13789 +31360 70822 +38144 12422 +39925 26550 +18733 67964 +14557 23598 +68231 70590 +28923 37251 +36731 36089 +16989 57160 +10112 90976 +81269 32323 +46176 11467 +34165 74556 +30496 32262 +33260 70590 +91319 45070 +80484 38171 +61567 48368 +36103 70590 +45693 70590 +41025 43757 +36802 65596 +21523 98958 +80599 32262 +49397 92078 +74366 65439 +30292 94948 +20673 10112 +13158 46131 +89970 26550 +70825 12276 +96736 32750 +26698 17481 +94201 26049 +66228 18185 +50623 91018 +63509 70822 +96572 46131 +34380 46715 +21120 17481 +24159 56000 +59659 74556 +31572 53951 +48375 82069 +12985 36089 +82040 10557 +63252 57117 +31520 86581 +38262 13789 +41980 40901 +76273 47552 +11812 46131 +28759 77080 +12882 92653 +64935 33260 +26550 83813 +19156 58394 +93914 35101 +43129 96976 +13090 57117 +98463 76524 +36993 46131 +89249 35207 +12936 18458 +26497 56000 +75288 35237 +79742 82354 +65715 12422 +21544 29737 diff --git a/app/Inputs/Year2024/DayXX.txt b/app/Inputs/Year2024/DayXX.txt new file mode 100644 index 0000000..e69de29 diff --git a/app/Year2024.hs b/app/Year2024.hs new file mode 100644 index 0000000..806ee0c --- /dev/null +++ b/app/Year2024.hs @@ -0,0 +1,162 @@ +module Year2024 + ( main, + ) +where + +import qualified AdventOfCode.Year2024.Day01 as Day01 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day02 as Day02 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day03 as Day03 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day04 as Day04 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day05 as Day05 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day06 as Day06 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day07 as Day07 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day08 as Day08 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day09 as Day09 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day10 as Day10 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day11 as Day11 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day12 as Day12 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day13 as Day13 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day14 as Day14 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day15 as Day15 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day16 as Day16 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day17 as Day17 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day18 as Day18 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day19 as Day19 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day20 as Day20 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day21 as Day21 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day22 as Day22 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day23 as Day23 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day24 as Day24 (run1, run2) +-- import qualified AdventOfCode.Year2024.Day25 as Day25 (run1) +import qualified AdventOfCode.Year2024.DayXX as DayXX (run1, run2) + +main :: IO () +main = do + putStrLn "Day01" + fixture <- readFile "app/Inputs/Year2024/Day01.txt" + putStrLn $ "Result #1: " <> Day01.run1 fixture + putStrLn $ "Result #2: " <> Day01.run2 fixture + + -- putStrLn "Day02" + -- fixture <- readFile "app/Inputs/Year2024/Day02.txt" + -- putStrLn $ "Result #1: " <> Day02.run1 fixture + -- putStrLn $ "Result #2: " <> Day02.run2 fixture + + -- putStrLn "Day03" + -- fixture <- readFile "app/Inputs/Year2024/Day03.txt" + -- putStrLn $ "Result #1: " <> Day03.run1 fixture + -- putStrLn $ "Result #2: " <> Day03.run2 fixture + + -- putStrLn "Day04" + -- fixture <- readFile "app/Inputs/Year2024/Day04.txt" + -- putStrLn $ "Result #1: " <> Day04.run1 fixture + -- putStrLn $ "Result #2: " <> Day04.run2 fixture + + -- putStrLn "Day05" + -- fixture <- readFile "app/Inputs/Year2024/Day05.txt" + -- putStrLn $ "Result #1: " <> Day05.run1 fixture + -- putStrLn $ "Result #2: " <> Day05.run2 fixture + + -- putStrLn "Day06" + -- fixture <- readFile "app/Inputs/Year2024/Day06.txt" + -- putStrLn $ "Result #1: " <> Day06.run1 fixture + -- putStrLn $ "Result #2: " <> Day06.run2 fixture + + -- putStrLn "Day07" + -- fixture <- readFile "app/Inputs/Year2024/Day07.txt" + -- putStrLn $ "Result #1: " <> Day07.run1 fixture + -- putStrLn $ "Result #2: " <> Day07.run2 fixture + + -- putStrLn "Day08" + -- fixture <- readFile "app/Inputs/Year2024/Day08.txt" + -- putStrLn $ "Result #1: " <> Day08.run1 fixture + -- putStrLn $ "Result #2: " <> Day08.run2 fixture + + -- putStrLn "Day09" + -- fixture <- readFile "app/Inputs/Year2024/Day09.txt" + -- putStrLn $ "Result #1: " <> Day09.run1 fixture + -- putStrLn $ "Result #2: " <> Day09.run2 fixture + + -- putStrLn "Day10" + -- fixture <- readFile "app/Inputs/Year2024/Day10.txt" + -- putStrLn $ "Result #1: " <> Day10.run1 fixture + -- putStrLn $ "Result #2: " <> Day10.run2 fixture + + -- putStrLn "Day11" + -- fixture <- readFile "app/Inputs/Year2024/Day11.txt" + -- putStrLn $ "Result #1: " <> Day11.run1 fixture + -- putStrLn $ "Result #2: " <> Day11.run2 fixture + + -- putStrLn "Day12" + -- fixture <- readFile "app/Inputs/Year2024/Day12.txt" + -- putStrLn $ "Result #1: " <> Day12.run1 fixture + -- putStrLn $ "Result #2: " <> Day12.run2 fixture + + -- putStrLn "Day13" + -- fixture <- readFile "app/Inputs/Year2024/Day13.txt" + -- putStrLn $ "Result #1: " <> Day13.run1 fixture + -- putStrLn $ "Result #2: \n" <> Day13.run2 fixture + + -- putStrLn "Day14" + -- fixture <- readFile "app/Inputs/Year2024/Day14.txt" + -- putStrLn $ "Result #1: " <> Day14.run1 fixture + -- putStrLn $ "Result #2: " <> Day14.run2 fixture + + -- putStrLn "Day15" + -- fixture <- readFile "app/Inputs/Year2024/Day15.txt" + -- putStrLn $ "Result #1: " <> Day15.run1 fixture + -- putStrLn $ "Result #2: " <> Day15.run2 fixture + + -- putStrLn "Day16" + -- fixture <- readFile "app/Inputs/Year2024/Day16.txt" + -- putStrLn $ "Result #1: " <> Day16.run1 fixture + -- putStrLn $ "Result #2: " <> Day16.run2 fixture + + -- putStrLn "Day17" + -- fixture <- readFile "app/Inputs/Year2024/Day17.txt" + -- putStrLn $ "Result #1: " <> Day17.run1 fixture + -- putStrLn $ "Result #2: " <> Day17.run2 fixture + + -- putStrLn "Day18" + -- fixture <- readFile "app/Inputs/Year2024/Day18.txt" + -- putStrLn $ "Result #1: " <> Day18.run1 fixture + -- putStrLn $ "Result #2: " <> Day18.run2 fixture + + -- putStrLn "Day19" + -- fixture <- readFile "app/Inputs/Year2024/Day19.txt" + -- putStrLn $ "Result #1: " <> Day19.run1 fixture + -- putStrLn $ "Result #2: " <> Day19.run2 fixture + + -- putStrLn "Day20" + -- fixture <- readFile "app/Inputs/Year2024/Day20.txt" + -- putStrLn $ "Result #1: " <> Day20.run1 fixture + -- putStrLn $ "Result #2: " <> Day20.run2 fixture + + -- putStrLn "Day21" + -- fixture <- readFile "app/Inputs/Year2024/Day21.txt" + -- putStrLn $ "Result #1: " <> Day21.run1 fixture + -- putStrLn $ "Result #2: " <> Day21.run2 fixture + + -- putStrLn "Day22" + -- fixture <- readFile "app/Inputs/Year2024/Day22.txt" + -- putStrLn $ "Result #1: " <> Day22.run1 fixture + -- putStrLn $ "Result #2: " <> Day22.run2 fixture + + -- putStrLn "Day23" + -- fixture <- readFile "app/Inputs/Year2024/Day23.txt" + -- putStrLn $ "Result #1: " <> Day23.run1 fixture + -- putStrLn $ "Result #2: " <> Day23.run2 fixture + + -- putStrLn "Day24" + -- fixture <- readFile "app/Inputs/Year2024/Day24.txt" + -- putStrLn $ "Result #1: " <> Day24.run1 fixture + -- putStrLn $ "Result #2: " <> Day24.run2 fixture + + -- putStrLn "Day25" + -- fixture <- readFile "app/Inputs/Year2024/Day25.txt" + -- putStrLn $ "Result #1: " <> Day25.run1 fixture + + putStrLn "DayXX" + fixture <- readFile "app/Inputs/Year2024/DayXX.txt" + putStrLn $ "Result #1: " <> DayXX.run1 fixture + putStrLn $ "Result #2: " <> DayXX.run2 fixture diff --git a/hie.yaml b/hie.yaml index 49f5d74..3ea134b 100644 --- a/hie.yaml +++ b/hie.yaml @@ -12,6 +12,9 @@ cradle: - path: "./app/Year2023.hs" component: "advent-of-code:exe:advent-of-code-2020-exe" + - path: "./app/Year2024.hs" + component: "advent-of-code:exe:advent-of-code-2020-exe" + - path: "./app/Paths_advent_of_code.hs" component: "advent-of-code:exe:advent-of-code-2020-exe" @@ -24,6 +27,9 @@ cradle: - path: "./app/Year2023.hs" component: "advent-of-code:exe:advent-of-code-2021-exe" + - path: "./app/Year2024.hs" + component: "advent-of-code:exe:advent-of-code-2021-exe" + - path: "./app/Paths_advent_of_code.hs" component: "advent-of-code:exe:advent-of-code-2021-exe" @@ -36,8 +42,26 @@ cradle: - path: "./app/Year2021.hs" component: "advent-of-code:exe:advent-of-code-2023-exe" + - path: "./app/Year2024.hs" + component: "advent-of-code:exe:advent-of-code-2023-exe" + - path: "./app/Paths_advent_of_code.hs" component: "advent-of-code:exe:advent-of-code-2023-exe" + - path: "./app/Year2024.hs" + component: "advent-of-code:exe:advent-of-code-2024-exe" + + - path: "./app/Year2020.hs" + component: "advent-of-code:exe:advent-of-code-2024-exe" + + - path: "./app/Year2021.hs" + component: "advent-of-code:exe:advent-of-code-2024-exe" + + - path: "./app/Year2023.hs" + component: "advent-of-code:exe:advent-of-code-2024-exe" + + - path: "./app/Paths_advent_of_code.hs" + component: "advent-of-code:exe:advent-of-code-2024-exe" + - path: "./test" component: "advent-of-code:test:advent-of-code-test" diff --git a/package.yaml b/package.yaml index aabe3ea..1f7a653 100644 --- a/package.yaml +++ b/package.yaml @@ -61,6 +61,17 @@ executables: - -rtsopts - -with-rtsopts=-N - -main-is Year2023 + advent-of-code-2024-exe: + main: Year2024.hs + source-dirs: app + dependencies: + - advent-of-code + ghc-options: + - -O2 + - -threaded + - -rtsopts + - -with-rtsopts=-N + - -main-is Year2024 tests: advent-of-code-test: diff --git a/src/AdventOfCode/Year2023/Day03.hs b/src/AdventOfCode/Year2023/Day03.hs index 439fa82..6eaf381 100644 --- a/src/AdventOfCode/Year2023/Day03.hs +++ b/src/AdventOfCode/Year2023/Day03.hs @@ -90,7 +90,8 @@ process2 input = in sum $ fmap (product . fmap (toInt . toExpression)) $ filter ((== 2) . length) $ - fmap (\symbol -> filter (near symbol) values) $ - filter - (\(_, _, _, exp) -> isGear exp) - operators + ( (\symbol -> filter (near symbol) values) + <$> filter + (\(_, _, _, exp) -> isGear exp) + operators + ) diff --git a/src/AdventOfCode/Year2024/Day01.hs b/src/AdventOfCode/Year2024/Day01.hs new file mode 100644 index 0000000..6aac7de --- /dev/null +++ b/src/AdventOfCode/Year2024/Day01.hs @@ -0,0 +1,40 @@ +module AdventOfCode.Year2024.Day01 + ( run1, + run2, + ) +where + +import Data.Bifunctor (Bifunctor (bimap)) +import Data.List (sort) +import Data.Map (singleton, unionsWith, (!?)) +import Data.Maybe (fromMaybe) +import GHC.Read (Read (readPrec)) +import Text.ParserCombinators.ReadPrec (ReadPrec) + +newtype Input = Input (Int, Int) + +instance Read Input where + readPrec = do + a <- readPrec + b <- readPrec + return $ Input (a, b) + +process1 :: [(Int, Int)] -> Int +process1 = + sum + . map (abs . uncurry (-)) + . uncurry zip + . bimap sort sort + . unzip + +run1 :: String -> String +run1 = show . process1 . map ((\(Input a) -> a) . read) . lines + +process2 :: [(Int, Int)] -> Int +process2 xs = sum $ (\x -> x * fromMaybe 0 ((!?) xx $ x)) <$> xs1 + where + (xs1, xs2) = unzip xs + xx = unionsWith (+) $ (`singleton` 1) <$> xs2 + +run2 :: String -> String +run2 = show . process2 . map ((\(Input a) -> a) . read) . lines diff --git a/src/AdventOfCode/Year2024/DayXX.hs b/src/AdventOfCode/Year2024/DayXX.hs new file mode 100644 index 0000000..227c266 --- /dev/null +++ b/src/AdventOfCode/Year2024/DayXX.hs @@ -0,0 +1,17 @@ +module AdventOfCode.Year2024.DayXX + ( run1, + run2, + ) +where + +process1 :: Int -> Int +process1 = id + +run1 :: String -> String +run1 = const "" + +process2 :: Int -> Int +process2 = id + +run2 :: String -> String +run2 = const "" diff --git a/stack.yaml b/stack.yaml index 91a8535..a1b451c 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-21.21 +resolver: lts-22.43 packages: - . diff --git a/stack.yaml.lock b/stack.yaml.lock index 2fb4359..1a1849b 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -13,7 +13,7 @@ packages: hackage: memoize-1.1.2 snapshots: - completed: - sha256: 7d4b649cf368f9076d8aa049aa44efe58950971d105892734e9957b2a26a2186 - size: 640060 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/21.yaml - original: lts-21.21 + sha256: 08bd13ce621b41a8f5e51456b38d5b46d7783ce114a50ab604d6bbab0d002146 + size: 720271 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/43.yaml + original: lts-22.43 diff --git a/test/AdventOfCode/Year2024/Day01Spec.hs b/test/AdventOfCode/Year2024/Day01Spec.hs new file mode 100644 index 0000000..90ffb75 --- /dev/null +++ b/test/AdventOfCode/Year2024/Day01Spec.hs @@ -0,0 +1,42 @@ +module AdventOfCode.Year2024.Day01Spec + ( spec, + ) +where + +import AdventOfCode.Year2024.Day01 + ( run1, + run2, + ) +import Test.Hspec + ( Spec, + it, + shouldBe, + ) + +spec :: Spec +spec = do + it "run1" $ do + run1 + ( unlines + [ "3 4", + "4 3", + "2 5", + "1 3", + "3 9", + "3 3" + ] + ) + `shouldBe` "11" + + it "run2" $ do + run2 + ( unlines + [ "3 4", + "4 3", + "2 5", + "1 3", + "3 9", + "3 3" + ] + ) + `shouldBe` "31" diff --git a/test/AdventOfCode/Year2024/DayXXSpec.hs b/test/AdventOfCode/Year2024/DayXXSpec.hs new file mode 100644 index 0000000..2538409 --- /dev/null +++ b/test/AdventOfCode/Year2024/DayXXSpec.hs @@ -0,0 +1,22 @@ +module AdventOfCode.Year2024.DayXXSpec + ( spec, + ) +where + +import AdventOfCode.Year2024.DayXX + ( run1, + run2, + ) +import Test.Hspec + ( Spec, + it, + shouldBe, + ) + +spec :: Spec +spec = do + it "run1" $ do + run1 (unlines []) `shouldBe` "" + + it "run2" $ do + run2 (unlines []) `shouldBe` ""