Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

More Books

Students also viewed these Databases questions

Question

LO3 Discuss the steps of a typical selection process.

Answered: 1 week ago