的示例是這樣的prolog-打破列表
?- runs([3,4,5,4,2,7,5,6,6,8,3], RunList).
RunList = [[3, 4, 5], [4], [2, 7], [5, 6, 6, 8], [3]]
列表需要在到了一些非遞減的連續編號的順序被打破。我的代碼是:
next([],0).
next([H|_],R):-
R is H.
runs1([],[]).
runs1([H|T],R):-
runs1(T,R1),
next(T,X),
H=<X,
R = [H|R1].
runs1([H|T],R):-
runs1(T,R1),
next(T,X),
H>X,
R = [[H]|R1].
我試過很多方法,但還是不知道怎麼寫呢?
希望有人能夠幫助我。
在此先感謝。
可能重複(http://stackoverflow.com/questions/29405498/extracting-sequences-lists-prolog) – lurker 2015-04-04 12:09:54