% template for reading input, outputting input, calling solve, and outputting output
sudoku :- write('Please enter puzzle as matrix:'),
          nl,
          read(Ls),
          show(Ls),
          solve(Ls,Ms),
          show(Ms),
          !.

% TODO: Implement this predicate
solve(Ls,Ms) :- fail.

% pretty printer for matrix representation
show([L|Ls]) :- length(L,X), show([L|Ls],X,X,X).
show([],I,J,D) :- write('+'), showHoriz(D).
show([L|Ls],I,J,D) :- checkHoriz(I,D), showList(L,J), K is I-1, show(Ls,K,J,D).

checkHoriz(I,D) :- I mod 3 =:= 0, !, write('+'), showHoriz(D).
checkHoriz(I,D).

showHoriz(0) :- !, nl.
showHoriz(X) :- write('-------+'), Y is X-3, showHoriz(Y).

showList([],J) :- write('|'), nl.
showList([X|Xs],J) :- number(X), !, showVert(X, J), K is J-1, showList(Xs,K).
showList([X|Xs],J) :- showVert(X, J), K is J-1, showList(Xs,K).

showVert(X,J) :- checkVert(J), write(X), write(' ').

checkVert(J) :- J mod 3 =:= 0, !, write('| ').
checkVert(J).

