Reputation: 59
I try to create an emergency system to find people on time and those late. so my list now looks like:
[ [patient(204,4,2),patient(203,3,2)] , [patient(303,7,3),patient(302,6,3)] , [patient(404,12,4) ,patient(403,11,4)] , [patient(504,16,5),patient(503,15,5)] ]
I want for each list to find those on time using the following function (score):
(consultation time) * (index of patient) + (2nd argument of patient predicate)
consultation time is constant:
example :
consultTime(15)
For this exemple i have to get something like :
[ [4 , 18] , [37, 51] , [72, 86] , [106, 120] ]
the problem is with the indices how can i preserve the same index as with a normal list i.e.:
[ [0, 1], [2, 3], [4, 5] ]
I'm sorry, i didn't find a good question for my problem.
Upvotes: 0
Views: 86
Reputation: 28963
the problem is with the indices how can i preserve the same index as with a normal list i.e.:
[ [0, 1], [2, 3], [4, 5] ]
Pass a counter in at the start of each list, use it to count through the elements, then return how far it got. Pass that value in to start the count for the next list:
% process a single list, just showing the counter
process([], C, C, []).
process([P1|P1s], Count, CountTo, [Count|P2s]) :-
succ(Count, Next),
process(P1s, Next, CountTo, P2s).
% for the list of lists
test([], _, []).
test([L1|L1s], CountFrom, [L2|L2s]) :-
process(L1, CountFrom, CountTo, L2),
test(L1s, CountTo, L2s).
e.g.
?- _Patients = [
[patient(204,4,2), patient(203,3,2)],
[patient(303,7,3), patient(302,6,3)],
[patient(404,12,4), patient(403,11,4)],
[patient(504,16,5), patient(503,15,5)]
],
test(_Patients, 0, Ps).
Ps = [[0, 1], [2, 3], [4, 5], [6, 7]]
Upvotes: 1