Implement partition (L,P,S) such that P is the prefix of L and s is the suffix...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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]. 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].
Expert Answer:
Answer rating: 100% (QA)
prefixPL appendPXL suffixSL appendXSL partitionaa partitio... View the full answer
Related Book For
Elementary Linear Algebra with Applications
ISBN: 978-0471669593
9th edition
Authors: Howard Anton, Chris Rorres
Posted Date:
Students also viewed these accounting questions
-
You may need to learn how to open a data file from the text CD or download one from the Web for use with the software for your course. Do this for the FL student survey data file on the text CD, from...
-
Let F be the function such that F(n) is the sum of the first n positive integers. Give a recursive definition of F(n).
-
A statistical program is recommended. You may need to use the appropriate appendix table or technology to answer this question Data for two variables, x and y, follow. a. Develop the estimated...
-
Baxter Ltd requires a new machine to use in the manufacture of a new product. Two machines are available: Big Gee and Maxi-Shadbolt. Baxter Ltd. depreciates machinery using the straight-line method....
-
In Gas Pump, South Dakota, there are two kinds of consumers, Buick owners and Dodge owners. Every Buick owner has a demand function for gasoline DB (p) = 20 5p for p 4 and DB (p) = 0 if p > 4....
-
Craig Company is a family- owned business in which you own 20% of the common stock and your brothers and sisters own the remaining shares. The employment contract of Craigs new president, Ajay...
-
In the past five years, there have been significant innovations in technology such as smartphones and tablets. Technology companies rely on intellectual property (IP) rights, such as patents,...
-
Dotball Candies manufactures jaw-breaker candies in a fully automated process. The machine that produces candies was purchased recently and can make 4,400 per month. The machine costs $ 9,500 and is...
-
2. Draw one (1) accurate graph to show the production possibilities frontier for the head of household's own child PPFo given a budget of T=20Eo+20Co when E is units of education and C is units of...
-
1. XYZ Ltd. ("XYZ") yesterday issued a $1,000 par value 5 year bond ("the Bond"), In evaluating any capital budgeting proposal, XYZ has, historically, utilized a Required Rate of Return of 25%. As a...
-
Which blood vessels flow directly into the afferent arterioles?
-
Janes sister-in-law, a stockbroker at Invest, Inc., is trying to get Jane to buy the stock of HealthWest, a regional HMO. The stock has a current market price of $25, its last dividend (D 0 ) was...
-
An investor is considering buying the stock of two home health companies that are similar in all respects except the proportion of earnings paid out as dividends. Both companies are expected to earn...
-
You are considering investing in the stock of Encompass Health (formerly HealthSouth). You do some market research and learn that the companys last dividend was $0.84 and the companys market beta is...
-
Humana Inc.s last dividend (D 0 ) was $1.12, and its earnings and dividends are expected to increase at a constant growth rate of 12 percent. Humanas (www.humana.com) market beta is 1.16. If the...
-
You are an HR manager working in a busy training department in a local government office. The department has a well-established managing diversity policy. Within that policy it is explicit that...
-
Consider the pallowing plant, X are given by Ax + Bu where state space matrix 1 1 [42] 1 B = [:] We want to closed loop poles at -5-6. find the state feedback gain vector
-
What are technical skills At what level are they most important and why?
-
(a) Show that if A is invertible and AB = AC, then B = C. (b) Explain why part (a) and Example 3 do not contradict one another.
-
Solve the linear programming problem posed in Example 3.
-
In each part, determine whether the linear operator T: M22 M22 is one-to-one. If so, find (a) (b) :/HE. :*) -ca
-
A phenotypically abnormal individual has a phenotypically normal father with an inversion on one copy of chromosome 7 and a phenotypically normal mother without any changes in chromosome structure....
-
Explain how polytene chromosomes of Drosophila are produced, and describe the six-armed structure they form.
-
Male honeybees, which are haploid, produce sperm by meiosis. Explain what unusual event (compared with other animals) must occur during spermatogenesis in honeybees to produce sperm. Does this...
Study smarter with the SolutionInn App