Implement a rule crypto that solves cryptarithmetic problems

Assignment Help Programming Languages
Reference no: EM131372339

Programming Languages Homework

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: 

"owner" facts of the form owner(p,n), meaning that person p owns animal named n.

"breed" facts of the form breed(a,b), meaning that animal named a is of type b.

For example: 

owner(fred,fido) means that a person named "fred" owns an animal named "fido". 

breed(fido,dog) means that the animal named "fido" is a dog. 

breed(leo,cat) means that the animal named "leo" is a cat. 

dogEnthusiast(sam) would be true if sam owned two different animals that were dogs.

2. Implement "listPicker" as a Prolog rule.

For example, the query:listPicker([42,3,99,7],[4,3,3],M) should result in Prolog's response:M = [7,99,99]. You only need to handle lists that contain integers.

3. Implement a rule "crypto" that solves the following cryptarithmetic multiplication problem:

TOCK * TOCK = GRIPTOCK

Each of the 4 letters (T,O,C,K) stands for a different digit. The 4 letters (G, R, I, P) can each be matched by any digit. The aim is to find a substitution of digits for the letters such that the above stated product is arithmetically correct. Your program should find all answers. It should be possible to query your solution in this manner:

?- crypto(G,R,I,P,T,O,C,K).

Your solution should then produce all of the combinations of the digits that satisfy the multiplication problem above. Don't get confused between the letter "O" and the number "0" (zero). 

Make sure you never let T=C, or C=K, etc... all of the distinct letters T,O,C,K have to stand for distinct digits.

Don't be surprised if it takes your computer a while to solve this problem. Use generate-and-test!

4. Implement a rule "interleave" that takes two lists, and combines them into a single list by alternating the elements. For example:

?- interleave([3,4,5],[7,8,9],X) should respond X=[3,7,4,8,5,9]

If the two lists are different lengths, include the excess elements at the end of the result list, with a "999" inserted first. For example:

?- interleave([1,2],[4,5,6,7],X) results in X=[1,4,2,5,999,6,7] 

?- interleave([1,2,3,4],[6,7],X) results in X=[1,6,2,7,999,3,4]

5. Convert "digitinc" into a Prolog rule. For example:

?- digitinc(22897,X) should respond X=33908.

Submit your solutions in a single file.

Problem 2 & 5 - Reference

"listPicker"

-  Inputs two lists the first list is the data and second list is the picker, and Outputs a list of values in the data list ref. by values in picker list.

"digitinc"

-  Takes as input integers with an arbitrary number of digits, and returns another digit integer constructed of the original input integer's digits, each incremented.  

Instructions for Prolog Assignment- Note the following:  

  • I recommend using the SWI-Prolog system.
  • You are only allowed to use basic functions which do not make the problems trivial.

Reference no: EM131372339

Questions Cloud

Discuss use of binary tree when searching for keys in array : Discuss the use of a binary tree when searching for keys in an array.
Contingency leadership and situational leadership : What are the differences and similarities in contingency leadership and situational leadership. How are contingency leadership and situational leadership important to how successful an organization becomes.
Identify the predominant design : After comparing Mintzberg s five basic organizational configurations (See Figure 12.8 ), identify the predominant design that works best for a health care organization. Please be sure to provide evidence to support your organizational design selec..
When performing logistics support analysis : When performing a logistics support analysis (LSA) you would have an activity that include LCC or LORA? I need to know if this statement is either true or false. This deals with the topic logistics. Give detail proof that its either true or false.
Implement a rule crypto that solves cryptarithmetic problems : Implement a rule "crypto" that solves the following cryptarithmetic multiplication problem: Each of the 4 letters (T,O,C,K) stands for a different digit. The 4 letters (G, R, I, P) can each be matched by any digit. The aim is to find a substitution..
Different resource required from entrepreneurial undertaking : Describe how the stakeholders will be apprised of the project's ongoing risk management activities? Identify and Explain 10 different resources required from Entrepreneurial undertaking. Describe the Importer Security Filing (ISF) (or called 10+2). W..
Explain the situation and why it is an ethical problem : Explain the situation and why it is an ethical problem. Propose a workable solution to the problem and why you believe this solution will work.
Can you see a possible conflict here for shuttles : There are also time-related behaviors to take account of: morning arrivals, evening departures, and local peaks of activity around lunchtimes?
How the balance between these two sets of data varies : Report on the statistical information that is being gathered by taxis and the passenger source; also on taxi idle time and missed pickups. Experiment with different numbers of taxis to see how the balance between these two sets of data varies.

Reviews

Write a Review

Programming Languages Questions & Answers

  Call the functions in the program

Have the main program call these functions to demonstrate how they work. Also, if you could help to explain to me how both constructors can be replaced with one constructor by using a single constructor with default parameters.

  Write temperature conversion application

Write down a temperature conversion application which converts from Fahrenheit to Celsius. Fahrenheit temperature must be entered from keyboard.

  Write a program that simulates battle between a cat and mice

I have written the program for the below assignment, but I am not getting the correct output. Below is the assignment and the program I have written along with the output I get.

  Determine the number of the nearest cross street

Write a function that uses a switch statement to determine the number of the nearest cross street for a given address and avenue number according to the preceeding alogorithm. Then write a program to test your function.

  Write application to which create-print random phone number

Write down the application which creates and prints random phone number of form xxx-xxx-xxxx. Write the dashes in output. Do not let first three digits contain 8 or 9.

  Add comment lines for the different sections.

Add comment lines for the different sections.

  Present the user with a menu with the given choices

CPSCI 121 - Object Oriented Programming: Present the user with a menu with the following choices: Output all values to the screen Add data values from a file Add a new data value from the keyboard.

  Program to convert temperature in celcius from fahrenheit

Write the program which accepts the temperature in Fahrenheit from user and conversts it to Celsius by subtracting 32 from Fahrenheit value and multiplying result by 5/9. Show both values.

  Create a multi-view program for the iphone

Compress the entire XCode project folder as a single zip, rar or other file format using an "archive file" or compression utility like PKZIP.

  Write program to calculate student-s quiz average

Write a program that will calculate a student's quiz average. The program should prompt the user for the number of quizzes and then ask the user for each quiz grade.

  Explain usability and accessibility in site design

A description of content to be included in site and how this content will be acquired. Attention should be given to copyright restrictions.

  Outline and critique how samsung has introduced and

outline and critique how samsung has introduced and developed a holistic system of tqm management and customer focused

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd