X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-22.git;a=blobdiff_plain;f=advent19%2FMain.hs;fp=advent19%2FMain.hs;h=25f608a6eb6675bb7a6c2f741c3161a70987280f;hp=7fe03159c679cabf2c5a6244cbcb3d8130d52ed0;hb=89eb500db478502b125606aa4ffbf8c2cc515ddf;hpb=7556dfa39ef3eec2bc5e55ff2cfaad101a6cfb5f diff --git a/advent19/Main.hs b/advent19/Main.hs index 7fe0315..25f608a 100644 --- a/advent19/Main.hs +++ b/advent19/Main.hs @@ -19,6 +19,7 @@ import Data.Maybe -- import Data.Ord import Control.Monad.Reader import Control.Lens hiding ((<|), (|>), (:>), (:<), indices) +import GHC.Generics (Generic) import Control.Parallel.Strategies import Control.DeepSeq @@ -27,7 +28,9 @@ import Control.DeepSeq -- pattern xs :> x <- (Q.viewr -> xs Q.:> x) where (:>) = (Q.|>) data Resource = Ore | Clay | Obsidian | Geode - deriving (Show, Eq, Ord) + deriving (Show, Eq, Ord, Generic) + +instance NFData Resource type Collection = MS.MultiSet Resource @@ -45,7 +48,7 @@ data SingleSearchState = SingleSearchState makeLenses ''SingleSearchState instance NFData SingleSearchState where - rnf a = a `seq` () + rnf (SingleSearchState a b) = rnf a `seq` rnf b `seq` () data Agendum s = Agendum { _current :: s @@ -109,7 +112,15 @@ part1 blueprints = sum [n * (MS.occur Geode (r ^. resources)) | (n, r) <- result where results = [ (n, _current $ fromJust $ runReader searchSpace (TimedBlueprint blueprint 24 (robotLimits blueprint)) ) | (n, blueprint) <- blueprints ] :: [(Int, SingleSearchState)] robotLimits bp = M.foldl' MS.maxUnion MS.empty bp - +-- part1 blueprints = sum [n * (MS.occur Geode (r ^. resources)) | (n, r) <- pResults] +-- where -- results = [ (n, _current $ fromJust $ runReader searchSpace (TimedBlueprint blueprint 24 (robotLimits blueprint)) ) +-- -- | (n, blueprint) <- blueprints ] :: [(Int, SingleSearchState)] +-- -- pResults = parMap rdeepseq id results +-- -- pResults = (fmap runABlueprint blueprints) `using` parList rdeepseq +-- pResults = (fmap runABlueprint blueprints) `using` (parList rdeepseq) +-- runABlueprint (n, blueprint) = (n, _current $ fromJust $ +-- runReader searchSpace (TimedBlueprint blueprint 24 (robotLimits blueprint)) ) +-- robotLimits bp = M.foldl' MS.maxUnion MS.empty bp part2 :: [(Int, Blueprint)] -> Int part2 blueprints = product [MS.occur Geode (r ^. resources) | r <- pResults]