Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implement partition (L,P,S) such that P is the prefix of L and s is the suffix of L and append (P,S,L) holds If L
Implement partition (L,P,S) such that P is the prefix of L and s is the suffix of L and append (P,S,L) holds If L is [],then P and s are [). If L is [H] , then P is [H] and s is 1. Otherwise, let length ofL be N. Then length of P is div(N, 2). Use Prolog's built-in integer division. length of s is N - div(N,2). You may need to use the length , prefix , suffix , append predicates that we have seen in class. In [15]: prefix(P,L) :- append (P,X,L). suffix(S,L) :- append (X,s,L). /* YOUR CODE HERE (delete the following line) */ partition (L,P,S) :- false. Added 5 clauses (s). Test-cases In [16]: 2- partition( [a],[a],[]). /* expected output: true. */ 7- partition( [1,2,31,[11, [2,31). /* expected output: true. */ 2- partition ( [a,b,c,d],X,Y). /* expected output: Y = [ c, d ], x = [ a, b ]. */ true. true. Y = [ c, d ], x = [ a, b].
Step by Step Solution
★★★★★
3.42 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
prefixPL appendPXL suffixSL appendXSL partitionaa partitio...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started