Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :- use_module(library(lists)).
- %participant(Id,Age,Performance)
- participant(1234, 17, 'Pé coxinho').
- participant(3423, 21, 'Programar com os pés').
- participant(3788, 20, 'Sing a Bit').
- participant(4865, 22, 'Pontes de esparguete').
- participant(8937, 19, 'Pontes de pen-drives').
- participant(2564, 20, 'Moodle hack').
- %performance(Id,Times)
- performance(1234,[120,120,120,120]).
- performance(3423,[32,120,45,120]).
- performance(3788,[110,2,6,43]).
- performance(4865,[120,120,110,120]).
- performance(8937,[97,101,105,110]).
- %1 5min
- madeItThrough(Participant) :-
- participant(Participant,_,_),
- performance(Participant, Performance),
- member(120, Performance).
- %2 15min
- juriTimes([],_,[],0).
- juriTimes([H|Tail], Juri, Times, Total) :-
- juriTimes(Tail, Juri, TimesN, TotalN),
- getTimePerfomance(H,Juri, T),
- append([T], TimesN, Times),
- Total is TotalN + T.
- getTimePerfomance(Participant, Juri, T) :-
- performance(Participant, List),
- nth1(Juri, List, T).
- %3 25min,
- patientJuri(Juri) :-
- getJuri(Juri, [], [], V),
- validateGoogJuri(V, Counter),
- Counter >= 2.
- getJuri(Juri, ListParticipant, ListVote, V) :-
- performance(ID,JurisTimes),
- \+member(ID, ListParticipant),
- append(ListParticipant, [ID], ListPN),
- nth1(Juri, JurisTimes, Time),
- append(ListVote, [Time], ListNV),
- getJuri(Juri, ListPN, ListNV, V).
- getJuri(_,_, V, V).
- validateGoogJuri([], 0).
- validateGoogJuri([H|T], Counter) :-
- validateGoogJuri(T, CounterN),
- checkPatient(H, CounterN, Counter).
- checkPatient(H, CounterN, Counter) :-
- H == 120,
- Counter is CounterN + 1.
- checkPatient(_, C, C).
- %4 7min
- listSum([],0).
- listSum([H|T], Sum) :-
- listSum(T, SumN),
- Sum is H + SumN.
- bestParticipant(P1, P2, Z) :-
- performance(P1, Votes1),
- performance(P2, Votes2),
- listSum(Votes1, Sum1),
- listSum(Votes2, Sum2),
- bestP(P1, Sum1, P2, Sum2, Z).
- bestP(P1, Sum1, _, Sum2, Z) :-
- Sum1 > Sum2,
- Z is P1.
- bestP(_,Sum1,P2,Sum2,Z) :-
- Sum2 > Sum1,
- Z is P2.
- bestP(_,_,_,_,_) :- fail.
- %5 7min
- allPerfs :-
- performance(ID, Times),
- participant(ID, _, Title),
- writeInfo(ID, Title, Times),
- fail.
- allPerfs.
- writeInfo(ID, Title, Times) :-
- write(ID),
- write(':'),
- write(Title),
- write(':'),
- write(Times),
- nl.
- %6 13min
- nSuccessfulParticipants(T) :-
- getAllVotes([], [], Votes),
- countSuccessfulP(Votes, T).
- getAllVotes(P, V,Votes) :-
- performance(ID, Vt),
- \+member(ID, P),
- getAllVotes([ID|P], [Vt|V], Votes).
- getAllVotes(_, V, V).
- countSuccessfulP([], 0).
- countSuccessfulP([H|Tail], T) :-
- countSuccessfulP(Tail, NT),
- listSum(H, Sum),
- length(H, Size),
- checkSuccessfulP(Sum, Size, Check),
- T is Check + NT.
- checkSuccessfulP(Sum, Size, Check) :-
- Total is Size * 120,
- Sum == Total,
- Check is 1.
- checkSuccessfulP(_,_,0).
- %7 10min
- juriFans(L) :-
- findall(ID-Vote,
- (performance(ID, Votes),
- findall(N, nth1(N, Votes, 120), Vote)),
- L).
- %8
- eligibleOutcome(Id,Perf,TT) :-
- performance(Id,Times),
- madeItThrough(Id),
- participant(Id,_,Perf),
- sumlist(Times,TT).
- nextPhase(N, P) :-
- findall(Bag,setof(TT-Id-Perf,
- (
- eligibleOutcome(Id, Perf, TT),
- performance(Id, Votes),
- member(120, Votes)
- ), [Bag]), R),
- reverse(R, NR),
- getNFirst(N, NR, P).
- getNFirst(0, _, []).
- getNFirst(N, [H|T], [H|P]) :-
- NewN is N - 1,
- getNFirst(NewN,T,P).
- %11
- impoe(X,L) :-
- length(Mid,X),
- append(L1,[X|_],L), append(_,[X|Mid],L1).
- langford(0,[]).
- langford(N,L) :-
- TotalLength is N * 2,
- length(LL, TotalLength),
- langfordCycle(N,L,LL).
- langfordCycle(0,L, L).
- langfordCycle(N,L, LL) :-
- impoe(N, LL),
- NewN is N - 1,
- langfordCycle(NewN, L, LL).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement