Part 1 done

This commit is contained in:
pingu committed 2024-12-09 10:26:30 +01:00
1 parent 27e4f9102b
commit fb98633a56
3 files changed
+30 -6

No files matched your search

+1
View File
@@ -102,6 +102,7 @@ executable 9
-- other-extensions:
build-depends: base ^>=4.18.2.1
, split
, extra
hs-source-dirs: app
default-language: GHC2021
executable 10
+28 -6
View File
@@ -2,14 +2,36 @@
module Main where
import Data.Functor
import Data.List
import Data.List.Extra
parse = undefined
data ℜ where
None :: ℜ
Num :: Int -> ℜ
deriving Eq
solve1 = undefined
instance Show ℜ where
show None = show '.'
show (Num n) = show n
solve2 = undefined
parse :: String -> [ℜ]
parse s = zip [0..] (trim s) >>= \(i,a) -> replicate (read [a]) (if even i then Num (i `div` 2) else None)
sort1 :: [ℜ] -> [ℜ]
sort1 s
| None `notElem` s = s
| otherwise = case last s of
None -> sort1 $ init s
n -> sort1 $ takeWhile (/= None) s ++ [n] ++ drop 1 (dropWhile (/= None) (init s))
sort2 :: [ℜ] -> [ℜ]
sort2 = undefined
solve :: ([ℜ] -> [ℜ]) -> [ℜ] -> Int
solve f s = let fixed = (\(Num n) -> n) <$> f s in
sum $ zipWith (*) fixed [0..]
main :: IO ()
main = readFile "inputs/9" <&> parse >>= \i ->
print (solve1 i) >>
print (solve2 i)
main = readFile "inputs/9.example" <&> parse >>= \i ->
print (solve sort1 i) >>
print (solve sort2 i)
+1
View File
@@ -0,0 +1 @@
2310441322937274193533567132116985851720723880225457294666988817398853303458531311938764274939253940144297616025713953814412577520122351316213684785413417648697127030154099593678525080189022667151488198741459691764604519914991623289279988591938863585533389879692217280498247292847127640419462741393894849876067622962868120705597412175321013585880365086663471114844258823172169836758626362763443665020483338625374133167796091757735961783509526982228378374769543348340783868404613623753267984896224371850665819691756583146395210229344576454599386171496638798285478488178735014932081196956683260921769317588476076293732834132295632139588586814694293844379436433176717833127936570669120422864201090101459173914909869182543707173721114537948396365317476902443257391778776703171957249624558582841249277957574648765987059782970852855521041472452292482127925719073245667939388815494661062776242127319572093634783643766234262716083171968135287611916947246609167574793535545358469244314819478653596192448713455995080965165488815744755953650523044135427661638472264228519921631245515153421217989151867697173844524684419576870651939403095935716773140859290512531974580958181648416792461733121187064272562323639617252646573769821158268355874808814118756232175521278437270905451582050792710538357715573305359483948327997755012298665353662792538457421994843385848929349632587627772876454383612637227826581842669542265506130879436548729838132724822482178916867799619301549241993329144169666275273627835649375266261817789689459159175706712776885683388537378812638455120692093619770353684788958935640186454953245368033397876353588523498667465268423985756461424802264856228313050258713403366203720228093921445791199168750715698132333852885252120791633617118876376844250577060969816896966424349364618453144818557816516915586686012677943187034139993285975515710756180953632688691958110211219507528912275236684755725244584377243723964103995676463731877598420931713111633955244842734748248704477344032912950903234619268715744712848214160175720334835648870434944592175795024651870622622241197309498737040725825918945448047639145276260374263596253839940653223836220474098831946297345549687749431748022419785886722141586262894152085268556292296382983768544321048844865227572883031289025391393844961689753551164702182422237969294682587831863108317212515508315435541669315618724409234262924996297953491902580464746379117837256649959299296481423758513249830239320795389489982237592252031226492247234274890541627606073935370828951862689893822339053178620691722345372527113847264817274843696242733621021153840843284534522685127148933374716182615596935354320881970104899368270296276758183642249721377935640838878363334676964942422375938566820561177215171666312364097803616278744765329715443539538126113671447672920718981391569322724368522927680616652634122604640597150477587756872605721825761307716595970233850377293178832543087639680373823424741367699576831995989961143687857409948904982804091486995673072846291322683867355621118156382562540861981671915961339868085483662982191396335817718639277966076766493485768981612929939942047734444403566283389373558383283955563636629781717464686529398741234339136984514687642971163129695178448311954651419485389559869738076368261673923392942245957516631783615334923657429861555634475256683312732257427313688696997248890576743506118681362191095549494746816399924903652151912688782282139102166898144733448837490635852558586143446863087563356228646131349241841689396745823539324553127163533907455893715635111519771493549863092497148361893748693316654337195676242223734817463364195236426772036691898673368708833365183996324818167125414898942637259106511147253181992749920175147953279515720174051582569434839267044109428984854523686543872439363956812788551348966359135914044903899542186636686545775768428452571452478791128917165193758558192475116376711661761279664323745909879298691799187731312588288212232814396931593436845769229936489822883299741845536388638616252739298583054839361836169158742295564759693226983834347723729266048162598957136377422316640324317256281127384387066996831792448733226759893848090866699818258359824758595801363271914196574469721675514676112243281572632529786329922231698546675647680813498985079572542998028882637806654899581635364137355157565418075228653526026813780375051931753371141974439427140473094865316771199132073182587163425922719337121958976585075757943883237737569278666152153607079679029931059673135795394148263987061731645428294534831118759413464877867585810285855607282747677287311573764212833721374214623119860863049116174716579968596659813844138585598186826713658253140969734664783514183482510713743807287212081239774631864374215578973997442373454628266435015437283993759594686813598255171188333542048256549649917781020181818573526901680123061103170762128911720506725747238727692353930286593964789934011117316205424482766396717514481187417157983294520317298399778603037897151993660273350282379286218958727189469452130528033399532143031744451341743166Line truncated