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 split 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).

For example,

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

true

this returns true because the list [3, 1, 4, 1, 2] can be separated into 3 sublists, and the sum of the values in each sublist will be equal or less than 5 (which is N).

list 1: [3, 1]

3 + 1 = 4, which is less than 5

list 2: [4, 1]

4 + 1 = 5, which is equal to 5

list 3: [2]

2 is less than 5.

Another example:

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

false

this shows false because the list [4, 3, 5, 2, 1] can not be split into 3rds so that the sum of integers in each sublists are equal or less than 6

if we try to work this out:

list 1: [4]

if we try to add 4 + 3, it becomes 7 and it is greater than 6. 4 needs to be its own list.

list 2: [3]

3 + 5 = 8, which is greater than 6. So 3 must be in its own list.

list 3: [5]

5 + 2 = 7, which is greater than 6. So 5 needs to be in its own list.

Because we could not make 3 sublists with the sum of each sublist equal or less than 6, it is 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!