Ask Programming Language Expert

problem 1: prepare a Prolog predicate has_duplicates (L) which is true if list L contains duplicated elements (i.e., at least 2 copies of an element). For ex:

?- has_duplicates([a,e,b,d,s,e]).
Yes
?- has_duplicates([a,b,d,s,e]).
No
?- has_duplicates([]).
No

problem 2: prepare a Prolog predicate remove_nth (N, L1, L2) which is true if list L2 is just list L1 with its Nth element removed. If L1 does not have an Nth element then the predicate must fail. You can suppose that N is strictly greater than 0. For ex:

?- remove_nth(4,[a,e,e,d,s,e],L).
L = [a,e,e,s,e] ;
No
?- remove_nth(6,[a,b],L).
No

problem 3: Define a Prolog predicate flatten (List, FlattenedList) which asserts List is any nested list of atoms and FlattenedList is the same list with the nesting removed. The atom [] must as well be removed. Your predicate must only produce one answer. You might use the built-in predicates not, ! and append. Don’t use a helper predicate.

?- flatten([a, [[b,c],d], [[e]], [f]], X).
X = [a,b,c,d,e,f] ;
no
?- flatten([a,[[]], [[c,d],e]], X).
X = [a,c,d,e] ;
no

problem 4: Implement a two-dimensional table in Prolog. Your program will include:

a) An insert_entry predicate that takes a table, row, column and an entry and inserts the entry at the given position creating a new table.

b) A search_entry predicate that takes a table, row and column and unifies its fourth argument with entry at the indicated place of the table.

c) prepare code which creates a table and populates it with at least 2 rows and 2 columns.

problem 5: We want to make a structure which will represent a deck of cards (not essentially full). Each card has a character (between  ‘2’  to  ‘9’ and  ‘T’,  ‘J’,  ‘Q’,  ‘K’,  ‘A’) and a suit (diamonds, hearts, clubs and spades):

a) Select a representation for each card and as well for the deck of cards (it can be empty or non-empty)

b) Define an add_card predicate which takes a card and a deck and adds the card if it is not already there (that is, no duplicates) making a new deck of cards. If the card is not of a valid suit or number this predicate will simply do nothing.

c) Define a sort_deck predicate which sorts a deck of cards putting diamonds first, hearts second, clubs third and spades at the end (each suit in ascending order itself).

d) Comprise a test case in your program which creates a deck of at least 5 cards and sorts it.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M9419

Have any Question?


Related Questions in Programming Language

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Question 1 what is a computer program what is structured

Question: 1. What is a Computer program? What is structured programming? 2. What is modular programming? Why we use it? 3. Please evaluate Sin (x) by infinite series. Then write an algorithm to implement it with up to th ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Php amp session managment assignment -this assignment looks

PHP & SESSION MANAGMENT ASSIGNMENT - This assignment looks at using PHP for creating cookies and session management. Class Exercise - Web Project: Member Registration/Login This exercise will cover adding data connectivi ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As