[Solved] Programming Problem2-Logic programming using PROLOG

$25

File Name: Programming_Problem2-Logic_programming_using_PROLOG.zip
File Size: 480.42 KB

SKU: [Solved] Programming Problem2-Logic programming using PROLOG Category: Tag:
5/5 - (1 vote)

Problem 1: Message Decoding

Alok sent a message to Boman containing letters from A-Z which is encoded to numbers using the following rules : A -> 1

B -> 2

Z ->26

Write a PROLOG program to determine the number of possible message(s) Boman could get after decoding the message from Alok. Define the following predicate Decode (String)

E.g. ?-Decode(7) 1 (G)

?-Decode(25)

2 (either BE (2,5) or Y (25))

Problem 2: Diwali Dinner

As a part of Diwali celebration, a special dinner is arranged in your hostel. The menu of the same is prepared along with their nutrient values as shown below

Starter Main Dish Desert
Corn Tikki (30)Tomato Soup (20)Chilli Paneer (40)Crispy chicken (40)Papdi Chaat (20)Cold Drink (20) Kadhai Paneer with Butter / Plain Naan (50)Veg Korma with Butter / Plain Naan (40)Murgh Lababdar with Butter / Plain Naan (50)Veg Dum Biryani with Dal Tadka (50)Steam Rice with Dal Tadka (40) Ice-cream (20)Malai Sandwich (30)Rasmalai (10)

Consider the following

  1. You are allowed to choose items from the menu in the following manner
    1. One item from each category (Starter, Main Dish and Desert) if you choose from all categories
    2. If you want to skip one or more categories, you can choose any number of items from your selected category(s) but with a limit in the nutrient value of 80
  2. You may be very hungry, not so hungry or on a diet
  3. If you are very hungry, you select one item each from Starter, Main dishes and Desert
  4. If you are not so hungry (or have placement test tomorrow), you might want to only have a Starter and a Main dish or a Desert and a Main dish
  5. If you are currently on a diet, you are concerned about the nutrient content of each food item. You would select only a single category and take food not exceeding nutrient value of 40.

Write a program in PROLOG which should be able to find menus/ items for you depending on whether you are hungry, not so hungry or on a diet.

  1. Define menu(Status,X,Y,Z) which will either find if a selected menu category choice is valid or not.

Status is <hungry,not so hungry, diet> and X, Y, Z are a starter, a main dish, and a desert, respectively. Value X, Y, Z can be either 0 or 1 (0 means not selected and 1 means selected) Eg. ?- menu(diet, 1,0,0)

True

?- menu (hungry,X,Y,Z)

X=1

Y=1

Z=1

  1. Also define find_items (status,X,Y,Z) to find out the possible combination of items from the selected categories

Eg. ?- find_items (not_so_hungry, 1,1,1)

False

?- find_items (diet, 0,1,0)

Items: Veg Korma with Butter / Plain Naan

Items: Steam Rice with Dal tadka

Problem 3: Prisoner Escape Problem

There is a jail in a hilly area with a steep mountain on one side and a river with crocodiles on another side. The prisoners are kept inside core unit of the jail for their entire life. To get rid of the sufferings, sometimes the prisoners try to escape from this place. The map of the jail is shown below. The prisoners do not have the idea about the map.

On the New Year celebration, all the security personnel were busy in other tasks. So, in the meantime the prisoners made plans to escape from the jail.

The core unit has 4 gates (G1, G2, G3, G4) which open towards corridor1 (C1). C1 has two outward gates

(G5, G6) which open towards corridor2 (C2). C2 has four outward gates (G7, G8, G10 and G11). It is not possible to escape from the jail through G7 or G9 because of the steep mountain and the river with crocodiles. But the prisoner may try those two gates.

There are two bounded land outwards of gate G10 and G12 and one tunnel which is connected to G11, G13 and G15. The tunnel is directly connected to the core unit of the jail. There is a blocked road ahead of G18. G17 is a gate which is open towards outside. The prisoner may return to his previous position if required.

The distance between each pair of gated which can be directly visited are as follows:

G1G5 = 4ft, G2G5=6ft, G3G5=8ft, G4G5=9ft, G1G6=10ft, G2G6=9ft, G3G6=3ft,

G4G6=5ft, G5G7=3ft, G5G10=4ft, G5G11=6ft, G5G12=7ft, G5G6=7ft, G5G8=9ft, G6G8=2ft, G6G12=3ft, G6G11=5ft, G6G10=9ft, G6G7=10ft, G7G10=2ft, G7G11=5ft, G7G12=7ft, G7G8=10ft, G8G9=3ft, G8G12=3ft, G8G11=4ft, G8G10=8ft, G10G15=5ft, G10G11=2ft, G10G12=5ft, G11G15=4ft, G11G13=5ft, G11G12=4ft, G12G13=7ft, G12G14=8ft, G15G13=3ft, G13G14=4ft, G14G17=5ft, G14G18=4ft, G17G18=8ft.

When the distance is given between a pair of gates, it means the prisoner can move between the pair of gates in any order. For example, distance between G1G5=4ft means the prisoner can move from G1 to G5 and vice-versa.

For the above scenario:

  1. Write a PROLOG program to find all possible paths for a prisoner to escape from the jail.
  2. Find the optimal path for the prisoner to escape. Optimal path is a path in which the prison has to cover minimum distance to escape from the jail.
  3. Given a path, your program should be able to find if it is valid or invalid in terms of escaping the jail.

Sample Input/Output:

Input:

Optimal(X)

Output:

G3G6G12G14G17

Input:

Valid ([G1, G6, G8, G9, G8, G7, G10, G15, G13, G14, G18, G17]) [The argument is a list] Output: True

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] Programming Problem2-Logic programming using PROLOG
$25