Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rec :- consult(prog).
- map(_,[],[]) :- !.
- map(F,[H1|T1],[H2|T2]) :-
- Term =.. [F,H1,H2],
- call(Term),
- map(F,T1,T2).
- rec_rev(Lst,Res) :-
- list(Lst), !,
- map(rec_rev,Lst,Res1),
- reverse(Res1,Res).
- rec_rev(A,A).
- writeN(_,0) :- !, nl.
- writeN(X,N) :-
- write(X),
- N1 is N-1,
- writeN(X,N1).
- writeStar(N,_) :-
- writeN('*',N).
- ribbonDiag(Lst) :-
- map(writeStar,Lst,_).
- between1(X,X,X) :- !.
- between1(X1,X2,N) :-
- X1 = N;
- X is X1+1,
- between1(X,X2,N).
- max3(X,Y,Z) :- Z is max(X,Y).
- min3(X,Y,Z) :- Z is min(X,Y).
- maxLst([],0).
- maxLst([H|T],M) :-
- maxLst(T,X),
- max3(H,X,M).
- neg(X,Y) :- Y is 0-X.
- minLst(Lst,M) :-
- map(neg,Lst,NLst),
- maxLst(NLst,MM),
- neg(MM,M).
- amp(Lst,A) :-
- maxLst(Lst,Max),
- minLst(Lst,Min),
- A is Max-Min+1.
- dashStar(0) :- !.
- dashStar(N) :-
- N1 is N-1,
- write('*'),
- write('-'),
- dashStar(N1).
- plotLine([],_) :- !, nl.
- plotLine(Lst,0) :- !,
- length(Lst,L),
- dashStar(L),
- nl.
- plotLine([H|T],X) :-
- X >= 0,
- H >= X, !,
- write('* '),
- plotLine(T,X).
- plotLine([H|T],X) :-
- X >= 0,
- H < X, !,
- write(' '),
- plotLine(T,X).
- plotLine([H|T],X) :-
- X < 0,
- H =< X,
- H < 0, !,
- write('* '),
- plotLine(T,X).
- plotLine([H|T],X) :-
- write(' '),
- plotLine(T,X).
- plotAll(_,0,_) :- !.
- plotAll(Lst,Amp,X) :-
- X = 0, !,
- write('-'),
- A1 is Amp-1,
- X1 is X-1,
- plotLine(Lst,X),
- plotAll(Lst,A1,X1).
- plotAll(Lst,Amp,X) :-
- write(' '),
- A1 is Amp-1,
- X1 is X-1,
- plotLine(Lst,X),
- plotAll(Lst,A1,X1).
- barDiag(Lst) :-
- amp(Lst,A),
- maxLst(Lst,M),
- plotAll(Lst,A,M).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement