Question: Write a predicate named split3(N,L) that has two arguments: N, a positive integer, and L, a list of positive integers. You may assume that the

Write a predicate named split3(N,L) that has two arguments: N, a positive integer, and L, a list of positive integers. You may assume that the list L is flat, i.e., it does not contain sublists. The predicate split3/2 returns true (or yes) if the list L can be partitioned into three sublists (with elements in the same order), such that the sum of the integers in each subset is less than or equal to N. Otherwise, it returns false (or no). Examples:

?-split3(5,[]).

false

?-split3(6,[5, 5, 12]).

false

?-split3(14,[6, 5, 10, 1, 1, 1, 14]).

true

?-split3(5,[3, 1, 4, 1, 2]).

true

?-split3(6,[4, 3, 5, 2, 1]).

false

?-split3(7,[4, 5, 7, 2, 3]).

false

?-split3(8,[3,5,4,2,7,1]).

true

?-split3(3,[1, 2, 2, 2, 1, 1]).

false

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!