Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [_,_,[_|X]|Tai]=[[],0,[1,2,3],4,5,6]
- Tai = [4, 5, 6],
- X = [2, 3]
- add(X,L,N).
- add(X,[],[X]).
- add(X,[Y],[Y,X|[]]).
- add(X,[H|T],[H|N]):-add(X,T,N).
- memberr(X,[X|T]).
- memberr(X,[H|T]):-
- memberr(X,T).
- member(X,[23,50,16,14,30,14]), Y is X*X, Y<400.
- X = 16,
- Y = 256
- X = 14,
- Y = 196
- X = 14,
- Y = 196
- first(X,[X|L]).
- first(X,[[5,2],3,4]).
- X = [5, 2]
- snd(X,[_,X|L]).
- X = 3
- lastt(X,[X]).//IF i ONLY WIRTE E.G A(X,[X]). and a(X,[2]). it will give me 2
- lastt(X,[_|L]):-
- lastt(X,L).
- lastt(X,[[5,2],3,4]).
- X=4
- append([],B,B).
- append([H|A],B,[H|AB]):-
- append(A,B,AB).
- append([1,2],[3,4],X).
- //opisano v tetradkata-stiga do dunoto,koeto e ([],B,B). 2roto B nqma stoinost tui kato AB nqma => 2roto B priema stoinostta na 1voto.
- //B=[3,4]->AB=[3,4] i se vrushtame nazad 2|AB->[2,3,4], 1|AB->[1,2,3,4]
- https://www.youtube.com/watch?v=0LR_N_EMjwk
- 2nd exercise
- 1member using append
- append([],B,B).
- append([H|A],B,[H|AB]):-
- append(A,B,AB).
- member(X,L):-
- append(A,[X],C),
- append(C,B,L),
- append(_,[X|_],L).
- member(2,[1,2,3,4])
- true
- 2last using append
- last(X,L):-append(_,[X],L).
- PREFIX
- prefix(P,L):-append(P,_,L).
- This says that list P is a prefix of list L when there is some list such that L is the result of concatenating P with that list. (We use the anonymous variable since we donโt care what that other list is: we only care that there is some such list or other.) This predicate successfully finds prefixes of lists, and moreover, via backtracking, finds them all:
- refix(X,[1,2,3,4]).
- X = []
- X = [1]
- X = [1, 2]
- X = [1, 2, 3]
- X = [1, 2, 3, 4]
- suffix(S,L):-append(_,S,L).
- That is, list S is a suffix of list L if there is some list such that L is the result of concatenating that list with S . This predicate successfully finds suffixes of lists, and moreover, via backtracking, finds them all:
- suffix(X,[1,2,3])
- X = [1, 2, 3]
- X = [2, 3]
- X = [3]
- X = []
- ??
- infix(A,L):-append(P,_,L),
- append(_,A,P).
- //infix(A,[1,2,3])
- A = []
- A = [1]
- A = []
- A = [1, 2]
- A = [2]
- A = []
- A = [1, 2, 3]
- A = [2, 3]
- A = [3]
- A = []
- %dali S e pod-vo na L
- subset([],[]).
- subset([X|S],[X|L]) :-
- subset(S,L).
- subset(S, [_|L]) :-
- subset(S,L).
- subset(P,[1,2,3])
- P = [1, 2, 3]
- P = [1, 2]
- P = [1, 3]
- P = [1]
- P = [2, 3]
- P = [2]
- P = [3]
- P = []
- del(X,[X|Tail],Tail).
- del(X,[Head|Tail],[Head|NewList]):-
- del(X,Tail,NewList).
- remove(X,L,N):-append(A,[X|B],L),
- append(A,B,N).
- remove(X,[X|L],L).
- remove(X,[H|L],[H|B]):-remove(X,L,B).
- add(X,L,N):-remove(X,N,L).
Add Comment
Please, Sign In to add comment