Created
December 13, 2012 18:51
-
-
Save trietptm/4278660 to your computer and use it in GitHub Desktop.
Split a list into two parts; the length of the first part is given.
Do not use any predefined predicates. Example:
?- split([a,b,c,d,e,f,g,h,i,k],3,L1,L2).
L1 = [a,b,c]
L2 = [d,e,f,g,h,i,k]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
length_list([], 0). | |
length_list([H|T], X) :- length_list(T, X1), X is X1+1, !. | |
split_list([X|Y], 1, [X], Y). | |
split_list([H|T], M, [H|L1], L2) :- split_list(T, M1, L1, L2), M is M1+1. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment