:- use_module(library(clpfd)). uniqueLine(Size, Rows):- length(Rows, Size), maplist(same_length(Rows), Rows), append(Rows, Vs), Vs ins 1..9, maplist(all_distinct, Rows).