but this only checks if 1-9 are members of the lists, not if they're on the same position in different lists.

I had the idea to use this function:

fun poslist xs n = map (fn x => List.nth (x , n)) xs;

(the function poslist is supposed to return whatever is in position n of the list xs, so I can isolate the individual lists in the char list list), but since poslist returns a char list rscheck can't work with it as it needs a char list list.

1 Answer
1

Your rscheck method just checks whether one of the rows is equal to [#"1",#"2",#"3",#"4",#"5",#"6",#"7",#"8",#"9"]. What it should do is check that all the rows contain the numbers in any order. Once you fix that you can solve the rest of the problem as follows:

The easiest way to check whether a matrix is a valid sudoku solution is to use your rscheck function on it, then transpose it (i.e. switch its rows and columns) and then use your rscheck on the transposed matrix. If it returns true both times, it's a valid sudoku solution.

To transpose the matrix you can either translate this OCaml code to SML, or simply use your poslist function for all indices from 0 to 8.

Since I don't know OCaml translating it might be a little hard. I can use poslist but since it returns a char list and rscheck works with a char list list I'm not entirely sure how to work this
–
GeorgeWChubbyOct 23 '10 at 15:53

@George: Right, it returns a char list. So if you call it with the indices from 0 to 8, you'll get 9 char lists. If you put those in a list, you'll have a char list list.
–
sepp2kOct 23 '10 at 16:04

How do I do this? I thought using @ would work, but this just makes a single char list. Do you have any idea how to make a char list list?
–
GeorgeWChubbyOct 23 '10 at 16:48

@George: @ concatenates. To create a list of lists, just do [list1, list2,...] or list1 :: list_of_lists.
–
sepp2kOct 23 '10 at 16:49

Of course. Brain fart from me. I'm trying to make a function that'll do this for me, like call poslist where n would be 8 and then it'll count down from n to 0 and return a char list list. Is this possible? (I could of course do it manually, but that's not a very smart solution).
–
GeorgeWChubbyOct 23 '10 at 17:09