|
@@ -1,3 +1,33 @@
|
|
|
-maxsum([X], [Y], M) :- !, M is X+Y.
|
|
|
+maxsum([X], [Y], M) :- M is X+Y, !.
|
|
|
maxsum([X|Xs], [Y|Ys], V) :- V is X+Y, maxsum(Xs, Ys, M), V > M, !.
|
|
|
-maxsum([X|Xs], [Y|Ys], M) :- maxsum(Xs, Ys, M).
|
|
|
+maxsum([_|Xs], [_|Ys], M) :- maxsum(Xs, Ys, M).
|
|
|
+
|
|
|
+lile(L) :- length(L,X), member(X,L).
|
|
|
+lileg(L) :- lile(L), iflc(L).
|
|
|
+iflc([]) :- !.
|
|
|
+iflc([X|Xs]) :- atomic(X), !, iflc(Xs).
|
|
|
+iflc([X|Xs]) :- lileg(X), iflc(Xs).
|
|
|
+
|
|
|
+arrange(L1,L2,V,S1,S2) :- part(L1,V,S11,S12), part(L2,V,S21,S22), append(S11,S21,S1), append(S12,S22,S2).
|
|
|
+part([],_,[],[]).
|
|
|
+part([X|Xs],V,[X|L1],L2) :- X < V, !, part(Xs,V,L1,L2).
|
|
|
+part([X|Xs],V,L1,[X|L2]) :- X > V, !, part(Xs,V,L1,L2).
|
|
|
+part([_|Xs],V,L1,L2) :- part(Xs,V,L1,L2).
|
|
|
+
|
|
|
+sumoftwo(L,N,X,Y) :- deepmember(X,L), deepmember(Y,L), N is X+Y.
|
|
|
+deepmember(X,[X|_]) :- atomic(X).
|
|
|
+deepmember(X,[Y|Ys]) :- deepmember(X,Y) ; deepmember(X,Ys).
|
|
|
+
|
|
|
+deeprev([],[]) :- !.
|
|
|
+deeprev([X|Xs], F) :- !, deeprev(X,R), deeprev(Xs,Vs), append(Vs,[R],F).
|
|
|
+deeprev(X,X).
|
|
|
+
|
|
|
+palindrome(X) :- reverse(X,Y), X == Y.
|
|
|
+
|
|
|
+pack([], []).
|
|
|
+pack([X|XS], [Z|ZS]) :- pack_helper(X, XS, YS, Z), pack(YS, ZS).
|
|
|
+
|
|
|
+% third arg is the rest of the list, fourth is the list of the adiacent occurences of X
|
|
|
+pack_helper(X, [], [], [X]).
|
|
|
+pack_helper(X, [Y|YS], [Y|YS], [X]) :- X \= Y.
|
|
|
+pack_helper(X, [X|XS], YS, [X|ZS]) :- pack_helper(X, XS, YS, ZS).
|