Parallelize next guess calculation
This commit is contained in:
parent
a97a4cfa08
commit
2a9f7c6f6b
2 changed files with 6 additions and 4 deletions
|
|
@ -23,6 +23,7 @@ dependencies:
|
||||||
- base >= 4.7 && < 5
|
- base >= 4.7 && < 5
|
||||||
- containers
|
- containers
|
||||||
- haskeline
|
- haskeline
|
||||||
|
- parallel
|
||||||
- text
|
- text
|
||||||
- transformers
|
- transformers
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,12 @@ module Jotto
|
||||||
, nextGuesses
|
, nextGuesses
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.List
|
|
||||||
import Data.Char
|
import Data.Char
|
||||||
|
import Data.List
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import Control.Parallel.Strategies
|
||||||
import qualified Data.Set as S
|
import qualified Data.Map as M
|
||||||
|
import qualified Data.Set as S
|
||||||
|
|
||||||
data Guess = Guess String Int
|
data Guess = Guess String Int
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
@ -160,7 +161,7 @@ nextGuesses g =
|
||||||
lpwords = M.map length $ pwords
|
lpwords = M.map length $ pwords
|
||||||
pclasses = M.keysSet pwords
|
pclasses = M.keysSet pwords
|
||||||
options1 = M.assocs $ allWords g
|
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
|
options3 = sortOn (\(_,_,w) -> length w) options2
|
||||||
options4 = sortOn (\(s,_,_) -> S.member s pclasses) options3
|
options4 = sortOn (\(s,_,_) -> S.member s pclasses) options3
|
||||||
options5 = sortOn (\(_,c,_) -> c) options4
|
options5 = sortOn (\(_,c,_) -> c) options4
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue