Skip to content

Instantly share code, notes, and snippets.

@trietptm
Created December 11, 2012 08:36
Show Gist options
  • Save trietptm/4257005 to your computer and use it in GitHub Desktop.
Save trietptm/4257005 to your computer and use it in GitHub Desktop.
Find the K'th element of a list. The first element in the list is number 1.
kth_element_of_list(X, [X|T], 1).
kth_element_of_list(X, [H|T], K) :- kth_element_of_list(X, T, K1), K is K1+1, K>1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment