cesky while1 - site about programming


append - connection of two lists
append([],L,L). append([H|T1],T2,[H|T3]):- append(T1,T2,T3).
reverse - linear list reverse
reverse([],[]). reverse([H|T],L):- reverse(T,L1), append(L1,[H],L).
length - the length of linear list
length([],D):- D = 0. length([H|T],D):- integer(H), length(T,DT), D is DT + 1.
length_g - the length of common list
length_g([],D):- D = 0. length_g([H|T],D):- integer(H), length_g(T,DT), D is DT + 1. length_g([H|T],D):- length_g(H,DH), length_g(T,DT), D is DH + DT.
member - atom is/is not member of common list
member(X,[]):- fail. member(X,[X|_]). member(X,[H|T]):- integer(H), member(X,T). member(X,[H|_]):- member(X,H). member(X,[_|T]):- member(X,T).
maximum - maximum of common list
max(X,Y,Z):- X >= Y, Z is X. max(X,Y,Z):- Z is Y. maximum([],X):- fail. maximum([H|T],X):- integer(H), maximum(T,X1), max(H,X1,X). maximum([H|_],X):- integer(H), X is H. maximum([H|T],X):- maximum(H,X1), maximum(T,X2), max(X1,X2,X). maximum([H|_],X):- maximum(H,X1), max(X,X1,X). maximum([_|T],X):- maximum(T,X1), max(X,X1,X).
reverse_g - common list reverse
reverse_g([],[]). reverse_g([H|T],L):- integer(H), reverse_g(T,L1), append(L1,[H],L). reverse_g([H|T],L):- reverse_g(T,L1), reverse_g(H,L2), append(L1,[L2],L). append([],L,L). append([H|T1],T2,[H|T3]):- append(T1,T2,T3).
depth - depth of common list
max(X,Y,Z):- X >= Y, Z is X. max(X,Y,Z):- Z is Y. depth([],D):- D = 0. depth([H|T],D):- integer(H), depth(T,DT), max(DT,1,D). depth([H|T],D):- depth(H,DH), X is DH + 1, depth(T,DT), max(X,DT,D).
Print this page
Author: Vaclav Bubnik © 2005