/* in Picat. CP is too slow for arrangement3.inp! Using foreach is better, but it should be translated to Prolog... This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import v3_utils. import util. import cp. main => go. go => [N,M] = read_file_lines().map(to_int), println([n=N,m=M]), Y = new_list(N), bind_vars(Y,[]), foreach(I in 1..M) mod2(I,N,J), Y[J] := Y[J] ++ [*] end, foreach(L in Y) println(L) end, nl. go2 => [N,M] = read_file_lines().map(to_int), println([n=N,m=M]), t(N,M,N,M), nl. t(0, 0,_N,_M). t(I,0,N,M) :- I > 0, I1 is I-1, nl,t(I1,M,N,M). t(I,J,N,M) :- I>0, J>0, mod2(J,N,Mod), (Mod =:= I -> print("*") ; true), J2 is J-1, t(I,J2,N,M). mod2(A,B,Mod) => Mod0 is A mod B, (Mod0 == 0 -> Mod = B ; Mod = Mod0). % TOO slow go_cp => [N,M] = read_file_lines().map(to_int), println([n=N,m=M]), X = new_list(M), X :: 1..N, GCC = new_list(N), GCC :: 1..M, global_cardinality(X,$[I-GCC[I] : I in 1..N]), println(gcc=GCC), Z #= sum([abs(GCC[I]-GCC[J]) : I in 1..N, J in I+1..N ]), println(z=Z), Vars = X ++ GCC, solve($[degree,updown,min(Z),report(printf("z:%d\n",Z))],Vars), println(x=X), println(gcc=GCC), println(z=Z), nl, fail, nl.