Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :- use_module(library(clpfd)).
- solve(N) :-
- latin_square(N,Square),
- maplist(writeln,Square).
- latin_square(N,Square) :-
- length(Square,N), % Square = [[X11,...,X1N],...,[XN1,...,XNN]]
- maplist(same_length(Square),Square), %
- append(Square,AllVars),
- AllVars ins 1..N,
- maplist(all_different,Square), % All different in a row.
- transpose(Square,TSquare), % All different in a column.
- maplist(all_different,TSquare), %
- labeling([ff],AllVars).
- diagonal_to_lst([[H]],[H]).
- diagonal_to_lst([[H|_]|T],[H|L]) :-
- maplist(tail,T,T1),
- diagonal_to_lst(T1,L).
- tail([_|T],T).
- :- use_module(library(clpfd)).
- solve(N) :-
- latin_square(N,Square),
- maplist(writeln,Square).
- latin_square(N,Square) :-
- length(Square,N), % Square = [[X11,...,X1N],...,[XN1,...,XNN]]
- maplist(same_length(Square),Square), %
- append(Square,AllVars),
- AllVars ins 1..N,
- maplist(all_different,Square), % All different in a row.
- transpose(Square,TSquare), % All different in a column.
- maplist(all_different,TSquare), %
- labeling([ff],AllVars).
- :- use_module(library(clpfd)).
- mrok(Sol) :-
- Vars = [M,R,O,K,C,I,E,N,S1,C1],
- Sol = sol(m:M,r:R,o:O,k:K,c:C,i:I,e:E,n:N,s1:S1,c1:C1),
- Vars ins 0..9,
- all_different(Vars),
- M #\= 0, C #\= 0,
- (M*1000 + R*100 + O*10 + K) *
- (M*1000 + R*100 + O*10 + K) #=
- C*10000000 + I*1000000 + E*100000 + M*10000 + N*1000 + O*100 + S1*10 + C1,
- labeling([ff],Vars).
- :- use_module(library(clpfd)).
- %zadanie z książki ze stronki meissnera 152 strona
- visit(sol(fs:FS, hs:HS, j:J, m:M, t:T)) :-
- Vars = [FS, HS, J, M, T],
- Vars ins 0..1,
- HS #<== FS,
- M #\/ J,
- FS #\ T,
- T #<==> J,
- M #==> (J #/\ HS),
- labeling([ff],Vars).
- :- use_module(library(clpfd)).
- equations2(sol(a:A, b:B, c:C, d:D, e:E, f:F, g:G)) :-
- Vars = [A, B, C, D, E, F, G],
- Vars ins 1..10,
- all_different(Vars),
- B + G #= D,
- B + C #= A,
- C + E + G #= F,
- D #< A #==> C #= 2,
- D #>= A #==> E #= 2,
- sum(Vars,#=,Sum),
- labeling([min(Sum),ff],Vars).
- %dwuwymiarowa dystrybucja
- equations21(sol(a:A, b:B, c:C, d:D, e:E, f:F, g:G)) :-
- Vars = [A, B, C, D, E, F, G],
- Vars ins 1..10,
- all_different(Vars),
- B + G #= D,
- B + C #= A,
- C + E + G #= F,
- D #< A #==> C #= 2,
- D #>= A #==> E #= 2,
- Sum in 7..70,
- labeling([ff],[Sum]),
- sum(Vars,#=,Sum),
- labeling([ff],Vars).
- %dwuwymiarowa dystrybucja
- %
- % Let V(G) be a set of vertices of the graph G, let N(v)
- % be a set of all neighbours of the vertex v in V, and
- % let a coloring be any assignment of the form V -> Colors,
- % where Colors = {1,2,3,...}. Find a coloring, which uses
- % a minimal number of colors, such that all sums of colors
- % of N(v) for every vertex v are pairvise distinct.
- % coloring([[2,3,4,5],[1,3],[1,2,4],[1,3,5],[1,4]],L).
- %
- :- use_module(library(clpfd)).
- coloring2(Graph,Coloring) :-
- length(Graph,N),
- length(Coloring,N),
- length(Tints,N),
- Cn in 1..N,
- labeling([ff], [Cn]),
- Coloring ins 1..Cn,
- constr(Graph,Coloring,Tints),
- all_different(Tints),
- labeling([ff], Tints).
- constr(Graph,Coloring,Tints) :-
- maplist(vert_sum(Coloring),Graph,Tints).
- vert_sum(VertexColoring,VertNeighInds, VertSum) :-
- maplist(ind_to_vert(VertexColoring),VertNeighInds,VertNeighs),
- sum(VertNeighs, #=, VertSum).
- ind_to_vert(VertexColoring,VertI,Vert) :-
- nth1(VertI,VertexColoring,Vert).
- :- use_module(library(clpfd)).
- fraction(sol(a:A, b:B, c:C, d:D, e:E, f:F, g:G, h:H, i:I), Test1, Test2) :-
- statistics(inferences, Test1),
- Vars = [A, B, C, D, E, F, G, H, I],
- all_different(Vars),
- Vars ins 1..9,
- DD = [BC, EF, HI],
- DD ins 1..81,
- BC #= 10*B + C,
- EF #= 10*E + F,
- HI #= 10*H + I,
- A*EF*HI + D*BC*HI + G*BC*EF #= BC*EF*HI,
- A*EF #>= D*BC,
- D*HI #>= G*EF,
- 3*A #>= BC,
- 3*G #=< HI,
- labeling([ff, bisect], Vars),
- statistics(inferences, Test2).
- %oz version 3.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement