My problem is, that I want to make a rule for splitting a list to several lists, containing only 3 items from the original, in order.
For example:
/*original list:*/
Fruits=[apple,banana,orange,pear, lemon, melon]
?-Split(Fruits).
/*results:*/
[apple,banana,orange];
[banana,orange,pear];
[orange,pear,lemon];
[pear,lemon,melon].
Is there any way to do this? :S
Prolog is excellent for this task. Just observe that append/3 can be used
in various directions:
Now simply define split/2 as follows. It will find _1 and _2 such that L = _1 ++ S ++ _2, where ++ is the list concatenation:
And here you go with your problem:
Bye
Best Regards