Article View: comp.lang.prolog
Article #4176the great split up
From: Eric Iverson
Date: Mon, 12 Feb 1990 05:17
Date: Mon, 12 Feb 1990 05:17
29 lines
1315 bytes
1315 bytes
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
Technical Details
Message-ID:
<EIVERSON.90Feb11221732@hades.nmsu.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!rpi!uupsi!cmcl2!lanl!opus!eiversonShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <EIVERSON.90Feb11221732@hades.nmsu.edu> Date: 12 Feb 90 05:17:32 GMT Sender: news@nmsu.edu Distribution: comp Organization: NMSU Computer Science Lines: 29