Summary Files Commits Branches @commit @diff @stats
path: root / Year 3 / Logical Programming / test.pdb
blob: 1da0a1fac46c5e69c0a24e987f9e6a956e968741 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
% четно_позиционирани, нечетно_позиционирани

even_elements([], []).
even_elements([_,B|X], [B|Y]) :- even_elements(X, Y).

odd_elements([], []).
odd_elements([_], [_]).
odd_elements([A,_|X], [A|Y]) :- odd_elements(X, Y).

% p(X,Y)

swap_odd_even(X, Y) :- even_elements(X, W), odd_elements(Y, W),
                       odd_elements(X, Z), even_elements(Y, Z).

% Кои са всички триелементни списъци, които съдържат а, б и в?

is_combination(_, []).
is_combination(X, [B|W]) :- member(B, X), is_combination(X, W).

% пермутация(X, Y)

ins_elem(X, A, [A|X]).
ins_elem([B|X], A, [B|Y]) :- ins_elem(X, A, Y).

rm_elem([A|X], A, X).
rm_elem([B|X], A, [B|Y]) :- rm_elem(X, A, Y).

perm([], []).
perm([_|_], []) :- false.
perm([], [_|_]) :- false.
perm(X, [B|Y]) :- member(B, X), rm_elem(X, B, W), perm(W, Y).