% https://open.kattis.com/problems/knightpacking % 1s % 1.3 Easy % Analyzing the problem, % What is the maximum number of non-attacking knights? import sat. go => nolog, member(N,1..10), println(n=N), X = new_array(N,N), X :: 0..1, % 1 has a knight Vs = [-2,-1,1,2], foreach(I in 1..N, J in 1..N) X[I,J] #= 1 #=> sum([ X[I+A,J+B] : A in Vs, B in Vs, abs(A)+abs(B) == 3, I+A >= 1, I+A <= N, J+B >= 1, J+B <= N ]) #= 0 end, Z #= sum([X[I,J] : I in 1..N, J in 1..N]), solve($[max(Z)], X), println(z=Z), foreach(Row in X) println(Row.to_list) end, nl, fail, nl. % [[1,1],[2,2],[3,5],[4,8],[5,13],[6,18],[7,25],[8,32],[9,41],[10,50]] go2 => println([ [I,ceiling(I*I/2)] : I in 1..10 ]), nl.