Question: THIS IS A PROLOG QUESTION ! Write a predicate chop_up(List, NewList) that takes List and binds NewList to List with all sequences of successive increasing

THIS IS A PROLOG QUESTION !

Write a predicate chop_up(List, NewList) that takes List and binds NewList to List with all sequences of successive increasing whole numbers replaced by a two-item list containing only the first and last number in the sequence. An example of successive increasing whole numbers is:19,20,21,22. (Note that the numbers have to be successive in the sense of increasing by exactly 1 at each step.) For example:

?- chop_up([9,10,5,6,7,3,1], Result). Result = [[9, 10], [5, 7], 3, 1] ?- chop_up([1,3,2,3,4], Result). Result = [1, 3, [2, 4]]

In this example, the sequence 9,10 has been replaced by [9,10], the sequence 5,6,7 has been replaced by [5, 7], and 2,3,4 has been replaced by[2, 4].

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!