comparison 3-Prolog/day3-sudoku.pl @ 68:b4f994693f7b

Fix condition check that was letting it backtrack to build a different set of rows
author IBBoard <dev@ibboard.co.uk>
date Sat, 07 Oct 2017 15:43:52 +0100
parents 8906b5a4517f
children
comparison
equal deleted inserted replaced
67:8906b5a4517f 68:b4f994693f7b
36 rows(_, RowLength, RowNum, []) :- RowNum > RowLength. 36 rows(_, RowLength, RowNum, []) :- RowNum > RowLength.
37 37
38 nth_from_list(Start, N, Input, Output) :- nth_from_list(N, Start, 1, Input, Output). 38 nth_from_list(Start, N, Input, Output) :- nth_from_list(N, Start, 1, Input, Output).
39 nth_from_list(N, Next, Pos, [Head|TailIn], [Head|TailOut]) :- Pos == Next, NewNext is Next + N, NewPos is Pos + 1, 39 nth_from_list(N, Next, Pos, [Head|TailIn], [Head|TailOut]) :- Pos == Next, NewNext is Next + N, NewPos is Pos + 1,
40 nth_from_list(N, NewNext, NewPos, TailIn, TailOut). 40 nth_from_list(N, NewNext, NewPos, TailIn, TailOut).
41 nth_from_list(N, Next, Pos, [_|TailIn], Output) :- NewPos is Pos + 1, nth_from_list(N, Next, NewPos, TailIn, Output). 41 nth_from_list(N, Next, Pos, [_|TailIn], Output) :- Pos < Next, NewPos is Pos + 1, nth_from_list(N, Next, NewPos, TailIn, Output).
42 nth_from_list(_, _, _, [], []). 42 nth_from_list(_, _, _, [], []).
43 43
44 cols(Board, ColLength, Cols) :- cols(Board, ColLength, 1, Cols). 44 cols(Board, ColLength, Cols) :- cols(Board, ColLength, 1, Cols).
45 cols(Board, ColLength, ColNum, [NewCol|Cols]) :- ColNum =< ColLength, NextColNum is ColNum + 1, 45 cols(Board, ColLength, ColNum, [NewCol|Cols]) :- ColNum =< ColLength, NextColNum is ColNum + 1,
46 nth_from_list(ColNum, ColLength, Board, NewCol), 46 nth_from_list(ColNum, ColLength, Board, NewCol),