Wednesday, February 21, 2024

Find the K'th element of a list in prolog

 

Find the K'th element of a list in prolog

element_at(X,[X|_],1).

element_at(X,[_|L],K) :- K > 1, K1 is K - 1, element_at(X,L,K1).


No comments:

Post a Comment