Advertisement
VladSmirN

lab task 3

Jun 20th, 2021
1,293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.99 KB | None | 0 0
  1. implement main
  2.     open core, console
  3.  
  4. class predicates
  5.     isExists : (integer*, integer, boolean [out]).
  6.     isSubset : (integer*, integer*, boolean [out]).
  7.  
  8. clauses
  9.     isExists([], Element, false) :-
  10.         !.
  11.     isExists([X | Xs], Element, S) :-
  12.         isExists(Xs, Element, S2),
  13.         if X = Element then
  14.             S = true
  15.         else
  16.             S = S2
  17.         end if.
  18.  
  19.     isSubset([], Set, true) :-
  20.         !.
  21.     isSubset([X | Xs], Set, S) :-
  22.         isSubset(Xs, Set, S2),
  23.         isExists(Set, X, A),
  24.         if A = true and S2 = true then
  25.             S = true
  26.         else
  27.             S = false
  28.         end if.
  29.         %write(X, " ", A).
  30.  
  31.     run() :-
  32.         init(),
  33.         L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
  34.         L1 = [3, 4, 5, 6, 7, 8, 9, 10],
  35.         isSubset(L, L1, A),
  36.         write(A, "Конец. Нажмите любую клавишу "),
  37.         _ = readchar().
  38.  
  39. end implement main
  40.  
  41. goal
  42.     mainExe::run(main::run).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement