diff --git a/inputs/2024/10.txt b/inputs/2024/10.txt new file mode 100644 index 0000000..286d3ba --- /dev/null +++ b/inputs/2024/10.txt @@ -0,0 +1,57 @@ +212345410210987621217890789890121034565442100125671056710 +200176761223670130306721698761210125471233693234982567891 +129289872334543245405432547654300276980344780126783456432 +038378969455698236912301238963211080187655693210695432569 +347432358766780147872898347876102391995040544589543521278 +456521243765469056321783210985989452876121235674512670569 +569010342894378765430654781234676543105431230123601789432 +878765401345219878345101698104569689298760345678765698901 +987871211216706789236782567665438776387654876659834217876 +856980100301893472121893432674321065410148987789323109845 +341213221298742345090898321789812764321039845654010256730 +210304378345651016782127100698903854523128734503765340321 +305445469098578727890036234567814923014509658712894321434 +416996954107689656781245898410345017877612549603401234323 +787887873256210545672012367321276676968233438556510965412 +696788980341011234543032456210987589859142123467656876701 +012697891232567849432141045108765412348054010198987655832 +763546321063458938543256036789012309878767198767810765910 +854435417654367867600167127678101210769898185656521894321 +945421308743216543214328998543232125658121034343433443212 +836710769034202398765011056760187034341030128765012534301 +327897854123101450127652347891298743210345689434547643212 +010898943030210763238943219782345646556776776521898756101 +898701034321347894567652308763201237649889889430189657810 +787652122134956238765641207454100348532794324321054346921 +896343043045840149454100012389019659431245010198761234430 +743214104556729450363267823478328760120356521082120123445 +125905234676518761278954954565405892102347436781034016596 +034876546787609687634543069676216743401958945698765407687 +345954434894514598527652178985345434567867010789896328778 +216763320123223423418701201234987101109798123478787819669 +307812018983123010509010110125676432238787234567698904550 +898900867654004327696327898006512343445676543234367803341 +714321978103215018987436567217009854232785450145236512232 +105497869289346787676503454398123767101090367096145210103 +216786454376549894521012345687634998256981278987054334565 +323445210865034743432301478710545877347801209678981021076 +434134348992125623245696589329014566467874314567832987985 +985012349887610014132787103458123487216965423050013456234 +876123456766521165001696212367870198103876302141123442112 +765034300125433674300105123798965287212963218932033230003 +052343212334894789212234037897234378733454367898144101894 +141256103456763210698210548782110569123765454727655432785 +230987232345854324782345699654023457014894325410766745696 +678796341078983105691056789503432128985601216321899874587 +569569478876803234528945093412351012676876307839782103091 +454478569945012343217854112328945401068985410988789232110 +123387654035219445306543201007876312345698523421654378901 +003298743124308556789801123216981235430785654530565467432 +210109632265467643007652014567800896521238703691454876543 +341234501256787632118743112310712987450349812782363989692 +478981987123895678729652105425673456100456701432672176781 +569210896054396569434501876734980143291456012341089065760 +354321345465787454303410969803965234582387345456543254854 +210983230376610341212823457812874345673296216967632103923 +123672121287523200123981046922123216780125407878921212310 +034561012898430112345672345451034301691012398761010123421 diff --git a/solutions/solutions.cabal b/solutions/solutions.cabal index 5eeeb8a..aced472 100644 --- a/solutions/solutions.cabal +++ b/solutions/solutions.cabal @@ -1157,3 +1157,8 @@ executable sln_2024_09 import: day main-is: 2024/09.hs build-depends: array, containers + +executable sln_2024_10 + import: day + main-is: 2024/10.hs + build-depends: array diff --git a/solutions/src/2024/10.hs b/solutions/src/2024/10.hs new file mode 100644 index 0000000..37a3c58 --- /dev/null +++ b/solutions/src/2024/10.hs @@ -0,0 +1,49 @@ +{-| +Module : Main +Description : Day 10 solution +Copyright : (c) Eric Mertens, 2024 +License : ISC +Maintainer : emertens@gmail.com + + + +>>> :{ +:main + "89010123 +78121874 +87430965 +96549874 +45678903 +32019012 +01329801 +10456732 +" +:} +36 +81 + +-} +module Main where + +import Advent (arrIx, getInputArray) +import Advent.Coord (Coord, cardinal) +import Advent.Search (dfs) +import Data.Array.Unboxed (UArray, (!), assocs) + +-- | >>> :main +-- 778 +-- 1925 +main :: IO () +main = + do input <- getInputArray 2024 10 + print (part1 input) + print (part2 input) + +part1 :: UArray Coord Char -> Int +part1 a = length [() | (start, '0') <- assocs a, i <- dfs step start, a ! i == '9'] + where + step x = [y | y <- cardinal x, Just (succ (a ! x)) == arrIx a y ] + +part2 :: UArray Coord Char -> Int +part2 a = length [() | (start, '0') <- assocs a, (i, _) <- dfs step (start, []), a ! i == '9'] + where + step (x, xs) = [(y, x : xs) | y <- cardinal x, Just (succ (a ! x)) == arrIx a y]