daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Apr 26th, 2018 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. % Some simple test Prolog programs
  2. % --------------------------------
  3.  
  4. % Knowledge bases
  5.  
  6. аppend([ ], Lista, Lista).
  7. аppend([ Elem | Lista1], Lista2, [Elem | Lista3]):-
  8.                                      аppend(Lista1, Lista2, Lista3).
  9.  
  10. list_rList([],[]).  
  11. list_rList([H|T],R):-  list_rList(T,RevT),  append(RevT,[H],R).
  12.  
  13. m2([A|As], [B|Bs], [A,B|Rs]) :-
  14.     !, m2(As, Bs, Rs).
  15. m2([], Bs, Bs) :- !.
  16. m2(As, [], As).
  17.  
  18. reverse([X|Y], A) :- reverse(Y, Z), reverse(X, Xrev), append(Z, [Xrev], A).
  19. reverse(X, X) :- X \= [_|_]. % X is not a list, or X is an empty list
  20.  
  21. flatten2([], []) :- !.
  22. flatten2([L|Ls], FlatL) :-
  23.     !,
  24.     flatten2(L, NewL),
  25.     flatten2(Ls, NewLs),
  26.     append(NewL, NewLs, FlatL).
  27. flatten2(L, [L]).
  28.  
  29.  
  30. remove_elem([], _, []).
  31. remove_elem([Element | Rest], Element, Result) :-
  32.     !,
  33.     remove_elem(Rest, Element, Result).
  34. remove_elem([X | Rest], Element, [X | Result]) :-
  35.     remove_elem(Rest, Element, Result).
  36.  
  37. replace([_|T], 0, X, [X|T]).
  38. replace([H|T], I, X, [H|R]) :-
  39.     I > 0,
  40.     I1 is I - 1,
  41.     replace(T, I1, X, R).
  42.  
  43. replace1(L, I, X, R) :-
  44.     Dummy =.. [dummy|L],
  45.     J is I + 1,
  46.     nb_setarg(J, Dummy, X),
  47.     Dummy =.. [dummy|R].
  48.  
  49. tr(Method, K) :-
  50.     length(L, K),
  51.     K1 is K - 1,
  52.     time(call(Method, L, K1, test, R)),
  53.     assertion(nth1(K, R, test)).
  54. % ins(Val,List,Pos,Res)
  55.  
  56. ins(Val,[H|List],Pos,[H|Res]):- Pos > 1, !,
  57.                                 Pos1 is Pos - 1, ins(Val,List,Pos1,Res).
  58. ins(Val, List, 1, [Val|List]).
  59.  
  60. /** <examples>
  61.  
  62. ?- loves(X, mia).
  63. ?- jealous(X, Y).
  64.  
  65. */
RAW Paste Data
Top