1

I am making a sudoku solving program and I have a potentialNbrsAt function that gets the numbers that could be at position x y.

Now, I am trying to get the intersect of each lists of potential numbers in a column. Something like the onlyOnePlaceForNbrInCol function bellow.

Code:

potentialNbrsAt :: Int -> Int -> Sudoku -> [Int]
potentialNbrsAt x y sudoku = intersect rowMissingNbrs $ intersect colMissingNbrs sqrMissingNbrs
                where rowMissingNbrs = getMissingNbrs $ getRow y sudoku
                      colMissingNbrs = getMissingNbrs $ getCol x sudoku
                      sqrMissingNbrs = getMissingNbrs $ getSquare squareIndex sudoku
                      squareIndex    = 3 * (y `div` 3) + (x `div` 3)

onlyOnePlaceForNbrInCol :: Int -> Int -> Sudoku -> Bool
onlyOnePlaceForNbrInCol colIndex nbr sudoku = -- What goes here? Some pointers please???

I think onlyOnePlaceForNbrInCol should, at some point, call potentialNbrsAt with each numbers from 0 to 8 as an argument for y. Telling me how to do this would greatly help.

1
  • PS: whenenver the number 9, or the div operator, occur in a Sudoku solver, it shows insufficient modelling: the grid does not have two dimensions (9x9), but four (3x3x3x3). In German, "die Anschauung ist auch oft der Feind des Verständnisses." Commented Jun 19, 2014 at 19:08

2 Answers 2

1

What about [ potentialNbrsAt x y sudoku | y <- [0..8] ] ? This gives you a list of all the results for such values of y.

Sign up to request clarification or add additional context in comments.

1 Comment

I did not expect it could be so easy. Thx!
1

So you're trying to determine whether all of the numbers [0..8] fulfill a given predicate.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.