Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!rpi!uupsi!cmcl2!lanl!opus!eiverson From: eiverson@nmsu.edu (Eric Iverson) Newsgroups: comp.lang.prolog Subject: the great split up Message-ID: Date: 12 Feb 90 05:17:32 GMT Sender: news@nmsu.edu Distribution: comp Organization: NMSU Computer Science Lines: 29 Here is a split routine I wrote. Think of it as one string acting as a catalyst to split another string in two. If you can think of a better, more efficient way to do it, please let me know. This is for Quintus Prolog and is going to be called many many times. % split(Cat,String,A,B) binds Cat onto String and splits it into A and B. % String is split at the center of Cat. split([C|C1],[S|S1],[S|A],B):- C == S,split2(C1,S1,A,B,1,_); split([C|C1],S1,A,B). split2([],X,[],X,N,H):- H is N-N//2,!. split2([C|C1],[C|S1],A,B,N,H):- N1 is N+1,!, split2(C1,S1,A1,B1,N1,H), (N1 > H,B=[C|B1],A=A1,!; A=[C|A1],B=B1),!. -- ------------------------------------------------------------------------ Another Gruntpig production, in association with the Rat Lab Steamworks. I want to kill everyone here with a cute colorful Hydrogen Bomb!! -Zippy the Pinhead