Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- > module Sudokus where
- > type Sudoku = [Integer]
- if there are no more 0s then we are all done!
- > solved s = 0 `notElem` s
- Replace the 0 by the move you are making
- > choose s (cell, mov) = zipWith choose' s [0..]
- > where
- > choose' digit index | cell == index = mov
- > | otherwise = digit
- > choices s = zip (repeat zeroCells) (posDigits s zeroCells)
- > where
- > zeroCells = case filter isZero (zip s [0..]) !! 0 of
- > (0, index) -> index
- > where
- > isZero (digit, index) = digit == 0
- these need to probably be edited for squig:
- posDigits are the digits which are not in a cell already
- > posDigits s cell = [digit | digit <- [1..9], free digit]
- > where
- > free digit = digit `notElem` [s !! x | x <- indices cell]
- > indices n = col n ++ row n ++ box n
- > col n = take 8 [x | x <- [n `mod` 9, n `mod` 9 + 9 ..], x /= n]
- > row n = take 8 [x | x <- [n - n `mod` 9 ..], x /= n]
- > --box n = [x+y | x <- rows, y <- cols, x+y /= n]
- > box n = findBoxIndexes n makeSquigelyBoxes
- > where
- > rows = take 3 [n - n `mod` 27, n - n `mod` 27 + 9 ..]
- > cols = take 3 [n `mod` 9 - n `mod` 3 ..]
- > squ1 = [0,1,2,9,11,18,20,27,29]
- > squ2 = map (+3) squ1
- > squ3 = map (+3) squ2
- > squ4 = [10,19,28,36,37,38,46,55,64]
- > squ5 = map (+3) squ4
- > squ6 = map (+3) squ5
- > squ7 = [45,47,54,56,63,65,72,73,74]
- > squ8 = map (+3) squ7
- > squ9 = map (+3) squ8
- > makeSquigelyBoxes = squ1 : squ2 : squ3 : squ4 : squ5 : squ6 : squ7 : squ8 : squ9 : []
- > findBoxIndexes _ [] = error "There was a problem"
- > findBoxIndexes a xs = filter (a /= ) $ head $ filter (a `elem`) xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement