SHARE
TWEET

Untitled

a guest Oct 21st, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %55
  2. DOMAINS
  3. i=integer
  4. list=i*
  5.  
  6. PREDICATES
  7. nondeterm enter(list)
  8. nondeterm getlength(list,i)
  9. nondeterm run
  10. nondeterm do(char)
  11. nondeterm check(i,i,list,i)
  12. nondeterm delete(list,i,i,list)
  13. CLAUSES
  14.  
  15. enter([H|T]):-
  16. write("Enter the element of the list or type 'END': "),
  17. readint(H),
  18. enter(T).
  19.  
  20. enter([]):-!.
  21.  
  22. getlength([],N):-N=0.
  23.  
  24. getlength([_|T],N):-
  25. getlength(T,NewN),N=NewN+1.
  26.  
  27. check(N,K,L,Pos):-
  28. N>=K,K>0,Pos>0,Pos<=N,K-1<=N-Pos,delete(L,Pos,K,L1), write(L1),nl;
  29. write("Bad value"),nl.
  30.  
  31. delete([H|T1],Pos,K,[H|T2]):-
  32. Pos=1,
  33. K=0,
  34. delete(T1,Pos,K,T2);
  35. Pos>1,
  36. K>0,
  37. NewPos=Pos-1,
  38. delete(T1,NewPos,K,T2).
  39.  
  40. delete([_|T1],Pos,K,T2):-
  41. Pos=1,
  42. K>0,
  43. NewK=K-1,
  44. delete(T1,Pos,NewK,T2).
  45.  
  46. delete([],_,_,[]):-!.
  47.  
  48. run:-
  49. write("*******ENTER*******"), nl,
  50. write("- 1 to START"),nl,
  51. write("- 0 to EXIT"),nl,
  52. write("***********************"),nl,
  53. write(">>"), readchar(X),
  54. write(X), nl, do(X), run.
  55.  
  56. do('1'):-
  57. enter(L),write("Your list is ",L),getlength(L,N),nl,
  58. write("N1 = "),readint(N1),
  59. write("N2 = "), readint(N2),
  60. K=N2-N1+1,
  61. check(N,K,L,N1).
  62.  
  63. do('0'):-
  64. write("That's all"),exit.
  65.  
  66. do(_):-
  67. write("Bad value"), nl.
  68. goal
  69. run.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top