Can anyone explain me how this routine works I want to know
how routine understands if there is an even number of elements or odd number of elements. thanks
median(!list,!median)
median_2(!list,!list,!median)
$clauses
median(List, Median) :-
median_2(List, List, Median).
median_2([_], [Z|_], odd(Z)).
median_2([_,_], [X,Y|_], even(X,Y)).
median_2([_,_|[X3|List]], [_|Remainder], Median) :-
median_2([X3|List], Remainder, Median).
how routine understands if there is an even number of elements or odd number of elements. thanks
median(!list,!median)
median_2(!list,!list,!median)
$clauses
median(List, Median) :-
median_2(List, List, Median).
median_2([_], [Z|_], odd(Z)).
median_2([_,_], [X,Y|_], even(X,Y)).
median_2([_,_|[X3|List]], [_|Remainder], Median) :-
median_2([X3|List], Remainder, Median).