From b2ffe8c5910d3481905aa8ef6537a4710bac8bb6 Mon Sep 17 00:00:00 2001 From: Julius Klotz Date: Sun, 7 Dec 2025 21:30:45 +0100 Subject: [PATCH] Added first try for day 5 part 2 --- bin/main.ml | 6 +- inputs/day05.txt | 1188 ++++++++++++++++++++++++++++++++++++++++++++++ lib/day5.ml | 93 ++++ 3 files changed, 1285 insertions(+), 2 deletions(-) create mode 100644 inputs/day05.txt create mode 100644 lib/day5.ml diff --git a/bin/main.ml b/bin/main.ml index 8dc46b2..ef7e20d 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,8 +1,10 @@ -let () = Printf.printf "Solution Day 1 part 1: %i\n" Aoc25.Day1.day1_part1 +(**let () = Printf.printf "Solution Day 1 part 1: %i\n" Aoc25.Day1.day1_part1 let () = Printf.printf "Solution Day 1 part 2: %i\n" Aoc25.Day1.day1_part2 let () = Printf.printf "Solution Day 2 part 1: %i\n" Aoc25.Day2.day2_part1 let () = Printf.printf "Solution Day 2 part 2: %i\n" Aoc25.Day2.day2_part2 let () = Printf.printf "Solution Day 3 part 1: %i\n" Aoc25.Day3.day3_part1 -let () = Printf.printf "Solution Day 3 part 1: %i\n" Aoc25.Day3.day3_part2 +let () = Printf.printf "Solution Day 3 part 1: %i\n" Aoc25.Day3.day3_part2*) let () = Printf.printf "Solution Day 4 part 1: %i\n" Aoc25.Day4.day4_part1 let () = Printf.printf "Solution Day 4 part 2: %i\n" Aoc25.Day4.day4_part2 +let () = Printf.printf "Solution Day 5 part 1: %i\n" Aoc25.Day5.day5_part1 +let () = Printf.printf "Solution Day 5 part 2: %i\n" Aoc25.Day5.day5_part2 diff --git a/inputs/day05.txt b/inputs/day05.txt new file mode 100644 index 0000000..6b833ab --- /dev/null +++ b/inputs/day05.txt @@ -0,0 +1,1188 @@ +34452670365908-39356756283317 +394529385884650-394628702944004 +102620947820170-103229070500605 +132181665511922-138200691289156 +394877463113550-395253130028203 +502095233029045-502348453390315 +503667223561226-509136145382983 +233819611497066-234572239483835 +275797343985335-278057790214828 +75641956243136-78098158659964 +398997208244951-399483317553646 +104211581332700-104903823508565 +29586830165344-29586830165344 +499902707469604-500416506287148 +222969155742602-225638060856634 +124970724723283-128402216224601 +43836223730745-49177711042138 +236829206791775-237714369832544 +295544212971961-296631956912466 +397878409296051-398461369679872 +555740025451076-555740025451076 +317432688175322-318690201064424 +394118192439225-394628702944004 +196569386910891-196569386910891 +21807523784418-29586830165344 +101147327087488-101957600189382 +445211190043980-450214690626508 +238169643361847-238936670811391 +121021350183766-124970724723282 +299177131826521-300552513843961 +333085364528713-338774729660723 +11409927143697-15757404441036 +145718975793308-148045006791963 +108758989044766-108913537716846 +497225205865627-497696644648547 +506802121296256-511843007452313 +63613769122503-68190178828324 +501471864514126-502348453390315 +362757224371869-371694343453311 +103229070500605-103403940640547 +484443073471193-491783260087311 +384857615754871-391132227884521 +86456683794648-87888022769678 +501277005625674-501786928024258 +322419283079195-330769757214938 +214639120715572-217292118959603 +107910444542181-108758989044766 +244526288084416-246901292266192 +300049307357264-301491744508326 +293497932941391-294855901549666 +239713421994880-240154915373051 +102972520195151-103403940640547 +345475268993763-347922672837434 +109260782149885-109617370216541 +234846741281996-235042869991585 +234572239483835-235042869991585 +478590655939622-479993055936532 +525800765093262-527130969692232 +400965986176932-401691889010421 +238169643361847-238936670811391 +3659870102819-9579210318065 +202375944552301-205876396954042 +49177711042139-49177711042139 +84160322907181-85669477462528 +334544930425571-340874780071105 +239367763196823-239713421994880 +345475268993763-347922672837434 +435167760872194-438421390324945 +88374065210316-90282361017819 +435167760872194-438421390324945 +358518392599281-358518392599281 +523739813447364-525157736658109 +534257412281077-534257412281077 +205876396954044-210144966664137 +234846741281996-235314077363408 +515987231565768-520075670866842 +72978626378777-75641956243134 +109260782149885-109878838468670 +192595356650067-196569386910890 +498762675103169-499002133600418 +287555507941658-289216319511713 +112420289168162-116527662920280 +217292118959603-217292118959603 +531045801225249-532381986753164 +103403940640547-104211581332700 +107611051822203-107910444542181 +244526288084415-244526288084415 +11409927143697-11409927143697 +172402346265457-176998982095232 +153513770178181-159388744093090 +498762675103169-499571236343420 +530361363963362-531483269113417 +416563751486851-421411688020067 +501050899249594-501786928024258 +528452800290912-529926766575504 +100982398544566-101147327087488 +453103199271597-457893048411251 +183361395784713-188030623150344 +544715073094800-550878697688545 +546794831410605-550878697688545 +529367412183135-530773948034653 +457893048411253-461922527847052 +474244124672323-478590655939621 +224683487928091-227618634803051 +445211190043980-446838869606531 +53837539586883-57085501630205 +234572239483835-234846741281996 +298135228199796-299659016879570 +106091441510522-106711332354283 +112420289168162-116527662920280 +291604185648252-293025329406781 +395716657652951-396145593335472 +303689717187907-307670519506495 +1210556096410-6852829420907 +82955131746018-84761614177813 +237203447687038-237402810674156 +273532980892752-279501514617625 +428358415261870-428358415261870 +183361395784713-188030623150344 +85330378558206-87034335549718 +493548174887900-493931919355338 +491783260087312-491783260087312 +527603841537498-529004200254332 +498762675103169-499285562943904 +80786390686864-82306298113309 +263125201783110-266246779901745 +102469491187341-102620947820170 +104631067099605-104903823508565 +330769757214939-330769757214939 +354349430225786-358518392599281 +104211581332700-104631067099605 +162057980455184-162057980455184 +522851414400525-524232577400358 +404821843165391-407148238085632 +497929985021076-498223446530046 +236829206791775-237203447687038 +365893569292118-368441675327834 +392372208096403-393250564396725 +397878409296051-398277999682961 +251847724431478-260294771091645 +462975967653181-471398428659349 +103624871426035-103846144422336 +373786710100659-381195128226437 +236568021831276-236829206791775 +103403940640547-103846144422336 +416563751486851-416563751486851 +555740025451077-559419282884614 +407148238085634-410242660079446 +156222751620993-159388744093090 +91542487246678-95890092309110 +426562379240243-428358415261870 +313569404339453-317432688175321 +534257412281077-541433740731218 +87509389258216-89165016102877 +226389362327271-229284272609470 +501277005625674-501786928024258 +394628702944004-395358712604694 +526755445779042-527984897328052 +501471864514126-502348453390315 +81913294088119-83486002027188 +105121334554032-105694322160237 +221541465544016-224062930385509 +282040764662818-289216319511713 +132181665511921-132181665511921 +384857615754870-384857615754870 +296271395259063-297703067613955 +392108756999806-392372208096403 +294649451849151-295989796806433 +303689717187907-309101389988233 +465885843614638-468929397982542 +173797958505398-179674064572918 +234572239483835-234846741281996 +51583995346630-59804047351206 +263125201783110-271029930108700 +292672644929383-293887113798457 +162057980455184-166552204500541 +238416665356049-239132802883773 +524761887918912-526334879358024 +91542487246678-98235869765402 +32287265814727-39356756283317 +297196279996741-298496652659387 +231657373363274-232299388189513 +141081783359266-145718975793307 +228055191796001-231101013122918 +234117168441687-234846741281996 +394628702944004-395358712604694 +394118192439225-394877463113550 + +501292155078636 +29737384906207 +238906703181576 +92163861247313 +249396112626231 +328446193194589 +172065505841500 +477286116586508 +404409499811762 +277426725252502 +183082083118673 +491649084978042 +435929412271336 +418179034295174 +453461496435259 +153331197634076 +409645496033537 +246243414531269 +165312162619398 +232789158206201 +168938678009081 +137057657395324 +22582330845330 +364089737570029 +218623163438848 +400225836619397 +32941811409006 +40105164819589 +219948133116281 +341871639814658 +363158795065533 +194428602615728 +378206730472285 +355908170636824 +334481655977816 +70792665713778 +517982776932015 +354916843845178 +397754506772912 +263645373737038 +540262269259210 +321356283969391 +461999997102774 +305573924969794 +157294979719468 +106855905848184 +495462177722627 +384020423317702 +9253989539332 +320590655671702 +297747373605813 +501041431765656 +41465289954720 +107583394429147 +181551387251145 +337152903580263 +422491228329013 +436913565358419 +126208558908926 +518162868247126 +300250232546250 +157017881852345 +87174759209774 +534493382463162 +470989820838994 +105455969558799 +205622889280247 +166789066092573 +258876460476447 +490993023854876 +11559714362622 +235999922116800 +54486541109459 +367937840380112 +547089333630500 +483873006499447 +150817606398881 +547123868861033 +114298639236927 +346524822903256 +1410113713073 +460038522984834 +229672788401684 +503006631228811 +260548578200942 +40619988131136 +305260315692144 +196411938340862 +388848556029998 +122630706883526 +383819463065209 +469893486151821 +413243227497573 +299781394045507 +319292073030209 +309484079766490 +522283504639591 +227549781685100 +382810391978998 +228496760322156 +129569820779853 +426250750923322 +318077513671630 +349039679642747 +157184550245080 +175362087873015 +167783905212768 +105737725705826 +105081905383799 +3223390023149 +416533994767034 +354492434467609 +450343837689368 +423835146000711 +243498685982830 +105567531100421 +192081518898239 +377587712266140 +524237418368664 +250088323399133 +517992088620447 +216635865822008 +256212760428895 +71229568261514 +327372784254673 +316363588353215 +404703221460815 +290416813337669 +20244522507464 +127067840794771 +427627550057474 +281990104236534 +505424143543493 +294482010377694 +524126806994904 +368734400870179 +249226767927706 +533135118518228 +303816791522348 +185601630644977 +420577613266233 +173141806429914 +432824818395338 +61443316538913 +475243492000383 +515448696533896 +543177545245920 +425170899621384 +218893349521148 +493996396899661 +78004411344407 +510961181970085 +435143172104329 +502696078699252 +122611041868992 +151383835118922 +50824278707889 +357783445456911 +176815225026556 +34667386751013 +197044730665308 +528952681207366 +70097352176828 +462446496020891 +232501392408667 +383108301316983 +177901990307880 +25555809406350 +505199795343179 +481497176438732 +126788178366572 +222508389099659 +306299915363785 +295408102095963 +460540531965255 +71510618273454 +70001548229415 +416930629417151 +141345181450859 +401916161006821 +22974629802369 +208067273247940 +19245535271732 +152519080575565 +257368222160494 +67807125607122 +458349579164657 +322969319041599 +93969220479687 +157823896245908 +560675438215492 +561646811766451 +457986904031101 +5206063576579 +501404244062428 +276135632228853 +525044850082727 +514823281254983 +114532561320576 +349431470533421 +514074688418317 +212384220027991 +308568704822128 +390467234971916 +146368049814596 +356311334599245 +279169003236902 +406568461353488 +338544742100913 +244490522061935 +133780232294933 +309115079025761 +337492326926599 +489192149618430 +433614407460438 +435517223362244 +206519748421544 +163618983996884 +17460036101972 +344910359298941 +20466997442818 +53120265378291 +530350069334923 +73617128287051 +227669666372703 +240306155018047 +396827879447050 +55098566030617 +365257566121245 +348924925975789 +533283800586277 +95092003358776 +120172950033443 +450289992740317 +561925906256694 +361729858822446 +173703136211047 +39749167134911 +406729086167023 +145147968131546 +14503353726214 +298224715853545 +160063084395273 +10746627273002 +114418002455126 +114664218868338 +96509348584175 +232245215429173 +221124155230841 +128133517505256 +92358660322456 +515728798839053 +482997701948537 +198852889847322 +260540423953059 +16522182430899 +200584606120815 +218707186201150 +129336795823053 +283558969632664 +467050606478774 +396238118708702 +166009282278824 +362256787524477 +14823289984060 +508207920690506 +266721897992084 +183641144047388 +105755702693609 +108498431021697 +385713686694725 +353886288729451 +402726612574058 +14540350321260 +188808999725520 +82997442753338 +47970955265490 +370188412024620 +422843593314465 +356566044071558 +460478404620075 +32381292707308 +212894561455610 +47841342730831 +110965122700102 +249531374149092 +109660714936186 +430107228248438 +444367931350216 +271965174565276 +456140335058749 +269893939695662 +307479249925895 +520268531503796 +554244123638262 +231729633525075 +57974774522041 +212653479748877 +205250391042282 +440497324111895 +480742615082854 +316406756956992 +22708978230410 +496923714658678 +49081511335387 +299464129610258 +500075323837096 +520357837973870 +129627859808137 +191789309846445 +315924118304912 +199921837798197 +349713086987126 +103896320733572 +365185761569601 +390234010929125 +641737591959 +412642471194840 +447538417581022 +356029125185340 +483711367024728 +72484076890528 +556661355910 +532915906623241 +186967392235830 +345969579956369 +106175026446266 +114138191924497 +386188661342227 +22511073673934 +556683164651629 +265582277826880 +404468874034943 +234973985591270 +537919064153347 +162010855895596 +167314435759725 +44931102690969 +370134013105977 +216230683735814 +66633999137994 +559328095895900 +317656265208130 +261235381733317 +120407140555108 +36061530164983 +198408020817210 +530507988115880 +517841091321149 +234250762051883 +320206794270616 +382605831214160 +199506509957211 +38091960129071 +271336325098508 +14034484724780 +235171806857770 +438748026252898 +558064711352878 +107965704396235 +63424184126576 +179082139794121 +325396070140954 +323879189179508 +384047626460221 +257921500074249 +8947284916506 +536818305770368 +255115437172514 +167506410788528 +550770472515141 +61764081937999 +331183658963436 +53413048854411 +50011112701311 +280865367214374 +299404812758670 +40848656090519 +138574985720850 +409793923990260 +377531655735996 +178665964017394 +339417169631434 +393766534782947 +81088224824219 +440448324362479 +454135138569553 +242527149321604 +216958539698452 +79850229715644 +343906181733407 +128418042659328 +42251300177615 +248835817396455 +512399231129443 +102600839976303 +414430662265832 +44493277270061 +359567091592900 +195060735488089 +34427274236683 +429299555875153 +280500693591844 +335825345250175 +334320970268995 +240536011805508 +78686736439043 +477905456922346 +206456810241586 +179630988206598 +487073752638393 +228128595822536 +180093829072468 +52789357867457 +210596875973822 +479810936692542 +560633605906467 +164183323734446 +156917950836797 +259900446199111 +150841395698350 +363568431163535 +463879150636946 +274425123826284 +260512933033678 +63049920915036 +102577468817779 +63449568680784 +411359340622027 +326458546716085 +36918154081533 +405259257092415 +238526216579231 +34516505693024 +144081191814334 +37307888101334 +328683103049767 +121264411689037 +347564249511341 +420910929013853 +49827629221345 +124752568714354 +86552435752534 +64802394381370 +45695747562599 +468007392707735 +191812665875951 +79334489349114 +482467933446762 +188771075196956 +37541236793536 +27897614131806 +105431429334895 +412680490250947 +452207822500725 +310317753638005 +235850912905297 +51817065113375 +166711245046748 +508924154667623 +156794396429351 +303172825421660 +355132709366177 +261521104134252 +363537932244898 +333813266971356 +443703277724122 +371651162228593 +172187867018104 +91177767818891 +540383172759377 +381657456293366 +244947172553456 +175193960845955 +447167063234601 +489814564788265 +549996873482634 +144504664063900 +557702605120680 +165911661434295 +221855444588123 +514693656688942 +534798738590126 +242481314659406 +442255413467700 +561707175604 +407259291214618 +357079033579536 +30535254157649 +496374616371160 +94253661772520 +390902968753856 +438811771208691 +496551061589522 +252016332567698 +148949713156139 +320907539667204 +414580008747383 +12803362580408 +432350573200223 +257895038184185 +15821281400167 +465103673998523 +87303599758072 +169635494774874 +330346195681141 +60404189114095 +318312212353217 +287806778757052 +451272532961829 +318439092423422 +218773469268785 +349001756861695 +411515700130153 +27933716138598 +264472966770332 +398440914709722 +537011394104870 +116377009840833 +252981025420504 +209401602479488 +260133910980446 +218678801098938 +462580531594130 +150400501234368 +321571431965759 +121729151972253 +244650904713511 +390358576782128 +213070717044160 +289386609907957 +532254904099726 +17760321713647 +51186260395945 +110952824439410 +47916329616674 +546703087147943 +32359803680389 +760639469319 +274006712450486 +26477900948453 +357216179840045 +4090284369566 +308687320941803 +131434510106764 +239189927427491 +407128141796012 +304642981077816 +499581667511573 +286935146841419 +363059055709333 +507853111710634 +41769094312818 +549649041940205 +282396170858647 +516832958778182 +14096613808350 +126162817941021 +291804670913261 +186823907208892 +26923703713955 +392647278748732 +411985077188768 +431509337138568 +390931395996001 +80798828912771 +400124938830008 +279670782376327 +410006469883633 +353602702444331 +55852531908343 +231223428863891 +438855367250061 +495251508109235 +206211612020949 +543581688882932 +466861506582203 +450615429216558 +170741861978890 +332373420761656 +384831017319478 +415599470843535 +138165416428748 +509311737357006 +561804479528186 +111089222902275 +452800365109398 +349285593423576 +70266780602833 +220095894769575 +282913609080164 +368458870417736 +449365291497685 +550404918242844 +251782559647479 +279731193427449 +484907108956862 +7661454109587 +520524245755441 +416197934760401 +486348853861467 +395535448150283 +427232261862581 +179158529316454 +431835392923185 +475147371224369 +295613399575956 +255415793822156 +74515597501862 +345740540269675 +154219138209924 +226722604666574 +360962192729155 +397592705682704 +428342572475783 +53027399685398 +291400559270091 +104843475845499 +139231206012327 +288427014140909 +224767607608376 +299216335718785 +478835522145288 +562111440190386 +310836480479757 +355661195655983 +86700039676784 +537373096866618 +381121905183810 +119503202473521 +196889437415754 +198439669818787 +386952673653434 +303329360539015 +210872733725951 +233459799749246 +422518470661829 +539106565879525 +387500914458607 +148728191744145 +40194469380710 +167452915144786 +482876673410824 +94763065008377 +280526677066472 +30988580390638 +347413113194151 +179910011592788 +558380466588344 +429821352284784 +554206587617213 +514645972056451 +167419593650549 +475869733316805 +367405162901833 +481820088476117 +223025261407835 +160591004282379 +518259010813936 +276207300283869 +70216543037908 +452665727520048 +490009545165586 +258369098823277 +162759028497049 +438397506912415 +562044497530197 +452480784082074 +487734003581298 +215894924398688 +303894373623968 +203590587453028 +352502952854792 +153657795238173 +331171025090935 +559899080415440 +490076607871361 +469738546839189 +512494377701014 +147658416023916 +31236101307168 +31340025387024 +453953204901183 +431254282219669 +15801966154577 +335630821534806 +108798480431181 +430684246092148 +493795770058596 +130439495858448 +93759889190794 +79038720845433 +182849614650131 +161906885160105 +536845344915904 +346368032151659 +90999323233671 +410178828121003 +324643179469130 +361318579222068 +188923602383994 +557366391431308 +58632025395318 +315141713794239 +56053759946368 +147274345295217 +364835799301448 +160995941223261 +98045403921191 +213603333609437 +160266416886179 +508045797946970 +342139119270070 +139034812119870 +157857634127622 +413769488535945 +116847372118343 +468050216535239 +40410104073471 +235937189235712 +462224782179386 +411126096048808 +143202325262688 +181884854783171 +33109163478278 +494133669902878 +389952764679482 +111281927161098 +378327189469023 +281048631033092 +186853119119151 +551387299123328 +120705337470707 +478501303571362 +430444522841170 +81798452066498 +549705493586200 +60413061501783 +244357118706739 +89575115954488 +209675025328996 +458441200416882 +167024356041950 +243107748521123 +79341281402154 +443656897852005 +212436240479871 +168824836650372 +134617609879995 +79084066755703 +60116247281350 +515434320057695 +12986973077988 +532968566406889 +70262745286531 +88451944359591 +164821045956820 +193442282415613 +150975665166079 +241958615395440 +472440033222624 +129216245494374 +440716089813555 +504438123488843 +62687833605233 +462090178644178 +10268491081539 +347421536897858 +259934577627446 +519963639791026 +281117498965350 +289408513849422 +19837385128042 +502549717245402 +448541633206940 +200801737153000 +171326449245758 +362023228570153 +16602639971451 +248067748192003 +39771382459758 +176504719797124 +318714770796728 +88880651395830 +220261112492090 +133582963269948 +244176097234107 +359367585517458 +72990690864714 +339274020273691 +224743905277212 +460368988886371 +487094644533607 +206433571522784 +324804597989049 +332996115830783 +286578787449395 +254418221919636 +320044585750492 +105554651947288 +246498878935123 +232610552384844 +219129755407537 +123254094469978 +266126581662236 +128190191215383 +441303538047128 +183321294903184 +251837691660138 +397561228744992 +343317651509921 +28224768925348 +9102329019795 +357543315217817 +534068128768220 +268124286742220 +305248988653268 +534255462960021 +556084906724589 +396027225891555 +231976324098425 +201076276964690 +423797315638362 +206055069067523 +170347504071787 +365824346409811 +148246158835942 +147180811295386 +300887918236856 +383875712380845 +386687886183235 +460855793899479 +38158215532919 +64460864640005 +124160116331656 +11916816734475 +430356051689677 +259275693368568 +19766723433352 +466176663065523 +151823510224053 +229645875317372 +257835370797183 +414131843334666 +528455484857520 +506975065507992 +232235626690485 +256989213440221 +348620717221751 +212287221340260 +26310282992812 +190545947295358 +239319614566816 +203988439985445 +147290059086678 +301615410055305 +36296144109247 +393927145627627 +335412426678441 +93845754544955 +355934610052716 +74124822677778 +308913922235648 +301113717464142 +512404974262690 +197317933840592 +536614572827930 +123444179550153 +482180074434710 +501057761071670 +377499071903273 +70567514178004 +353725670995100 +143490460947717 +66663590747832 +222315479118691 +397610354293936 +274556690350417 +271305417517187 +280406429455367 +191711849299610 +214326354557105 +561890731033682 +15149960795536 +288035942207314 +306855289168476 +280798940527432 +439251276272658 +541432956084795 +452515174573287 +413718185577492 +514026734221714 +177121185481326 +271031763678400 +522326716767985 +468443138737379 +74485157056453 +150980825551071 +365472565693361 +293960521275356 +36113794563403 +446035733671362 +443969993695602 +251158432062274 +147025965911389 +75315165121815 +548128054964638 +316399010120257 +430170526346910 +75598069639512 +60778192785409 +24283258455027 +239230413188052 +230804443303528 +263597441896724 +167289395632284 +510645833255895 +193775549770295 +5671473528571 +201739270646341 +483255160608192 +438630444043993 +252518672462185 +549194109654497 +70627904914240 +514003763927035 +279961921436683 +325100579305936 +275962102437973 +550569884281993 +240508531456399 +535912204520902 +422388366313252 +258764601151992 +518979989936302 +483698560757738 +7431990925751 +463453949818764 +421918554412240 +317750523590995 +380691768717258 +395017035221043 +201876656535475 +128310447351323 +152360848864559 +353744374931070 +105142285703720 +313631049823429 +221302220622244 +449424389190548 +41809740936337 +345135732041620 +340155430920099 +81720400175512 +267575555440187 +85661238441924 +445932931880821 +436062213802360 +410705769590909 +387802272045950 +76011785648728 +484247695755035 +346059514890633 +158014039344777 +58584984760551 +204973472373491 +359545996690331 +225578675352022 +37997059778985 +155366867836275 +558124765607036 +340613895371483 +526214891057593 +99055223145280 +9986136250794 +194346786088413 +259681918712500 +167311464015388 +30937884332875 +357036483421640 +288981080470009 +340190938293792 +153129204052864 +393853832130078 +72191500367112 +174628138437040 +313585240576558 +394771066278776 +191857648973145 +188085249517205 +134836250213155 +218346450986505 +490785562968431 +238887317503097 +142776020282557 +381538894703043 +233481695589489 +541371403099869 +290991203138041 +14748699142401 diff --git a/lib/day5.ml b/lib/day5.ml new file mode 100644 index 0000000..8c1500a --- /dev/null +++ b/lib/day5.ml @@ -0,0 +1,93 @@ +let split_empty_line lines = + let rec split acc = function + | [] -> (List.rev acc), [] + | "" :: xs -> (List.rev acc), xs + | x :: xs -> split (x::acc) xs + in + split [] lines + +let input = Reuse.split "inputs/day05.txt" '\n' + +let create_ingredients lines = + List.map (fun x -> int_of_string x) lines +let create_ranges lines = + let splits = List.map (fun line -> String.split_on_char '-' line) lines in + List.map (fun line -> (int_of_string (List.nth line 0) , int_of_string (List.nth line 1))) splits + +let is_fresh number ranges = + let valid_ranges = List.filter (fun (x,y) -> number >= x && number <= y) ranges in + if List.length valid_ranges > 0 then 1 else 0 + + +let solve_part1 inputs = + let (first, second) = split_empty_line inputs in + let second = List.filter (fun x -> x <> "") second in + let ingredients = create_ingredients second in + let ranges = create_ranges first in + List.fold_left (fun acc entry -> acc + (is_fresh entry ranges)) 0 ingredients + +let update_range (x, y) ranges = + List.fold_left (fun (u1, u2) (t1, t2) -> + Printf.printf "Updating range step (%i, %i) with (%i, %i)\n" u1 u2 t1 t2; + if t1 = u1 && t2 = u2 then (u1, u2) + else if u1 > t2 then (u1, u2) + else if u2 < t1 then (u1, u2) + else if t1 <= u1 && t2 >= u2 then (0,0) + else if t1 >= u1 && u1 <= t2 then (u1, t1 - 1) + else if t1 <= u1 && t2 >= u1 then (t2 + 1, u2) + else (u1 ,u2) + ) (x, y) ranges + +let rec update_ranges to_process updated_ranges = + match to_process with + | [] -> updated_ranges + | (x, y) :: xs -> + let (u1, u2) = update_range (x, y) xs in + Printf.printf "Updating range: (%i,%i) to (%i, %i)\n" x y u1 u2; + update_ranges xs ((u1, u2) :: updated_ranges) + +let solve_part2 inputs = + let (first, _) = split_empty_line inputs in + let ranges = create_ranges first in + let updated = update_ranges ranges [] in + let updated = List.filter (fun (x,y) -> x + y <> 0) updated in + List.fold_left (fun acc (x, y) -> acc + (y - x) + 1) 0 updated + + + +let day5_part1 : int = + solve_part1 input + +let day5_part2 : int = + solve_part2 input + +module Tests = struct + let test_input = "3-5 +10-14 +16-20 +12-18 + +1 +5 +8 +11 +17 +32" + + + + let run_tests () = + let test_lines = String.split_on_char '\n' test_input in + + let part1_result = solve_part1 test_lines in + let part2_result = solve_part2 test_lines in + if part1_result <> 3 then + failwith ("Day 5 Part 1 test failed: expected 3, got " ^ string_of_int part1_result); + + if part2_result <> 14 then + failwith ("Day 4 Part 2 test failed: expected 14, got " ^ string_of_int part2_result); + + Printf.printf "All day 4 tests passed!\n" +end + +let () = Tests.run_tests()