split out some map stuff

This commit is contained in:
Quinten Kock 2021-12-20 14:03:35 +01:00
parent fbf5324a9d
commit bf1c371137
1 changed files with 2 additions and 1 deletions

View File

@ -30,7 +30,8 @@ next :: Algorithm -> Image -> Image
next algo (Img def diff) = Img (newDefault algo def) newDiff where
nonDefault = foldr (\(x,y) -> insertManyWith (++) (neighs x y)) M.empty diff
neighs x y = map (\i -> ((x-1 + i `mod` 3, y-1 + i `div` 3), [i])) [0..8]
calcNonDef = M.filter (/= newDefault algo def) $ M.map (\ns -> algo A.! binToDec (nonDefToNum ns)) nonDefault
known = M.map (\ns -> algo A.! binToDec (nonDefToNum ns)) nonDefault
calcNonDef = M.filter (/= newDefault algo def) known
nonDefToNum ns = map (\i -> if i `elem` ns then not def else def) [0..8]
newDiff = M.keys calcNonDef