1

I'm trying to get the dimensions of a sudoku board in ECLiPSE CLP, however I get the following error:

type error in dim([[_389, 9, 8, _395, _397, _399, _401, _403, _405], [_409, _411, _413, _415, 7, _419, _421, _423, _425], [_429, _431, _433, _435, 1, 5, _441, _443, _445], [1, _451, _453, _455, _457, _459, _461, _463, _465], [_469, _471, _473, 2, _477, _479, _481, _483, 9], [_489, _491, _493, 9, _497, 6, _501, 8, 2], [_509, _511, _513, _515, _517, _519, _521, 3, _525], [5, _531, 1, _535, _537, _539, _541, _543, _545], [_549, _551, _553, 4, _557, _559, _561, 2, _565]], [_567, _569])

I get this when I call dim(Board,[R,C]), where Board is a sudoku board:

Board = [
[_, 9, 8, _, _, _, _, _, _],
[_, _, _, _, 7, _, _, _, _],
[_, _, _, _, 1, 5, _, _, _],
[1, _, _, _, _, _, _, _, _],
[_, _, _, 2, _, _, _, _, 9],
[_, _, _, 9, _, 6, _, 8, 2],
[_, _, _, _, _, _, _, 3, _],
[5, _, 1, _, _, _, _, _, _],
[_, _, _, 4, _, _, _, 2, _]].

Anyone any idea why this happens?

The Oddler
  • 6,314
  • 7
  • 51
  • 94

1 Answers1

0

You are calling dim/2 which expects an array as first argument. However Board in your case, is a list. A simple conversion can be obtained by calling:

array_list(BoardArray,Board)

Small note: since a sudoku will always have an equal amount of rows and columns, you could also use the same variable for stating the dimension. Like so:

dim(Sudoku,[N,N])

EDIT:

In order to also convert the inner lists, you want to iterate through the list of lists and convert every row list into an array. This goes like following:

(foreach(Row,Board), foreach(RowArray,Out)
do
  array_list(RowArray,Row)
),
array_list(BoardArray,Out)

We iterate simultaneously through Board and Out in order to convert every row-list into a row-array and after the loop, we also convert the parent board list to a board array.

This appeared to be already answered here .

Community
  • 1
  • 1
SND
  • 1,552
  • 2
  • 16
  • 29
  • This seems to have fixed it. Thanks! – The Oddler Mar 17 '16 at 17:49
  • I still have a problem though. Now when I run dim(BoardArray,[N,N]), I get "no". I think it's because now I have an array of lists, rather than an array of arrays. Is this correct, and how can I fix that? – The Oddler Mar 17 '16 at 18:23
  • 1
    That will indeed probably be the problem. I will edit my answer according to what you're looking for. – SND Mar 17 '16 at 18:25