Last active
August 29, 2015 14:04
-
-
Save zkessin/0b1f436f753b1a7c4402 to your computer and use it in GitHub Desktop.
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
%-*- Prolog -*- | |
split(Head, Tail, HeadLength, FullList) :- | |
length(Head, HeadLength), | |
append(Head, Tail, FullList). | |
?- split(H,T, 3, [a,b,c,d,e,f,g,h,i,j,k,l]). | |
H = [a, b, c], | |
T = [d, e, f, g, h, i, j, k, l]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So what is going on here?
Basicly given a List, Full List and a length it is broken into sub lists of which the first half is the specified length, and he 2nd is the rest. This works because append can break a list apart, and length can cause it to backtrack until it finds the Head it wants