Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab 5 #5

Open
BertLisser opened this issue Oct 12, 2018 · 0 comments
Open

Lab 5 #5

BertLisser opened this issue Oct 12, 2018 · 0 comments

Comments

@BertLisser
Copy link

BertLisser commented Oct 12, 2018

subgridInjective :: Sudoku -> (Row,Column) -> Bool
subgridInjective s (r,c) = injective vs where
   vs = filter (/= 0) (subGrid s (r,c))

consistent :: Sudoku -> Bool
consistent s = and $
               [ rowInjective s r |  r <- positions ]
                ++
               [ colInjective s c |  c <- positions ]
                ++
               [ subgridInjective s (r,c) |
                    r <- [1,4,7], c <- [1,4,7]]

The call of function subgridSecondInjective is missing in consistent.
Ex. 2
The following code is Okay

constraints :: Sudoku -> [Constraint]
constraints s = sortBy length3rd
    [(r,c, freeAtPos' s (r,c) totConstrnts) |
                       (r,c) <- openPositions s ]

but why not refactor the code

prune :: (Row,Column,Value)
      -> [Constraint] -> [Constraint]
prune _ [] = []
prune (r,c,v) ((x,y,zs):rest)
  | r == x = (x,y,zs\\[v]) : prune (r,c,v) rest
  | c == y = (x,y,zs\\[v]) : prune (r,c,v) rest
  | sameblock (r,c) (x,y) =
        (x,y,zs\\[v]) : prune (r,c,v) rest
  | sameblock2 (r,c) (x,y) =
        (x,y,zs\\[v]) : prune (r,c,v) rest
  | otherwise = (x,y,zs) : prune (r,c,v) rest

I see you understand this, but you are on the half way.

Exercise 4
Good. Only unnecessary complicated code.

ex4_21 :: Int -> IO ()
ex4_21 n = ex4_22 n False 0 emptyN emptyN emptyN

ex4_22 :: Int -> Bool -> Int -> Node -> Node -> Node -> IO ()
ex4_22 _ False 1000 _ _ _ = do
  print("No sudoku found")
ex4_22 n False c _ _ _ = do
  print("Try")
  print(show c)
  print("/1000")
  r <- genRandomSudoku
  bs <- randomize [0..8]
  let x = eraseBs r (take n bs)
  temp <- genProblem x
  ismin <- isMinimal temp
  ex4_22 n ismin (c+1) r x temp
ex4_22 n True c r x temp = do
  showNode r
  showNode x
  showNode temp

Exercise 5
The question was to generate NRC sudokos's without empty blocks. Thus the code can then be much simpler. But the remark is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant