Ask Question, Ask an Expert


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]).
?- has_duplicates([a,b,d,s,e]).
?- has_duplicates([]).

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] ;
?- remove_nth(6,[a,b],L).

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] ;
?- flatten([a,[[]], [[c,d],e]], X).
X = [a,c,d,e] ;

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

Cp1404cp5632 2016 sp22252 assignment 1 - shopping list

CP1404/CP5632 2016 SP2/22/52 Assignment 1 - Shopping List 1.0 Task: You are to plan and then code a console-based program in Python 3, as described in the following information and sample output. This assignment will hel ...

Programming assignment- implement a udp client and udp

PROGRAMMING ASSIGNMENT- Implement a UDP client and UDP server that support simple timeout-based retransmission with AIMD congestion control: -The client should send as many packets as are in its CURWIN (current window) a ...

This assignment introduces you to the perl language and cgi

This assignment introduces you to the Perl language and CGI programming. You will use your scripting and html skills to build a Perl program that will gather user input to then generate a personal webpage. This program w ...

Write a program that calculates several possible tips to

Write a program that calculates several possible tips to give to a waiter at a restaurant. Ask the user to enter the total cost of the meal and then calculate a tip at 10%, 12.5%, 15%, 17.5%, and 20%. Write the original ...

The briefyour small development team of ideally three

The Brief Your small development team of (ideally) three people has been asked to implement and test the Human Resource Information System desktop application. Your software product will be a database- backed desktop app ...

1 implement dfs by using prolog2 implement bfs by using

1. Implement DFS by using PROLOG. 2. Implement BFS by using PROLOG. 3.  Solve the problem of Question 3 in Assignment 1 by using your PROLOG programs of DFS and BFS, respectively. Question 3 from Assignment 1 to Solve wi ...

Integrative programmingassignment- managing a user account

Integrative Programming Assignment- Managing a User Account List Objective: To manage a user list that can be modified and saved to a text file. Inputs: • Input text file consisting of pairs of usernames and passwords, s ...

1 construct a markov algorithm that will reverse the order

1) Construct a Markov Algorithm that will reverse the order of an input string that consists of zero or more upper case letters. ABCDE should become EDCBA, AB should become BA, A should stay A, and A should stay A. NOTE: ...

Assignmentcase problem1 - online trivia found on pages

Assignment: Case Problem1 - Online Trivia found on pages 794-795 of your textbook. Complete the web pages and upload them to your 000WebHost account. After uploading the files make sure to update your index.html page to ...

Purposethe purpose of this assignment is to practice using

Purpose: The purpose of this assignment is to practice using loops, selections, and other basic features of Java in order to solve a real-world problem. Program Description: The Jeddah Broker Company is one of the compan ...

  • 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

A cola-dispensing machine is set to dispense 9 ounces of

A cola-dispensing machine is set to dispense 9 ounces of cola per cup, with a standard deviation of 1.0 ounce. The manuf

What is marketingbullwhat is marketing think back to your

What is Marketing? • "What is marketing"? Think back to your impressions before you started this class versus how you

Question -your client david smith runs a small it

QUESTION - Your client, David Smith runs a small IT consulting business specialising in computer software and techno

Inspection of a random sample of 22 aircraft showed that 15

Inspection of a random sample of 22 aircraft showed that 15 needed repairs to fix a wiring problem that might compromise

Effective hrmquestionhow can an effective hrm system help

Effective HRM Question How can an effective HRM system help facilitate the achievement of an organization's strate