Prolog separating into two lists issue

后端 未结 4 1270
太阳男子
太阳男子 2020-12-12 06:40

I have a prolog assignment.

I need to look at the first item in a list, see if its following items are the same until they are not and separate the lists by the firs

4条回答
  •  隐瞒了意图╮
    2020-12-12 07:43

    When the first two elements are different you do not need a recursive goal.

    grab([], [], []).
    grab([A,A|Rest], [A|As], L2):- !, grab([A|Rest], As, L2).
    grab([A|Tail], [A], Tail).
    

提交回复
热议问题