Advertisement
elvecent

Prolog5

Oct 13th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. rec :- consult(prog).
  2.  
  3. map(_,[],[]) :- !.
  4. map(F,[H1|T1],[H2|T2]) :-
  5. Term =.. [F,H1,H2],
  6. call(Term),
  7. map(F,T1,T2).
  8.  
  9. rec_rev(Lst,Res) :-
  10. list(Lst), !,
  11. map(rec_rev,Lst,Res1),
  12. reverse(Res1,Res).
  13. rec_rev(A,A).
  14.  
  15. writeN(_,0) :- !, nl.
  16. writeN(X,N) :-
  17. write(X),
  18. N1 is N-1,
  19. writeN(X,N1).
  20.  
  21. writeStar(N,_) :-
  22. writeN('*',N).
  23.  
  24. ribbonDiag(Lst) :-
  25. map(writeStar,Lst,_).
  26.  
  27. between1(X,X,X) :- !.
  28. between1(X1,X2,N) :-
  29. X1 = N;
  30. X is X1+1,
  31. between1(X,X2,N).
  32.  
  33. max3(X,Y,Z) :- Z is max(X,Y).
  34. min3(X,Y,Z) :- Z is min(X,Y).
  35.  
  36. maxLst([],0).
  37. maxLst([H|T],M) :-
  38. maxLst(T,X),
  39. max3(H,X,M).
  40.  
  41. neg(X,Y) :- Y is 0-X.
  42.  
  43. minLst(Lst,M) :-
  44. map(neg,Lst,NLst),
  45. maxLst(NLst,MM),
  46. neg(MM,M).
  47.  
  48. amp(Lst,A) :-
  49. maxLst(Lst,Max),
  50. minLst(Lst,Min),
  51. A is Max-Min+1.
  52.  
  53. dashStar(0) :- !.
  54. dashStar(N) :-
  55. N1 is N-1,
  56. write('*'),
  57. write('-'),
  58. dashStar(N1).
  59.  
  60. plotLine([],_) :- !, nl.
  61. plotLine(Lst,0) :- !,
  62. length(Lst,L),
  63. dashStar(L),
  64. nl.
  65. plotLine([H|T],X) :-
  66. X >= 0,
  67. H >= X, !,
  68. write('* '),
  69. plotLine(T,X).
  70. plotLine([H|T],X) :-
  71. X >= 0,
  72. H < X, !,
  73. write(' '),
  74. plotLine(T,X).
  75. plotLine([H|T],X) :-
  76. X < 0,
  77. H =< X,
  78. H < 0, !,
  79. write('* '),
  80. plotLine(T,X).
  81. plotLine([H|T],X) :-
  82. write(' '),
  83. plotLine(T,X).
  84.  
  85. plotAll(_,0,_) :- !.
  86. plotAll(Lst,Amp,X) :-
  87. X = 0, !,
  88. write('-'),
  89. A1 is Amp-1,
  90. X1 is X-1,
  91. plotLine(Lst,X),
  92. plotAll(Lst,A1,X1).
  93. plotAll(Lst,Amp,X) :-
  94. write(' '),
  95. A1 is Amp-1,
  96. X1 is X-1,
  97. plotLine(Lst,X),
  98. plotAll(Lst,A1,X1).
  99.  
  100. barDiag(Lst) :-
  101. amp(Lst,A),
  102. maxLst(Lst,M),
  103. plotAll(Lst,A,M).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement