diff options
-rw-r--r-- | hsolve/FSu.hs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/hsolve/FSu.hs b/hsolve/FSu.hs index 1bd250a..1d0eea3 100644 --- a/hsolve/FSu.hs +++ b/hsolve/FSu.hs @@ -10,7 +10,7 @@ import Data.STRef type Value = Int -- Sudoku value type Index = Int -- Sudoku index -type Arr s a = STArray s Int a +type Arr s a = STUArray s Int a data State s = State { stateMark :: Arr s Bool, stateResults :: STRef s [[Maybe Value]] } @@ -54,7 +54,7 @@ tryAll arr !i (v:vs) st = do -- assumes the considered position is empty getPoss :: forall s. Arr s Value -> Index -> State s -> ST s [Value] getPoss arr i st = do - fillArray mark 0 8 True + fillArrayBool mark 0 8 True goRow (rowOf i) 0 goCol (colOf i) 0 goBlock (blockOrigin (blockOf i)) 0 @@ -107,7 +107,7 @@ isValidBlock arr b st = indexSetNoDups arr [blockOrigin b + 9 * y + x| y <- [0.. indexSetNoDups :: forall s. Arr s Value -> [Index] -> State s -> ST s Bool indexSetNoDups arr set st = do - fillArray mark 0 8 False + fillArrayBool mark 0 8 False applyInMark set where mark = stateMark st @@ -124,11 +124,9 @@ indexSetNoDups arr set st = do then return False else writeArray mark v True >> applyInMark is -fillArray :: Arr s a -> Int -> Int -> a -> ST s () -fillArray arr !i1 !i2 v - | i1 <= i2 = do - writeArray arr i1 v - fillArray arr (i1 + 1) i2 v +fillArrayBool :: Arr s Bool -> Int -> Int -> Bool -> ST s () +fillArrayBool arr !i1 !i2 v + | i1 <= i2 = unsafeWrite arr i1 v >> fillArrayBool arr (i1 + 1) i2 v | otherwise = return () rowOf :: Index -> Index |