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

Complete case programming assignment at the end of chapter

Complete Case Programming Assignment at the end of Chapter 4, page 283. Be sure to create an event planning document for each event in the program prior to writing code. Write the code that will execute the program requi ...

Assignmenta student had to make a decision on how to be

Assignment A student had to make a decision on how to be paid. The student could accept a straight $10/hour or take 10 cents for the first hour, but have the hourly wage double each hour. That is, the student would make ...

Most languages are case sensitive so keywords can be

Most languages are case sensitive, so keywords can be written only one way, and the regular expressions describing their lexemes are very simple. However, some languages, like SQL, are case insensitive, so a keyword can ...

Sum of digits in a string design a program that asks the

Sum of Digits in a String Design a program that asks the user to enter a string containing a series of single digit numbers with nothing seperating them. The program should display the sum of all the single digit numbers ...

Figure is code to count the number of primes from 2 to n

Figure is code to count the number of primes from 2 to n, using the sieve method on a suitably large array a. That is, a[i] is TRUE at the end only if there is no prime p i or less that evenly divides i. We initialize al ...

Lab assignmentwe begin our investigation of object-oriented

Lab Assignment We begin our investigation of object-oriented programming by creating an object-oriented program with a class called Employee. You will create two objects based on the Employee class, along with a class th ...

Write a program containing two classes named student and

Write a program containing two classes named student and roster, respectively. The program will maintain a current roster of students within a given course. Student data for the program includes student ID, first name, l ...

Programming languages assignment write the following as

Programming Languages Assignment Write the following as Prolog rules:  1. Implement a rule "dogEnthusiast". Someone is a "dogEnthusiast" if they own AT LEAST TWO dogs. Assume that the only types of facts available are: " ...

Programming oneusing jgrasp and the software development

Programming One Using jGrasp and the Software Development Kit, write a program in response to the following prompt: Write a program that prompts the user to input three numbers. This program should then output the number ...

Programming project sorting to find anagramssee project 4

Programming Project Sorting to find anagrams See Project 4 on pg. 869 for the basic ideas of this project. We will find the longest anagrams in the words.txt provided in the Chapter 13 files on the author's website. 1. F ...

  • 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

Section onea in an atwood machine suppose two objects of

SECTION ONE (a) In an Atwood Machine, suppose two objects of unequal mass are hung vertically over a frictionless

Part 1you work in hr for a company that operates a factory

Part 1: You work in HR for a company that operates a factory manufacturing fiberglass. There are several hundred empl

Details on advanced accounting paperthis paper is intended

DETAILS ON ADVANCED ACCOUNTING PAPER This paper is intended for students to apply the theoretical knowledge around ac

Create a provider database and related reports and queries

Create a provider database and related reports and queries to capture contact information for potential PC component pro

Describe what you learned about the impact of economic

Describe what you learned about the impact of economic, social, and demographic trends affecting the US labor environmen