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....
-
A recent study by the Government Accountability Office found that consumers got correct answers about Medicare only 67 percent of the time when they called 1-800-MEDICARE. (a) At = .05, would a...
-
Capitalization of Interest on July 31, 2010, Bismarck Company engaged Duval Tooling Company to construct a special-purpose piece of factory machinery. Construction was begun immediately and was...
-
The following table presents the numbers of employees, by age group, who were promoted, or not promoted, in a sample drawn from a certain industry during the past year. Can you conclude that the...
-
A financial analyst engaged in business valuation obtained financial data on 53 drug companies (Industry Group SIC 3 code: 283). The file Business Valuation contains the following variables: COMPANY...
-
The Weber Company had the following information in its 2010 annual report: Cash and Marketable Securities: Total Assets: Total Liabilities: Dec. 31, 2010 23,500 54,000 28,000 Dec. 31, 2009 22,000...
-
In spring 2021, Amir Nathoo was at the helm of one of the most talked-about startups in the massive and fragmented educational technology (EdTech) industry. Just six years earlier, Nathoo and his...
-
Consider two individuals. Antoine and Belinda, with marginal benefit functions respectively given by: MBA = 10 Q and MBB = 5 Q, where Q represents the amount of a (pure) public good. Suppose the good...
-
Can someone have a diagnosis consistent with a mental illness, but still be competent and responsible for his/her actions? Explain your
-
1 White Wedding Corporation will pay a $1.90 per share dividend next year. The company pledges to increase its dividend by 3.78 percent per year, indefinitely. If you require an 10 percent return on...
-
The following account balances were taken from the 2024 post-closing trial balance of the Bowler Corporation: cash, $8,500; accounts receivable, $13,500; inventory, $23,000; equipment, $170,000;...
-
Debra is thinking about going to Disneyland with her friend. Debra is willing to pay HK$X to go to Disneyland. A ticket to Disneyland costs HK$428 and she will have to cancel her part- time job that...
-
For what reason in Eelthousev Bindley is the Nephew the only authorized party to sue the auctioneers given the cause of action in that case. [a] Identify the cause of action and [b] explain why the...
-
3. Problem 3 - Microscopic entropy change for a gas expansion. In this problem we will think about a gas as a few indistinguishable black checkers pieces on a large checkerboard. (a) How many ways...
-
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
-
You are performing the audit of Galway Ltd for the financial year ended 30 June 20X0. Under the terms of a major loan contract, Galway Ltd is required to maintain certain financial ratios. If the...
-
What purpose does a management letter serve?
-
What is the auditors responsibility for after-balance-date events? How does the auditor discharge this responsibility?
Study smarter with the SolutionInn App