Implement a rule crypto that solves cryptarithmetic problem

Assignment Help Programming Languages
Reference no: EM131305271

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:

"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" from Homework #2 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" from Homework #2 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:

1. I recommend using the SWI-Prolog system.

2. You are only allowed to use basic functions which do not make the problems trivial.

Reference no: EM131305271

Questions Cloud

Described the situation of a feedlot owner : Described the situation of a feedlot owner who "uses derivatives to hedge the price he pays for feed and the price he gets for steers."
Would you have bought or sold these futures contracts : If you were a speculator who expected interest rates to fall, would you have bought or sold these futures contracts? Briefly explain.
Identify the independent variable and the dependent variable : Explain why Dr. Jones can be reasonably confident that the participants' age is not a confounding variable. That is, explain why it is unlikely that one group does better on the memory task because they are substantially older than the other group..
Why is a prospectus necessary in doctoral level work : Why is a prospectus necessary in doctoral level work.Piaget found dramatic differences in development between preschoolers and elementary-age children. Discuss several of these differences from cognitive, physical, and psychosocial perspectives.
Implement a rule crypto that solves cryptarithmetic problem : Programming Languages Assignment. Implement a rule "crypto" that solves the following cryptarithmetic multiplication problem: TOCK * TOCK = GRIPTOCK
Discuss about the adhd characteristic traits : Discuss about the ADHD Characteristic Traits,Environmental and Biological Influences,Attention Deficit Disorders With or Without Hyperactivity (ADHD) etc.
How might you hedge against the risk : Will you be more worried about market interest rates rising or falling? Briefly explain.- How might you hedge against the risk you identified in part (a)?
What type of investor would find the futures contract : What type of investor would find this futures contract useful in speculating? Briefly explain how these investors would use it to speculate.
Describe gender differences for the social interactions : Describe the effectiveness of a new program (compared to the old program) for teaching reading to elementary school students.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write program using array to show fifo queue

Write program using any language which uses the array to demonstrate simple FIFO queue with 10 job entering the queue and 5 jobs removed from the queue by the server.

  Write a paper discussing threads vs processes

Write a paper discussing Threads vs Processes. What is a Thread? What is a Process? How are they different? How are they the same? What types of problems lend themselves to Threads?

  A program is required which prompts the user

A program is required which prompts the user to enter the individual price of 3 different items and computes and prints the total cost of the 3 items as well as the average cost. remember to add sales tax (5% or 0.05) to the total cost.

  Create a math tutoring program

You are being contracted to create a math tutoring program for a local elementary school.  This tutoring software should ask children which operation they would like to work on

  Write a function that uses stream-map

Now write a function that uses stream-map to produce the sum of two streams element by element for the first x elements . Be sure to test with several different types of streams (for example, you could sum together the odd and even numbers betwee..

  Create class for factory workers are paid certain amount

Create class for Factory workers are paid a certain amount for each unit they make and their total pay is the number of units produced times the pay per unit.

  Implement an android application with the requirements

Design and implement an Android application with the requirements - Just one database that contains all data for the list, list items, widgets, text fields and activities mentioned in the above requirements.

  Write a report of about 900 words that- identifies at least

write a report of about 900 words that- identifies at least 3 users of hr services internal to your organisation and

  Divide the input space for the into three equivalence class

Furthermore, you may further divide the third classes into more classes: inputs whose length is long than 60 but less than 120, inputs whose length is long than 120 but less than 180, etc...

  Write a program to enter any number of integers in array

Write a program which permits a user to enter any number of integers, which are then stored in the array. After user enters integers, perform the following operations on array.

  Design and implement a java program

Design and implement a Java program which defines an array of size SIZE, randomly populated with Integer or int values in the range 1 .. MAXRNG and sorts the array in increasing order of its values using QuickSortOpt1 and then by QuickSortOpt2. Consi..

  Features of object oriented programming

Write a 200- to 300-word short-answer response to the following: Describe the main features of Object Oriented Programming - Encapsulation, Inheritance and Polymorphism

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