Information Technology Reference
In-Depth Information
3.
Use Prolog to solve the cryptarithmetic puzzle CROSS + ROADS = DANGER .
Note: If you are not careful with the ordering of constraints in your program,
the program could run for hours. With a proper ordering, it should only take a
second or so. Explain briefly the order you have chosen.
4.
Consider the following problem:
Donna, Danny, David, and Doreen were seated at a table in a restaurant.
The men sat across from each other, as did the women. They each ordered a
different main course with a different beverage. In addition,
- Doreen sat beside the person who ordered steak.
- The chicken came with a Coke.
- The person with the lasagna sat across from the person with milk.
- David never drinks coffee.
- Donna only drinks water.
- Danny could not afford to order steak.
Who ordered the pizza?
Write a Prolog program that solves this problem by displaying who ordered each
of the main courses and each of the beverages. Hint: Begin by writing clauses
defining predicates beside (
)
x , y
, which holds if person x is sitting beside person
y , and across (
)
x , y
, which holds if person x is sitting across from person y .
5.
Many newspapers feature a puzzle called KenKen in the recreational section.
The KenKen puzzle is similar to Sudoku except that arithmetic relations are
involved. Write a Prolog program that solves a 4
×
4 KenKen puzzle taken from
a newspaper.
Hint: You will need the uniq predicate used for the Sudoku problem for the rows
and for the columns. It will also be convenient to define two auxiliary predicates,
sub and div , where sub (
x , y , z
)
holds when either z
=
x
y or z
=
y
x , and
div (
x , y , z
)
holds when either z
=
x
÷
y or z
=
y
÷
x .
6.
The answers submitted by five students to a true/false quiz are as follows:
Teresa: true, true, false, true, false
Tim: false, true, true, true, false
Tania: true, false, true, true, false
Tom: false, true, true, false, true
Tony: true, false, true, false, true
 
Search WWH ::




Custom Search