Advertisement
Guest User

prolog-AI

a guest
Oct 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. % ex. 2
  2. rotaction(L,_,0,L).
  3. rotaction(L,Dir,N,Res):- -N > 0, N1 is N-1, rot(L,Dir,L1), rotaction(L1,Dir,n1,Res).
  4. rot(L,st,L1):- rotst(L,L1).
  5. rot(L,dr,L1):- rotdr(L,L1).
  6. rotst([],[]).
  7. rotst([X|R],L):- append(R,[X],L).
  8. rotdr([],[]).
  9. rotdr(L,[X|L1]):- ultim(L,L1,X).
  10. ultim([X],[],X).
  11. ultim([Y|R],[Y|L1],X):- ultim(R,L1,X).
  12.  
  13. % ex. 3
  14. list_sub([],[]).
  15. list_sub([_|Xs],Ys) :-list_sub(Xs,Ys).
  16. list_sub([X|Xs],[X|Ys]) :-list_sub(Xs,Ys).
  17.  
  18. sublist_of(Sub,List) :-list_sub(List,Sub).
  19.  
  20. list_sublist_sum(Xs,S,Target) :- sublist_of(S,Xs),
  21. sum(S,#=,Target).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement