Parallelize next guess calculation

This commit is contained in:
Joscha 2018-09-20 19:05:48 +00:00
parent a97a4cfa08
commit 2a9f7c6f6b
2 changed files with 6 additions and 4 deletions

View file

@ -23,6 +23,7 @@ dependencies:
- base >= 4.7 && < 5
- containers
- haskeline
- parallel
- text
- transformers

View file

@ -21,11 +21,12 @@ module Jotto
, nextGuesses
) where
import Data.List
import Data.Char
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import Control.Parallel.Strategies
import qualified Data.Map as M
import qualified Data.Set as S
data Guess = Guess String Int
deriving (Show)
@ -160,7 +161,7 @@ nextGuesses g =
lpwords = M.map length $ pwords
pclasses = M.keysSet pwords
options1 = M.assocs $ allWords g
options2 = map (\(set, w) -> (set, worstCase set lpwords, w)) options1
options2 = parMap rdeepseq (\(set, w) -> (set, worstCase set lpwords, w)) options1
options3 = sortOn (\(_,_,w) -> length w) options2
options4 = sortOn (\(s,_,_) -> S.member s pclasses) options3
options5 = sortOn (\(_,c,_) -> c) options4