-- import Data.Ord
import Control.Monad.Reader
import Control.Lens hiding ((<|), (|>), (:>), (:<), indices)
+import GHC.Generics (Generic)
import Control.Parallel.Strategies
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
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
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]