diff options
author | Emile <git@emile.space> | 2024-12-01 22:05:46 +0100 |
---|---|---|
committer | Emile <git@emile.space> | 2024-12-01 22:05:46 +0100 |
commit | 3577bb20ef3a3e1af25f1419a3e4a88d336866a0 (patch) | |
tree | c48ecf3d79695c54901883889b91b9ee0fdf8164 |
2024 day one
-rw-r--r-- | 2024/d01.example_input | 6 | ||||
-rw-r--r-- | 2024/d01.input | 1000 | ||||
-rw-r--r-- | 2024/d01.lisp | 36 | ||||
-rw-r--r-- | advent.asd | 11 | ||||
-rw-r--r-- | package.lisp | 3 |
5 files changed, 1056 insertions, 0 deletions
diff --git a/2024/d01.example_input b/2024/d01.example_input new file mode 100644 index 0000000..b8af9ad --- /dev/null +++ b/2024/d01.example_input @@ -0,0 +1,6 @@ +3 4 +4 3 +2 5 +1 3 +3 9 +3 3 diff --git a/2024/d01.input b/2024/d01.input new file mode 100644 index 0000000..8c7e06a --- /dev/null +++ b/2024/d01.input @@ -0,0 +1,1000 @@ +82728 61150 +39850 94024 +24609 43406 +24964 98661 +16230 17299 +29827 43603 +52378 90132 +15961 90132 +48209 97422 +90738 75302 +50850 18024 +83479 94024 +91264 72109 +66553 64129 +39685 55155 +31946 67583 +39808 34091 +45133 43008 +57938 97422 +70650 78635 +40085 43526 +82147 44804 +48132 11603 +36805 26938 +95935 52745 +43007 59992 +64997 70247 +16361 24737 +77467 35575 +88430 84124 +40863 81976 +85989 33349 +64698 77416 +63392 63630 +32665 89542 +82943 39849 +91491 97422 +96858 17299 +88128 75447 +82315 83417 +12263 29681 +56902 35541 +16051 55031 +41613 70247 +48481 82123 +39670 89542 +31830 94024 +93702 46875 +27322 97674 +77697 38394 +12569 43603 +35225 13575 +59674 47405 +18319 89542 +88626 68373 +26170 74493 +70247 91908 +38965 28783 +52976 51470 +15339 80450 +72244 13084 +46476 91257 +11615 43109 +92556 35200 +30522 17599 +52667 55031 +61811 24081 +15611 55031 +31461 62239 +36424 16768 +92745 44773 +10246 50548 +86509 28934 +45418 78893 +45156 63696 +95535 55031 +16691 96423 +43778 43603 +71564 52518 +87002 81976 +94024 83359 +20893 60991 +62456 35753 +33024 85311 +66867 44981 +61522 43603 +16128 43603 +41863 94024 +88684 33301 +59882 95399 +70842 13159 +62709 16215 +16058 48454 +67232 35375 +62624 16768 +47204 53486 +81027 66508 +76530 49287 +25749 46116 +81620 45156 +71662 77019 +80092 68967 +19088 31955 +40308 81976 +39855 90825 +93549 88660 +71622 81450 +64422 30851 +43828 60702 +77801 90810 +13925 91184 +51830 83830 +12507 26391 +50014 45156 +56843 97422 +57063 17118 +37260 38582 +94363 18325 +58862 23200 +57703 82014 +33084 64836 +51041 69435 +97254 51941 +35644 43603 +18669 57530 +56890 23054 +31788 80735 +54517 89542 +52172 29681 +50286 17299 +96866 94024 +56782 91820 +25469 18254 +33882 20182 +56421 31746 +91215 40070 +83847 64836 +62253 94024 +94121 60848 +98477 21613 +37590 85421 +25770 14916 +59401 59921 +73382 51470 +58149 62768 +54118 22482 +59395 59921 +63746 81450 +94883 13575 +50314 29681 +93858 82015 +27751 54143 +26917 35753 +81996 23054 +71969 93265 +30553 20135 +77288 83737 +79468 95847 +30637 31173 +57832 95779 +29795 13575 +71371 94024 +27972 69030 +43433 55031 +45878 97422 +74042 95825 +38197 69071 +63067 45758 +76552 65255 +86156 64724 +19492 46293 +52089 69521 +66789 34079 +82613 42340 +20542 18205 +22143 14916 +73968 89542 +40335 45290 +92711 51470 +19146 94024 +53047 13284 +49843 25804 +96430 95399 +98633 90132 +50516 43603 +23379 25467 +35212 73008 +22440 61796 +51478 40724 +81249 43603 +53260 51470 +83243 59921 +92917 90132 +53224 95399 +83043 51275 +79555 63244 +70751 64836 +84246 97100 +46769 16885 +59806 13284 +20614 60848 +81232 23902 +59959 16768 +37902 14331 +29562 55031 +52097 81976 +24953 58343 +17261 55031 +54502 99896 +96242 48343 +37556 81450 +18272 60848 +66670 19012 +83198 80333 +23519 95399 +17886 38271 +16359 99341 +40648 33892 +77114 77385 +36008 71553 +79769 60848 +47199 13575 +46285 88410 +23880 81943 +57491 98108 +98778 27568 +21135 25456 +96914 81450 +78774 13575 +63430 45001 +87607 65255 +29550 16633 +93138 95399 +53884 94498 +29227 55031 +11378 97422 +73168 92972 +28560 40280 +58428 30760 +85756 94197 +51545 77019 +40374 13431 +96538 64836 +70888 85369 +96291 70247 +87918 64137 +76493 52966 +88843 60854 +92908 65255 +39225 81310 +70001 56892 +76446 24595 +85220 81450 +58580 43167 +97422 29681 +61228 64836 +28019 70247 +90150 43603 +51935 95924 +90430 86513 +84890 89326 +45758 74544 +33282 70247 +35203 36593 +81450 12273 +99714 31653 +62192 43603 +48547 64836 +81976 13575 +58583 13431 +14066 12887 +62207 42508 +86711 13431 +36650 44019 +57249 40786 +80718 64836 +63471 14916 +71861 55031 +68757 14916 +41204 17299 +66794 98207 +95829 45758 +83965 43978 +87160 29681 +49557 81901 +61775 92631 +43971 24451 +95603 70593 +68672 97422 +99669 13325 +24435 61844 +73318 89542 +54617 69071 +71223 17299 +55314 97422 +93737 46194 +47491 93916 +34979 79658 +77019 81976 +61998 77019 +45142 79564 +58057 77878 +77811 68285 +67567 46867 +75736 90132 +35995 64599 +69522 24241 +74746 91359 +76546 13431 +61686 60848 +81479 56819 +86234 46898 +17684 14916 +54606 36671 +91078 14916 +87613 81450 +68950 29904 +92860 29681 +97548 26634 +94120 46867 +65885 51516 +93925 71162 +65057 13284 +47652 75587 +90143 16768 +22958 13575 +19110 56571 +90991 86313 +86342 49453 +13474 89542 +39258 60854 +32081 78421 +59662 60854 +77568 24365 +26287 64963 +73097 56013 +65459 97422 +15222 20848 +94198 46293 +31524 54464 +62524 13431 +63731 23054 +94492 58590 +39340 89542 +98341 94382 +87046 14916 +54817 73805 +92197 79829 +75996 81752 +15843 51151 +81860 91508 +97487 81450 +55465 45279 +98617 72612 +41836 15262 +96431 59346 +68321 24649 +44222 14916 +12305 26436 +26128 43083 +49032 45758 +32611 59921 +16984 83584 +79976 81450 +53906 65866 +28125 40953 +79829 13431 +71094 66024 +15262 74605 +10894 73112 +33135 25114 +73835 81176 +92084 51692 +99655 48595 +26871 78248 +21930 46867 +11939 95399 +50426 27946 +84499 46293 +76605 21967 +70366 70247 +23875 11765 +29040 23054 +65978 70247 +65316 81976 +78274 57844 +19602 36987 +59993 45758 +61413 40822 +95133 15262 +60391 17299 +56884 20462 +32017 86368 +61814 70068 +36780 50859 +34229 89542 +96617 14382 +16265 64992 +68054 57606 +41854 27907 +87505 25772 +82921 13575 +29611 51470 +64836 77139 +12016 94024 +25898 90132 +39759 40921 +70322 28732 +16957 97215 +80739 20405 +42783 59243 +53327 35753 +60939 93730 +65608 21723 +51615 77019 +42372 60225 +82865 62922 +51705 13575 +60517 44646 +32859 49938 +65056 65110 +66014 59518 +95374 69071 +62688 45758 +19612 34764 +14898 91359 +35158 84040 +46004 51534 +12662 84719 +59241 22568 +50371 69943 +66714 13864 +32091 90159 +27889 21234 +21486 43277 +91705 71361 +43597 78281 +96488 23720 +16085 91359 +84801 65255 +17302 77019 +35657 34340 +89315 10686 +56279 81976 +14916 91359 +55031 17299 +99549 45758 +69322 42820 +15753 54646 +13910 81943 +10622 60854 +89542 16187 +45934 58213 +25961 23054 +73079 81694 +73577 61502 +11146 72825 +41762 68244 +75839 64836 +54839 56505 +42362 93709 +23054 45156 +41434 22280 +68919 81976 +51470 35694 +82925 95399 +52548 82748 +77271 49843 +77587 13575 +58491 73903 +90544 70247 +97483 43603 +92561 80709 +37349 35639 +81533 23054 +16921 67801 +54482 57089 +55983 20574 +18017 47405 +91613 94024 +28936 87183 +94041 56294 +97989 65255 +74053 31819 +12545 55980 +82508 23054 +16768 46293 +68704 47565 +79617 47405 +41459 81943 +88096 43603 +59389 13284 +24842 81976 +13968 67491 +46198 81943 +15283 65255 +49913 17088 +10405 14916 +92804 62365 +76765 79391 +54682 68981 +33524 18156 +76148 23054 +66461 77019 +33406 94024 +51127 34897 +23852 13284 +72435 81607 +26294 77019 +42775 13961 +75922 97390 +47133 87320 +36766 95060 +30569 95399 +27931 19111 +54334 29670 +40819 18317 +70620 90199 +65626 93032 +53032 31988 +80476 13284 +26777 11497 +56970 23054 +40175 89542 +76426 77019 +25173 94024 +87181 95399 +51275 77019 +16447 63367 +81943 50854 +10254 78936 +75282 45758 +60082 23054 +64998 79829 +49070 13431 +56755 52197 +69071 73076 +75338 17299 +75541 29541 +90443 88931 +89908 84016 +13663 62808 +36653 13284 +49672 67563 +55603 11156 +66603 64971 +88089 13284 +42518 72738 +63672 65255 +46069 92788 +35113 47405 +25531 68032 +55846 41799 +68911 99772 +97864 43603 +67936 13284 +64842 97422 +95511 77019 +53067 70247 +33019 65117 +48961 89542 +91310 82114 +81303 13284 +21127 46293 +55847 81943 +49862 95399 +90703 91620 +51583 59242 +95384 44667 +71879 10528 +51111 51072 +73704 64836 +67917 43603 +90318 65645 +38668 46293 +58760 48017 +46625 81450 +31014 94197 +60854 97422 +37481 81450 +49181 89542 +94558 82318 +88224 74894 +33578 38935 +17470 47295 +97321 73090 +14158 29681 +71896 90132 +37567 30968 +13543 84125 +56076 69071 +17520 97422 +13731 83298 +64073 13431 +79501 48002 +15814 81943 +22828 54359 +82055 70247 +45012 81943 +65118 34203 +27935 71093 +72534 90132 +67283 90132 +94197 96436 +11632 43603 +57374 23054 +88992 75593 +40356 22369 +55831 13431 +21812 65255 +13044 46867 +61280 28505 +93877 81976 +97018 47932 +39895 66100 +94335 13575 +43867 43722 +91800 13284 +39295 59394 +37827 91359 +43381 46913 +12882 10753 +99546 14556 +69726 83158 +92017 45758 +92576 85933 +82806 99520 +95240 16049 +73226 75691 +95399 75289 +41658 13284 +32251 72477 +21150 81976 +25532 89542 +68624 43603 +99988 47405 +28545 73762 +47911 14241 +10006 45084 +70869 97422 +76635 17299 +74980 16768 +29665 32846 +22260 13284 +83589 16768 +12297 43603 +94460 30815 +14367 74187 +48459 78588 +48094 14916 +64554 34585 +40966 15981 +55992 68759 +56286 64836 +91359 58182 +37712 46867 +10002 27220 +35390 51119 +79851 27599 +28003 29681 +11126 81943 +77889 56829 +21290 65255 +12281 42665 +58526 23054 +96441 43603 +32713 24189 +11803 69829 +15808 15511 +87150 87399 +61028 69071 +43603 18973 +49827 13284 +79374 17299 +63980 46293 +35321 91359 +63092 77019 +93950 81943 +61348 98676 +67412 26112 +88625 61556 +82756 46867 +61980 51275 +33183 15153 +82717 54552 +10272 69791 +90197 85585 +66042 81450 +87499 55031 +22891 59921 +19636 87817 +14035 89514 +44978 72496 +66453 83959 +35532 21026 +90326 76422 +45538 14916 +58391 45699 +68240 23054 +17327 17309 +54811 36357 +29411 13575 +19772 20557 +55843 19650 +34136 23054 +35640 80932 +31022 13284 +51453 17849 +59415 73413 +47405 60585 +24554 59847 +16449 77019 +84635 13284 +71150 79399 +91304 45758 +16316 45156 +24372 65255 +51800 56078 +25967 56557 +10335 13575 +26500 61450 +21511 65255 +47266 52620 +51507 36666 +43522 16768 +13302 60048 +28720 13431 +27828 60848 +17916 65255 +27845 63254 +60848 90132 +15202 26716 +21780 50888 +45198 50172 +15593 56206 +84399 81976 +84383 97422 +45107 50570 +55693 45156 +61697 77864 +40967 99041 +12361 81976 +85195 10836 +23903 59921 +75889 63849 +85462 69833 +55277 98966 +99467 16768 +80545 92826 +97028 13431 +49543 58198 +79679 81450 +37768 14916 +49987 43592 +52388 81391 +49705 31727 +97337 89542 +65261 15228 +32193 23798 +96980 56609 +55973 96548 +43554 54178 +14385 53532 +13284 52896 +31417 79377 +39843 40105 +47537 60848 +97596 94197 +92481 23651 +32979 91359 +20137 44731 +32782 77019 +97715 14916 +36171 73797 +52352 77019 +65624 70034 +43735 94024 +32065 81450 +37801 70247 +57260 91182 +58699 22228 +46293 95695 +88201 51470 +65421 70247 +98471 80000 +97663 91359 +29825 40467 +36280 83692 +63395 93834 +13431 46293 +65598 56325 +45294 58994 +36392 13431 +48817 70247 +42632 14916 +75814 12534 +79015 29681 +63583 14222 +21811 65255 +15712 77019 +82774 94024 +25558 87504 +40351 82954 +66201 41337 +17467 13431 +25618 78048 +21325 93477 +48070 23054 +71739 44215 +22764 14916 +70342 81976 +61768 43603 +90132 31672 +35753 85115 +87424 95399 +44506 59921 +58439 69764 +91737 43091 +84038 85175 +34169 32959 +57299 67053 +16078 55031 +94423 45156 +12025 76644 +49243 35658 +24206 76815 +19466 68123 +36271 16768 +20805 59921 +44320 90492 +55138 64836 +80603 45758 +80337 30227 +59921 67830 +95013 23975 +42358 45118 +60271 62795 +91829 14916 +72118 81976 +42079 64836 +29714 47405 +75024 69180 +97698 17299 +53871 60848 +32772 94024 +23136 69263 +65014 13284 +99723 70247 +10739 69071 +96656 20261 +77088 64836 +60997 27431 +16566 59892 +34855 71849 +13575 43778 +10925 81943 +41426 38747 +45792 91359 +77266 13575 +54453 89542 +26345 88825 +45204 69926 +22055 70247 +66184 45758 +89954 13284 +76966 78245 +16756 75144 +35954 13431 +41534 55700 +34625 25112 +16484 27791 +13180 43603 +72476 26272 +56865 44266 +29214 52239 +48021 13137 +85762 56515 +11530 14094 +25191 46867 +40256 27805 +42575 35753 +78015 89542 +79395 36014 +51976 60848 +91540 78975 +15438 29681 +83498 13575 +70566 28673 +78791 46293 +40988 46249 +84968 15198 +12950 51470 +43049 40408 +29441 17880 +33283 29681 +45021 77019 +19403 60496 +37671 13897 +52800 46293 +65255 73346 +19007 78906 +61032 95399 +41062 99758 +58160 16768 +16220 49027 +10787 64836 +55534 70247 +32708 17299 +26862 17299 +32335 46867 +46693 23383 +24824 75634 +21313 80071 +53841 35488 +76356 81943 +10703 43632 +82980 98849 +11274 88022 +68390 65255 +45798 90132 +66426 37716 +27073 81077 +40291 57328 +76494 71247 +44324 90132 +15572 62595 +67578 19687 +59765 81976 +29681 81450 +24923 60526 +63193 28900 +68670 81943 +21643 55031 +17767 98815 +70739 17299 +77675 64144 +65919 70247 +86115 35753 +35921 70247 +35695 95399 +17571 90132 +10776 23054 +55618 19388 +23004 60854 +35209 81976 +70656 48543 +28799 13575 +62772 16890 +88333 35753 +89689 12805 +96145 16768 +44732 79829 +41319 70247 +17299 81450 +48321 81450 +60541 32436 +98932 47405 +50849 27716 +81857 62305 +64010 89156 +34841 99387 +27063 83357 +73447 64896 +83334 29681 +44937 87174 +59004 13575 +17881 49843 +71379 50689 +92853 47405 +32440 91359 +88509 13575 +29889 42477 +83016 14916 +34898 19758 +43489 89542 +26612 13575 +58720 93232 +63399 16768 +46867 29681 +23466 17299 +63419 70636 +53408 34371 +66651 75494 +44058 18000 +13953 81450 +69061 13284 +92526 15134 +69474 97422 +56975 26225 +94591 26288 +20141 33683 +84695 17299 +14687 79829 +34338 64836 +26755 89542 +11290 21632 +30499 83141 +52953 16639 +78106 31125 +44897 79242 diff --git a/2024/d01.lisp b/2024/d01.lisp new file mode 100644 index 0000000..b4ec6f2 --- /dev/null +++ b/2024/d01.lisp @@ -0,0 +1,36 @@ +(in-package :aoc/2024) + +(defparameter *input/d1* + (asdf:system-relative-pathname :advent "2024/d01.input")) + +(defun readlists (filename) + "Read the left and right columns of numbers into individual lists" + (let ((left-numbers '()) + (right-numbers '())) + (with-open-file (stream filename :direction :input) + (loop for line = (read-line stream nil nil) + while line do + (let* ((tab-pos (search " " line)) + (left (parse-integer (subseq line 0 tab-pos))) + (right (parse-integer (subseq line (1+ tab-pos))))) + (push left left-numbers) + (push right right-numbers)))) + (list + (nreverse left-numbers) + (nreverse right-numbers)))) + +(let* ((input-list (readlists *input/d1*)) + (left (sort (first input-list) #'<)) + (right (sort (second input-list) #'<)) + (diff (mapcar #'- left right)) + (absdiff (mapcar #'abs diff)) + (result (apply #'+ absdiff))) + (print result)) +; 2066446 + +(let* ((input-list (readlists *input/d1*)) + (left (first input-list)) + (right (second input-list)) + (result (apply #'+ (mapcar #'(lambda (x) (* x (count x right))) left)))) + (print result)) +; 24931009 diff --git a/advent.asd b/advent.asd new file mode 100644 index 0000000..d67098d --- /dev/null +++ b/advent.asd @@ -0,0 +1,11 @@ +(asdf:defsystem #:advent + :serial t + :description "Advent of Code" + :author "Emile Hansmaennel <cl@emile.space>" + :license "MIT" + :depends-on (#:alexandria) + :components ((:file "package") + (:file "utils") + (:module "2024" + :components ((:file "package") + (:file "d01"))))) diff --git a/package.lisp b/package.lisp new file mode 100644 index 0000000..7eb4fab --- /dev/null +++ b/package.lisp @@ -0,0 +1,3 @@ +(defpackage #:aoc/2024 + (:use #:cl)) + |