Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unique([]):-!.
- unique([H|T]):-
- member(H, T), !, fail;
- unique(T).
- getLen([],0).
- getLen([_|T],N) :- getLen(T,N1), N is N1+1.
- pred(_,0,[]):-!.
- pred([H|Tail],N,[H|NewTail]):-N1 is N-1,pred(Tail,N1,NewTail).
- pred([_|Tail],N,Ans):-pred(Tail,N,Ans).
- point([X,Y]) :-
- random_between(0,50,X),
- random_between(0,50,Y).
- checkP([X1,Y1],[X2,Y2],[X3,Y3]) :-
- XY1 is X2-X1, XY2 is Y2-Y1,
- XZ1 is X3-X1, XZ2 is Y3-Y1,
- XZ1 \= 0, XZ2 \= 0,
- A is XY1 / XZ1, B is XY2 / XZ2,
- A\=B.
- showt([],_):-!.
- showt([H|T],N) :-
- write('Triangle №'),write(N),
- write(' '),write(H),nl,
- N1 is N+1,
- showt(T,N1).
- res(L,S) :-
- showt(L,1),write('Square : '),
- _s is round(S),write(_s),nl.
- sortL(L1,L2) :-
- pred(L1,2,L2),
- shared(L2).
- shared([[A,B,C],[D,E,F]]) :-
- L= [A,B,C,D,E,F],
- unique(L).
- best([],L,L0,S0,S) :-!,L=L0,S=S0.
- best([H|T],L,_,S0,S) :-
- square(H,S1),
- S1<S0,!,best(T,L,H,S0,S).
- best([_|T],L,L0,S0,S) :- best(T,L,L0,S0,S).
- square([],0) :-!.
- square([H|T],S) :-
- square(T,S1),
- geron(H,Temp),
- S is S1 + Temp.
- geron([P1,P2,P3],S) :-
- P1 = [X1,Y1],P2 = [X2,Y2],P3 = [X3,Y3],
- Ax is X1 -X2, Ay is Y1 - Y2,
- Axy is Ax*Ax + Ay*Ay, sqrt(Axy,A),
- Bx is X1 - X3, By is Y1 -Y3,
- Bxy is Bx*Bx + By*By, sqrt(Bxy,B),
- Cx is X2 - X3, Cy is Y2 - Y3,
- Cxy is Cx*Cx +Cy*Cy, sqrt(Cxy,C),
- P is (A + B + C)/2,
- St is P*(P-A)*(P-B)*(P-C),
- sqrt(St,S).
- gen(0,[]):-!.
- gen(N,[H|L]) :-
- point(H),
- N1 is N - 1,
- gen(N1,L).
- run :-
- gen(6,L),
- unique(L),
- write('Points : '),write(L),nl,
- findall(L1,pred(L,3,L1),List),
- % showt(List,1),
- findall(L2,sortL(List,L2),L3),
- showt(L3,1),
- L3 = [H|T],
- square(H,S0),
- best(T,L4,H,S0,S),
- res(L4,S).
- solve :-
- run;solve.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement