Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
collapse_runs( Xs , [Y|Ys] ) :- % for a non-empty list... run(Xs,Y,X1) , % identify the run, discarding the dupes collapse_runs(X1,Ys) % and recurse down on whatever's left over . % easy! collapse_runs( [] , [] ) . % there are no runs in the empty list % ----------------------------------------------------- % a run consists of 1 or more identical elements. % So... pop the head of the list and discard things % from the tail until we encounter something different. %------------------------------------------------------ run([X|Xs],X,R) :- discard(Xs,X,R) . discard( [] , _ , [] ) . discard( [X|Xs] , X , T ) :- !, discard(Xs,X,T) . discard( [X|Xs] , _ , [X|Xs] ) .