RosettaCodeData/Task/Averages-Median/Prolog/averages-median.pro
2023-07-01 13:44:08 -04:00

9 lines
219 B
Prolog

median(L, Z) :-
length(L, Length),
I is Length div 2,
Rem is Length rem 2,
msort(L, S),
maplist(sumlist, [[I, Rem], [I, 1]], Mid),
maplist(nth1, Mid, [S, S], X),
sumlist(X, Y),
Z is Y/2.