Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solving a Puzzle by Encoding it in Prolog: solve/1 The following puzzle needs to expressed as a prolog program. The puzzle is the folloWing: Four

image text in transcribedimage text in transcribed

Solving a Puzzle by Encoding it in Prolog: solve/1

The following puzzle needs to expressed as a prolog program. The puzzle is the folloWing: Four suspects a, b, c, and d were rounded up for questioning concerning a robbery. It was known for sure that at least one of them was guilty and that no one outside these four were involved. The following facts turned up: 1. a was definitely innocent. 2. if b was guilty then he had exactly one accomplice. 3. ifc was guilty then he had exactly two accomplices. You need to write a predicate, solve(Guilty), which when called with a variable will return one of the possible gangs (as lists) of people who could have committed the robbery together, given the facts above. Your predicate needs to handle redo's, i.e., after your predicate returns at the top-level, if you type in a "," then if there is another gang that could have committed the crime, then it should be returned, when there are no more gangs that could have committed the crime together then it should fai Every code line must end in a comment describing what the code does. You will want to use the subset/2 predicate (which is defined below) subset(].[ subset([XIL],[XIS): subset(L,S) The following puzzle needs to expressed as a prolog program. The puzzle is the folloWing: Four suspects a, b, c, and d were rounded up for questioning concerning a robbery. It was known for sure that at least one of them was guilty and that no one outside these four were involved. The following facts turned up: 1. a was definitely innocent. 2. if b was guilty then he had exactly one accomplice. 3. ifc was guilty then he had exactly two accomplices. You need to write a predicate, solve(Guilty), which when called with a variable will return one of the possible gangs (as lists) of people who could have committed the robbery together, given the facts above. Your predicate needs to handle redo's, i.e., after your predicate returns at the top-level, if you type in a "," then if there is another gang that could have committed the crime, then it should be returned, when there are no more gangs that could have committed the crime together then it should fai Every code line must end in a comment describing what the code does. You will want to use the subset/2 predicate (which is defined below) subset(].[ subset([XIL],[XIS): subset(L,S)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions