commit 66fc1893b9581dacab3570998be521daa51e4513 Author: tommy Date: Mon Dec 2 08:16:38 2024 -0500 Day 1: Part 1 diff --git a/day1/day1.lua b/day1/day1.lua new file mode 100644 index 0000000..4a51e17 --- /dev/null +++ b/day1/day1.lua @@ -0,0 +1,44 @@ +--Lua 5.4.2 +local File = io.open("input.txt", "r") + +if not File then + print("File not found") + return +end + +local LeftList = {} +local RightList = {} +local Distances = {} + +for Line in File:lines() do + local LeftId, RightId = Line:match("(%d+)%s+(%d+)") + table.insert(LeftList, tonumber(LeftId)) + table.insert(RightList, tonumber(RightId)) +end + +local function SortFunction(a, b) + return a < b +end + +table.sort(LeftList, SortFunction) +table.sort(RightList, SortFunction) + +if #LeftList ~= #RightList then + print("Lists are not the same size") + return +end + +for ListIndex = 1, #LeftList do + local LeftId, RightId = LeftList[ListIndex], RightList[ListIndex] + local Distance = math.abs(LeftId - RightId) + Distances[ListIndex] = Distance +end + +local TotalDistance = 0 +for _, Distance in next, Distances do + TotalDistance = TotalDistance + Distance +end + +print("Total distance:", TotalDistance) + +File:close() diff --git a/day1/input.txt b/day1/input.txt new file mode 100644 index 0000000..5a9f332 --- /dev/null +++ b/day1/input.txt @@ -0,0 +1,1000 @@ +64430 75582 +87936 20843 +98310 72035 +98142 69076 +73170 50561 +65508 20716 +72642 84718 +63792 89556 +88319 66913 +38149 43160 +88982 10253 +34137 95932 +79589 92389 +49164 98263 +49746 92762 +53896 43420 +21240 95725 +88691 37648 +47697 66763 +38234 98154 +74901 20452 +70760 11404 +16084 74024 +77408 32178 +81054 45709 +68478 92252 +52984 55239 +14952 20843 +42548 69422 +21427 20329 +92508 81533 +22650 76459 +48388 81843 +49540 25697 +65666 12373 +45713 16199 +42419 10468 +64757 30375 +58273 43473 +10576 20540 +31508 42210 +21718 52578 +55862 92252 +29892 20716 +35978 50547 +18953 43473 +51379 31038 +16417 83883 +66023 24679 +28031 55268 +69178 45771 +56463 93602 +33368 20147 +16434 43473 +97551 73418 +46904 19198 +25697 60996 +37363 35781 +11282 92252 +35209 72035 +66763 27103 +85271 69322 +33759 94633 +17008 83883 +97073 21870 +24061 55053 +53095 92252 +12374 92762 +25571 51808 +37178 10953 +88710 67938 +64979 48065 +49734 80760 +73780 81067 +55802 37177 +78442 90493 +97220 32178 +39845 25697 +27359 39117 +66371 17473 +50236 82028 +54937 41865 +11989 69107 +61602 78467 +83376 75395 +84545 42210 +24250 55446 +29247 37936 +48897 21653 +89795 26960 +60748 39097 +32745 20716 +66967 43473 +63073 21718 +71949 83590 +30876 83883 +43640 21718 +37703 37133 +19198 43473 +43605 42609 +35757 54910 +20959 23081 +29302 52984 +56530 82308 +95611 42671 +60818 39516 +18302 61539 +25344 25697 +91669 80760 +67090 98098 +44280 59977 +17423 65400 +56952 78467 +23067 72035 +45925 76133 +84963 87050 +29175 32178 +89724 74826 +85282 49648 +86399 77097 +34615 52896 +47895 52578 +68604 72035 +30689 20716 +66582 92521 +72688 76209 +47389 87846 +66229 64769 +32205 70746 +95885 83814 +56440 19941 +87356 21436 +67641 92252 +20678 45960 +31065 75217 +95705 69076 +90463 44022 +51401 36472 +73186 48543 +45910 49551 +26499 84718 +94815 20415 +46840 43473 +47483 94710 +11870 43473 +28799 14080 +24832 79589 +83929 51875 +39407 53253 +73986 62364 +66614 44738 +75392 21277 +70204 55613 +99686 21718 +85726 19198 +47638 92252 +81669 30026 +70370 60748 +53783 11004 +54371 35046 +72567 87098 +87969 32178 +81067 60748 +61446 98023 +76471 92252 +64431 25697 +42080 80760 +14486 13466 +82716 52984 +49351 15539 +36159 15090 +56913 88064 +96843 44738 +66639 89714 +91239 42210 +65785 76459 +49114 86785 +58894 41438 +45307 79589 +38693 80286 +21963 52722 +46504 44738 +22201 84718 +15556 61539 +86120 86377 +21887 81067 +32242 92762 +61544 37648 +29147 73990 +24239 62852 +30163 48652 +95900 83883 +71487 60590 +69076 47403 +68557 70174 +80423 85726 +92873 10245 +59391 87955 +15416 80760 +90803 70939 +25081 81067 +10323 46564 +75418 60748 +92762 43409 +32178 20716 +72035 25025 +30702 11797 +70262 20843 +10801 60970 +69510 56933 +38295 27487 +57266 71215 +39071 92542 +20540 21718 +57027 81151 +77729 90745 +96980 28442 +65961 19198 +55385 82179 +86139 91952 +72873 61041 +95457 44738 +84209 83883 +93774 92762 +67731 14982 +81176 26473 +50239 13336 +74772 81067 +91982 80690 +40004 89466 +52769 72035 +40693 42210 +50506 26856 +71898 68597 +99210 32178 +45079 53505 +17581 94678 +83211 28309 +52582 50257 +62597 92762 +20716 38593 +18630 73077 +20835 30809 +75099 18088 +56109 42210 +31503 72884 +60392 83711 +26052 17008 +49938 20540 +16604 85679 +94700 29256 +52740 69859 +84337 25174 +46814 64723 +68259 34542 +79927 18036 +57010 78467 +73378 90472 +83131 30214 +84704 37648 +36494 40475 +43734 90827 +85678 61539 +65197 81067 +80121 24363 +97038 85579 +59873 72035 +54928 17827 +46120 33920 +68979 32133 +88690 90929 +38840 92762 +66900 67817 +59182 85839 +15538 81151 +60198 54586 +57452 71692 +12212 79875 +62853 67888 +67754 53532 +86454 52984 +94629 92403 +80986 30351 +76966 77097 +78419 92762 +12343 20540 +26294 75804 +18240 23339 +72971 58631 +69610 81067 +96198 31081 +25389 13525 +29670 76459 +39477 79589 +58028 21718 +77097 27842 +95031 78097 +32844 43989 +12618 96437 +82959 43688 +40438 20716 +58980 80760 +26176 39610 +81464 24846 +31997 35781 +82384 83883 +54010 20844 +63959 45452 +43239 16738 +45375 87524 +36278 95715 +96601 80760 +82935 27550 +13493 58808 +17988 92762 +59523 67650 +69133 44178 +59959 77097 +89068 20843 +31067 36430 +55300 23059 +36759 48277 +91317 46947 +58240 85726 +22368 92356 +60765 84751 +72733 26888 +19688 62073 +90158 57933 +11176 28442 +53051 50769 +76632 97012 +98132 80760 +73098 83281 +46753 25697 +44849 15301 +62899 74187 +71237 81067 +56670 20649 +18624 82808 +32614 34732 +98452 76464 +51626 35781 +55943 89986 +59443 72035 +96628 73132 +77928 45659 +76256 74161 +13944 94048 +12446 20843 +70331 46956 +46097 39097 +46415 83883 +29460 44307 +73685 89046 +53969 52578 +82435 40606 +65769 45167 +89700 50621 +80281 43473 +97402 60748 +11127 87361 +50692 60748 +43989 61539 +40319 11156 +85446 71698 +58820 89274 +77545 80760 +34103 37577 +83858 33573 +23402 61991 +82147 48488 +15719 80760 +16987 22112 +41519 29897 +29178 47932 +92027 25765 +92998 92252 +52103 77097 +64962 32490 +81888 29503 +92252 57018 +88397 32178 +13852 89473 +73603 20540 +95704 32178 +36045 46227 +38834 72035 +85241 60748 +94036 77097 +90984 92762 +44738 44738 +48078 76459 +40832 24578 +78789 78634 +42210 92252 +16967 61124 +76704 65696 +69647 51055 +41412 35781 +50365 63580 +33725 79129 +90837 17116 +25000 52578 +55672 81986 +50507 73820 +82260 92762 +58284 33808 +79462 43473 +76384 23808 +49652 81151 +24386 44424 +76993 77003 +11077 79166 +58255 43047 +81122 28757 +63846 30206 +69361 76459 +19338 35781 +28857 37648 +33643 89353 +61915 52984 +54227 18855 +16162 92252 +21546 60184 +15120 61012 +63185 68250 +44681 89512 +25644 80760 +12963 42210 +41952 17962 +46649 89796 +46412 68405 +32401 61539 +81393 20540 +13678 78467 +68025 99213 +27934 35781 +91794 61539 +98970 71396 +18314 69562 +19908 97620 +69828 60768 +89139 36928 +71402 25697 +64070 32178 +55145 38138 +65851 25697 +98808 67787 +57244 21718 +18541 79589 +88135 84731 +77694 61539 +52608 83313 +67204 91715 +47233 39097 +99317 37648 +84111 30506 +71316 39097 +24604 61539 +28504 58867 +64952 35781 +72718 43275 +55834 44738 +30446 92252 +37415 29159 +41743 78467 +26267 59675 +33658 11262 +50677 44738 +71609 78322 +26047 52977 +31723 21718 +44390 72035 +53788 89828 +84829 60748 +57972 32178 +93241 27703 +38576 20540 +44958 84718 +94256 47639 +41263 85109 +75946 67054 +20333 77097 +55509 95680 +39858 40117 +88032 21718 +98778 76619 +89995 18411 +28456 62071 +61789 72035 +78073 70754 +77073 31065 +86999 21718 +42298 40782 +50995 43473 +32947 20843 +40617 22994 +84633 40716 +19900 28627 +17816 68538 +32530 25156 +17673 77097 +38208 77097 +54880 78467 +10746 36942 +36110 23213 +80179 61360 +55819 35781 +28442 79589 +88289 92066 +83346 28171 +37597 74543 +45978 84718 +52946 28442 +64609 92762 +24593 39097 +92409 92252 +60718 60223 +26498 70229 +14277 35781 +90961 79589 +19915 79965 +68301 14227 +56321 80760 +15922 67051 +80444 72035 +49913 39097 +97519 83883 +81867 76459 +72049 32178 +98003 81151 +29774 84718 +83596 92936 +65711 41869 +94799 72035 +52228 74833 +35681 15295 +86161 47398 +99764 44738 +13342 66763 +19557 41667 +85701 24392 +67265 54679 +24579 60748 +99212 72720 +11279 20540 +81879 36662 +42791 12924 +98914 75630 +29879 52984 +87696 69076 +54212 32065 +30014 76459 +43433 64434 +31827 43749 +27323 32614 +47887 78467 +12778 90971 +38504 25697 +11985 12152 +88281 32178 +60313 18405 +84487 44738 +10753 76459 +11349 59672 +58532 69076 +37463 81151 +74158 17588 +47713 16319 +52617 99026 +75642 54241 +86070 84718 +89264 68926 +13839 84718 +16425 22018 +15973 35781 +97324 39267 +74858 93659 +30114 82028 +91599 92765 +47093 37648 +50285 60748 +14846 15314 +89741 83883 +27133 42151 +38409 39097 +34370 60748 +43982 69423 +22858 20843 +57345 34197 +40807 61764 +75561 28363 +14111 34713 +49442 81067 +61122 53151 +97636 25131 +43772 25697 +55030 83358 +52741 23263 +74578 81559 +50656 34834 +62586 23884 +99380 73924 +41885 46691 +95691 23340 +68929 18409 +32180 25515 +27880 69609 +15658 25697 +40225 76459 +54028 95026 +51248 83206 +55585 44495 +34730 36987 +72713 43473 +48744 43473 +50628 44738 +66099 81067 +84471 82826 +74726 43646 +63777 80760 +38782 10687 +62565 32178 +30082 36088 +66224 25697 +17798 39097 +65148 37648 +50731 66803 +60010 16037 +71057 20540 +79087 47464 +63666 37648 +61860 74023 +46372 33274 +40076 97575 +81205 25697 +29232 48419 +91161 25173 +80675 51474 +45465 75816 +80432 80760 +84712 73906 +32924 96322 +27386 25697 +35781 80760 +28248 77822 +33634 48276 +93878 48409 +26858 59450 +63868 42103 +94063 13352 +26657 52984 +65635 92762 +47508 11445 +87138 83597 +33328 62612 +70031 85726 +81151 23518 +42263 32662 +85424 71871 +21504 72035 +76646 90060 +36770 31991 +76459 43473 +58215 44495 +20418 86232 +68543 81067 +71082 52984 +24484 86494 +70941 98749 +71613 24014 +98938 35781 +42671 25697 +11798 25697 +55015 81601 +92532 78131 +10415 43260 +89920 11599 +36610 30402 +11196 46252 +61243 80760 +47794 15435 +10054 40848 +90743 52578 +12980 92252 +43206 92762 +23376 69724 +45693 77097 +79629 70562 +69524 20540 +30811 48749 +76688 51485 +50584 77097 +46173 35918 +22138 92762 +98933 52984 +55451 42210 +97723 34368 +39097 60748 +29080 78467 +58962 78467 +71265 13782 +14559 20716 +14366 20540 +68344 72035 +48432 88048 +38005 43473 +85989 93533 +98422 83883 +20685 80045 +69814 72035 +11356 28819 +39329 20843 +52898 19198 +43135 25697 +20409 25697 +52446 34899 +63515 84718 +19371 20540 +16430 20540 +45803 74304 +66092 33425 +80760 95646 +64945 37648 +43951 78467 +87271 17766 +91354 75924 +32506 37648 +15452 79052 +87783 42991 +90937 75439 +68208 97868 +91228 92252 +35773 92762 +74252 32178 +96573 74280 +29447 31544 +61206 62085 +75242 75894 +76850 77838 +22095 24247 +78467 55285 +27611 20540 +18974 84363 +74621 83883 +19469 19323 +26785 25697 +99803 77726 +96042 21449 +61772 39950 +21746 79309 +44817 14075 +65817 54251 +90360 84880 +40529 83883 +63336 62916 +57489 39191 +41980 76639 +61947 69076 +72393 92252 +72994 20540 +38393 42671 +61264 25490 +28725 27770 +68461 83883 +68050 19198 +97146 44738 +13195 32178 +48395 14399 +55269 12291 +43616 62312 +76357 19177 +50496 55565 +97083 24002 +32806 69076 +71713 47157 +91635 92762 +23121 20540 +27917 92762 +61595 77858 +96038 78467 +51300 30664 +99332 39795 +49914 33272 +87083 54823 +39253 99039 +98686 23548 +63961 20540 +76429 42671 +84657 78621 +18867 58861 +28534 92703 +20843 72035 +40011 42210 +28716 35781 +64363 94627 +41215 39358 +74285 77374 +37245 20843 +53602 35781 +73935 90042 +35283 25697 +84164 92252 +26264 19198 +49434 92252 +67281 76459 +47315 37648 +21216 70552 +57730 44738 +55530 83883 +23807 60687 +79378 65500 +81270 19442 +89580 78935 +81287 76459 +37987 82563 +29721 71638 +76282 93445 +82973 44738 +43095 76459 +57911 42481 +15665 30034 +97099 20843 +77440 61539 +61564 40937 +38697 50046 +91585 71537 +66058 44507 +96221 92762 +80464 31623 +52031 88911 +74599 81151 +44495 81151 +37781 50336 +42333 92252 +25393 37648 +31875 40879 +25513 60748 +52578 20540 +83883 67476 +13961 80760 +86512 72429 +52957 37648 +70656 20843 +32267 78467 +67751 23702 +83650 76459 +11249 44738 +82052 44240 +60178 19059 +78052 80760 +92063 42210 +47149 42671 +82429 61080 +24749 68627 +26862 32614 +77843 56271 +24471 41563 +15084 62867 +15444 43417 +15492 61539 +22651 80760 +62625 21763 +49448 48757 +47125 36097 +45650 21134 +76382 40592 +28236 81067 +24712 28270 +26908 63823 +51661 92252 +33112 54575 +59018 52984 +12648 35781 +47726 76268 +16833 15099 +17720 24491 +64016 31467 +62900 37648 +66411 97080 +47653 32178 +78845 16864 +98508 26852 +83446 10379 +50837 40936 +85485 63694 +41709 37648 +84178 28689 +27821 57472 +89199 43473 +95089 43852 +80677 20716 +84551 20125 +84718 11853 +14520 20843 +61473 92762 +69357 37320 +36592 24917 +88660 35781 +92407 20540 +17708 20540 +27217 12607 +51540 44495 +93978 77706 +83790 34181 +46160 69737 +21508 54282 +20593 84718 +12368 38902 +46760 16081 +46693 75780 +90007 89913 +63689 76234 +98781 92745 +77580 44738 +24571 39242 +37950 98910 +63333 76587 +14765 74779 +41979 55432 +65602 13148 +34240 32614 +40909 22506 +25236 78757 +56096 32614 +85735 39877 +37637 52969 +34344 33132 +53389 47303 +66490 36750 +18024 48801 +45153 91679 +94052 20540 +67564 74190 +54685 84718 +89848 69076 +15698 44738 +67033 35486 +23435 24004 +99883 69819 +32300 68680 +82028 21625 +19382 78452 +40073 37648 +86881 31642 +42474 41279 +59165 80760 +60370 34541 +74295 73389 +98654 42210 +87697 39399 +68417 55320 +32125 87304 +23153 51288 +32963 12352 +18366 57673 +74792 50327 +78281 43473 +41693 49359 +41188 35781 +19719 72035 +44395 72831 +75495 78467 +14585 21023 +94358 23804 +13464 23423 +58483 85726 +44941 69076 +91349 12344 +95485 83883 +58981 65861 +43473 61539 +51945 69762 +40385 44738 +32646 42174 +73150 81067 +12154 37648 +55441 20843 +98025 39097 +15339 38796 +31543 42210 +65949 42245 +31434 32614 +57312 57203 +91833 76885 +23286 52984 +58987 32178 +12591 37648 +37648 32316 +97542 35781 +33381 44140 +69851 92540 +60076 19198 +86697 32614 +25533 96431 +68777 15175 +47390 75651 +94550 80760 +61539 20843