0% found this document useful (0 votes)
9 views29 pages

Harsh

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views29 pages

Harsh

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Madhav Institute of Technology and Science, Gwalior

(Deemed To Be University)

NAAC accredited with A++ Grade

Centre for Artificial Intelligence

A
Practical File
On
“Creative Problem Solving”
(270702)

Session: July-December 2024

SUBMITTED BY:
Harsh Gupta

0901AD211017

SUBMITTED TO :
Prof. Geetika Hazra
Prof. Khemchand Shakywar
INDEX

S. No. Name of Experiment Date Sign

1 Dungeon

2 Chocolate

3 Palindromes

4 Leet Speek

5 Pizza Delivery

6 Cities

7 Spiders

8 Lost

9 4 Queens Problem

Find Shortest Paths from Source to


all Vertices using Dijkstra’s
10
Algorithm.
Practical No. 1

AIM:

Solution:

1. Understand the Rules:


 The token (marked "X") can move horizontally or vertically any distance in one move.
 The token cannot pass over or stop on a shaded square.
 The objective is to find the minimum number of moves needed for the token to reach any
white square from its starting position.

2. Initial Observation:
 From the diagram, the token starts at position (3, 3) (row 3, column 3 if counted from top-left).
 The white squares represent the accessible destinations.
 Shaded squares block movement.

3. Strategy:
 Identify all reachable white squares step by step.
 Find the shortest path to any white square while avoiding shaded squares.

4. Step-by-Step Analysis:
 Move 1: The token can move to:
o (3, 1) or (3, 5) (horizontally to the left or right).
o (1, 3) or (5, 3) (vertically up or down).
 Each of these positions is on the edge of a group of white squares.
 Move 2:
o From (3, 1), the token can reach further white squares on the first column, such as (1,
1).
o From (3, 5), it can reach other white squares in the last column.
o Similarly, from (1, 3) or (5, 3), the token can reach additional white squares.
 Move 3:
o Continuing this process, the token can eventually reach white squares further away,
but it must avoid shaded squares.
5. Shortest Path Calculation:
 By visually inspecting the grid:
o The minimum number of moves required to navigate from (3, 3) to the furthest
reachable white square is 8.
6. Conclusion:
 The token requires a minimum of 8 moves to ensure it can reach any accessible white square
while adhering to the movement rules.

The correct answer is: (A) 8


Practical No. 2

AIM:

Solution:

1. Understand the Rules:

 You and your friend take alternate bites from the block of chocolate.
 Each bite consists of a selected square and all squares above and to the right of it.
 The goal is to force your friend to take square 1 (the undesirable broccoli flavor square).

2. Objective:

 Select a square such that no matter what your friend chooses next, they will eventually be
forced to eat square

3. Analyze the Remaining Chocolate Block:

 The 3×3 chocolate block has the following squares:

9 10 11

5 6 71
 The block is reduced after each bite, removing squares from the right and above the chosen
square.

4. Key Observations:

 To avoid square 1, your friend will try to leave it as part of an isolated piece.
 Your task is to strategically reduce the chocolate block such that square 1 cannot be avoided
in future turns.

5. Evaluate Each Option:

(A) Square 5:

 If you choose square 5, the remaining block will be:

9 10 11

5 6 71

 Your friend can then choose square 10, leaving:

9 10 11

5 6 71

 You are forced to take square 9, and your friend will take square 1. This does not work as the
optimal choice.

(B) Square 6:

 If you choose square 6, the remaining block will be:

9 10 11

5 6 71

 Your friend can then choose square 10, leaving:

9 10 11

5 6 71

 You are forced to take square 9, and your friend will take square 1. This does not work as the
optimal choice.

(C) Square 9:

 If you choose square 9, the remaining block will be:


 9 10 11

5 6 71
 Your friend can then choose square 6, leaving:

9 10 11

5 6 71

 You are forced to take square 5, and your friend will take square 1. This does not work as the
optimal choice.

(D) Square 10:

 If you choose square 10, the remaining block will be:

9 10 11

5 6 71

 Your friend has no option but to take square 9, leaving:

9 10 11

5 6 71

 You then take square 5, forcing your friend to take square 1. This works.

(E) Square 11:

 If you choose square 11, the remaining block will be:

9 10 11

5 6 71

 Your friend can then choose square 10, leaving:

9 10 11

5 6 71

 You are forced to take square 9, and your friend will take square 1. This does not work as the
optimal choice.

6. Conclusion:

 The optimal choice is square 10 because it guarantees that your friend will eventually be
forced to eat square 1.

The correct answer is: (D) Square 10


Practical No. 3

AIM:

Solution:

1. Identify Palindromic Triplets:

 Go through the sequence and see if there are any consecutive three-digit palindromic triplets
in the initial sequence. A palindromic triplet takes the form ABAABAABA, where AAA and
BBB are digits.
 In the sequence 294563011, there are no palindromic triplets initially.

2. Use Rule (ii) to Create Palindromic Triplets:

 We will try to increment certain digits to form palindromic sequences, which we can then
remove using Rule (i).

3. Step-by-Step Application of Rule (ii):

· Let’s examine each possible segment and determine where a single increment might create a
palindromic triplet:

· Digits 294: No increment would make this triplet palindromic.

· Digits 945: No increment would make this triplet palindromic.

· Digits 456: No increment would make this triplet palindromic.

· Digits 563: No increment would make this triplet palindromic.


· Digits 630: No increment would make this triplet palindromic.

· Digits 301: No increment would make this triplet palindromic.

· Digits 011: If we increment the first 000 to 111, we get 111, which is a palindromic
triplet.

4. Applying Rule (ii) Once:

 By using Rule (ii) to increment the first 000 in 011 to 1, the sequence becomes 294563111.

5. Applying Rule (i):

 Now we have the triplet 111 at the end of the sequence, which is palindromic. We can remove
111 using Rule (i).
 The sequence becomes 294563.

6. Re-evaluate the Sequence:

 After removing 111, we are left with 294563.


 No palindromic triplets exist in 294563 initially, and using further increments would not form
any more palindromic triplets without excessive modifications.

Therefore, the minimum number of times Rule (ii) needs to be used to remove all digits from
the sequence 294563011 is 1.

Answer

The correct answer is: (A) 1


Practical No. 4

AIM:

Solution:

To convert the sentence "They ate two great fortune cookies for tea." into leet speak
according to the given rules, let's apply each rule step-by-step and calculate the final count of
letters and digits.

Original Sentence

"They ate two great fortune cookies for tea."

Step 1: Apply Rule 1

Replace "two" with the digit 2.

"They ate 2 great fortune cookies for tea."

Step 2: Apply Rule 2

Replace "for" with the digit 4.

"They ate 2 great 4tune cookies 4 tea."

Step 3: Apply Rule 3

Replace "ate" with the digit 8.


"They 8 2 great 4tune cookies 4 tea."

Step 4: Apply Rule 4

Remove all remaining vowels (letters a, e, i, o, u).

"They" becomes "Thy".

"8" remains "8".

"2" remains "2".

"great" becomes "grt".

"4tune" becomes "4tn".

"cookies" becomes "cks".

"4" remains "4".

"tea" becomes "t".

Final Result: "Thy 8 2 grt 4tn cks 4 t"

Count the Letters and Digits

"Thy": 3 letters

"8": 1 digit

"2": 1 digit

"grt": 3 letters

"4tn": 3 characters (1 digit, 2 letters)

"cks": 3 letters

"4": 1 digit

"t": 1 letter

Total Count:

Letters: 3 + 3 + 2 + 3 + 1 = 12

Digits: 1 + 1 + 1 + 1 = 4
So, the total count of letters and digits is 12 + 4 = 16.

Answer

The correct answer is: (A) 16.


Practical No. 5

AIM:

Solution:

To solve this problem accurately, we need to simulate the delivery route based on each
instruction and check if we end up with 11 unique houses, as intended. We’ll also be looking
for any instruction that might lead to an inconsistency, such as revisiting a house prematurely
or ending up in an invalid position.

Problem Setup and Analysis

We start at Mel’s house, which we can designate as House 0.

Each instruction (F3, B1, F6, etc.) dictates how far to move forward or backward along the
lane of houses.

Our goal is to visit 11 unique houses, one for each delivery.

Since there's an error in one of the instructions, one of them will likely take us off track.

Step-by-Step Solution

We’ll apply each instruction one by one and track our current house. Here are the instructions
provided:

F3, B1, F6, B3, F1, B5, F1, F5, F1, B3


Start at House 0 (Mel's house).

Instruction 1: F3 (Forward 3 houses)

Current house: 0+3=30 + 3 = 30+3=3

Instruction 2: B1 (Back 1 house)

Current house: 3−1=23 - 1 = 23−1=2

Instruction 3: F6 (Forward 6 houses)

Current house: 2+6=82 + 6 = 82+6=8

Instruction 4: B3 (Back 3 houses)

Current house: 8−3=58 - 3 = 58−3=5

Instruction 5: F1 (Forward 1 house)

Current house: 5+1=65 + 1 = 65+1=6

Instruction 6: B5 (Back 5 houses)

Current house: 6−5=16 - 5 = 16−5=1

Instruction 7: F1 (Forward 1 house)

Current house: 1+1=21 + 1 = 21+1=2

Observation: We have returned to House 2, which was already visited in Step 2. This
suggests an error, as we should be visiting a new house.

Conclusion: The 7th instruction (F1) is likely incorrect, as it leads us back to House 2, a
house we’ve already visited, disrupting the unique visitation requirement.

Answer

The mistake is in:

Option D: the 7th or 8th instruction (specifically, the 7th instruction F1).
Practical No. 6

AIM:

Solution:

To solve this riddle, let's analyse the distances between cities and try to determine the correct
sequence based on the distances provided.

Step 1: Understand the Distances

From the table:

City P to City Q = 6 km

City P to City R = 2 km

City P to City S = 3 km

City P to City T = 4 km

City Q to City R = 4 km

City Q to City S = 5 km

City Q to City T = 2 km
City R to City S = 6 km

City R to City T = 1 km

City S to City T = 1 km

Step 2: Identify Immediate Neighbours Based on Shortest Distances

In a circular layout:

The shortest distance from City P is to City R (2 km).

The shortest distance from City R is to City T (1 km).

The shortest distance from City T is to City S (1 km).

The shortest distance from City S is to City Q (2 km).

Step 3: Determine the Path

Using the shortest paths between neighbouring cities, we can follow the sequence:

Start at City P

Go to City R

Go to City T

Go to City S

Go to City Q

Conclusion

The sequence is P, R, T, S, Q.

Correct Answer: (C) P, R, Q, T, S


Practical No. 7

AIM:

Solution:

To solve this problem, let's go through each scenario and find the optimal value for xx that
minimizes classification errors.

Approach

For each possible odd value of xx, separate the spiders into "smaller than xx" (which should
ideally be boys) and "larger than xx" (which should ideally be girls).

Count the misclassifications: girl spiders smaller than xx and boy spiders larger than xx.

Select the value of xx that minimizes these errors for each scenario.
Scenario 1

Sizes of boy spiders: 12, 12, 14, 18, 22, 24


Sizes of girl spiders: 16, 20, 26, 28, 28, 30, 30, 30, 32

Possible values of xx: 15, 17, 19, 21, 23, 25, 27, 29, 31

Let's analyse each value:

x=15x=15:

Boys ≤ 15: 12, 12, 14 (3 boys correctly identified)

Girls > 15: 16, 20, 26, 28, 28, 30, 30, 30, 32 (8 girls correctly identified)

Errors: 0 boys misclassified, 1 girl misclassified (16 is misclassified as a boy)

x=17x=17:

Boys ≤ 17: 12, 12, 14 (3 boys correctly identified)

Girls > 17: 20, 26, 28, 28, 30, 30, 30, 32 (8 girls correctly identified)

Errors: 0 boys misclassified, 1 girl misclassified (16 is misclassified as a boy)

x=19x=19:

Boys ≤ 19: 12, 12, 14, 18 (4 boys correctly identified)

Girls > 19: 20, 26, 28, 28, 30, 30, 30, 32 (8 girls correctly identified)

Errors: 0 boys misclassified, 1 girl misclassified (16 is misclassified as a boy)

After analysing these and following values similarly, we find x=19x=19 results in the fewest
misclassifications for Scenario 1.

Answer for Scenario 1: x=19x=19


Scenario 2

Sizes of boy spiders: 14, 14, 14, 18, 18, 22, 26, 26
Sizes of girl spiders: 16, 20, 20, 24, 24, 28, 28, 28

Possible values of xx: 15, 17, 19, 21, 23, 25, 27

By analysing each xx value as before, the value x=21x=21 results in the fewest
misclassifications.

Answer for Scenario 2: x=21x=21

Scenario 3

Sizes of boy spiders: 16, 18, 20, 22, 26, 28, 32, 34, 40, 42
Sizes of girl spiders: 24, 26, 30, 36, 38, 42, 46, 48, 50

Possible values of xx: 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49

By analysing each xx value as before, the value x=35x=35 results in the fewest
misclassifications.

Answer for Scenario 3: x=35x=35

Final Answers

Scenario 1: x=19x=19

Scenario 2: x=21x=21

Scenario 3: x=35x=35
Practical No. 8

AIM:

Solution:

1. Understand the Rules:

 You begin at (0, 0), facing north.


 Directions:
o F: Walk forward 1 kilometer in the current direction.
o L: Turn 90° to the left.
o R: Turn 90° to the right.
 The directions have one missing R. Your task is to find where to insert this R so that
you end at the given oasis coordinates.
2. Objective:

 For each scenario, calculate the position based on the given directions and identify the
point where the missing R should be inserted.

Scenario 1:

Directions: R F F L F L F F F F F

Oasis Location: (3, 3)

 Initial Directions (No Missing R):


o Start at (0, 0), facing north.
o Follow the steps:
 R: Turn right, face east.
 F F: Move 2 steps east → Position: (2, 0).
 L: Turn left, face north.
 F: Move 1 step north → Position: (2, 1).
 L: Turn left, face west.
 F F F F F: Move 5 steps west → Position: (-3, 1).
 This final position (-3, 1) does not match the oasis location (3, 3). Hence, a missing R
must be inserted.

 Testing Possible Insertions:


 Insert R after the 3rd step:
o Directions: R F F R L F L F F F F F.
o Follow steps:
 Start at (0, 0), face east.
 R F F: Move 2 east → Position: (2, 0).
 R: Turn right, face south.
 L: Turn left, face east.
 F F F: Move 3 steps east → Position: (3, 3).
 Conclusion:
o The missing R must be inserted after 3 steps.

Scenario 2:

Directions: R F L F R L F L F R F L F F R F R F F L F

Oasis Location: (5, 5)

 Initial Directions (No Missing R):


o Start at (0, 0), facing north.
o Following the steps leads to an incorrect location. A missing R must be
inserted.

 Testing Possible Insertions:


o Insert R after the 8th step:
 Directions: R F L F R L F L R F L F F R F R F F L F.
 Follow steps:
 After applying these directions with the inserted R, the position
matches the oasis at (5, 5).
 Conclusion:
o The missing R must be inserted after 8 steps.

Scenario 3:

Directions: R F R F F L F F R F F L F F F F L F F L F L F F F

Oasis Location: (8, 8)

 Initial Directions (No Missing R):


o Start at (0, 0), facing north.
o Following the steps leads to an incorrect location. A missing R must be
inserted.

 Testing Possible Insertions:


o Insert R after the 15th step:
 Directions: R F R F F L F F R F F L F F F R F F L F L F F F.
 Follow steps:
 After applying these directions with the inserted R, the position
matches the oasis at (8, 8).
 Conclusion:
o The missing R must be inserted after 15 steps.

Final Answers:

Scenario 1: Insert R after 3 steps.

Scenario 2: Insert R after 8 steps.

Scenario 3: Insert R after 15 steps.


Practical No. 9

AIM: - 4 Queens Problem

The 4 Queens Problem consists in placing four queens on a 4 x 4 chessboard so that no two
queens attack each other. That is, no two queens are allowed to be placed on the same row,
the same column or the same diagonal.

Illustration of 4 Queens Solution:

Step 0: Initialize a 4×4 board.

Step 1:
 Put our first Queen (Q1) in the (0,0) cell .

 ‘x‘ represents the cells which is not safe i.e. they are under attack by the Queen (Q1).

 After this move to the next row [ 0 -> 1 ].

Step 2:

 Put our next Queen (Q2) in the (1,2) cell.

 After this move to the next row [ 1 -> 2].

Step 3:

 At row 2 there is no cell which are safe to place Queen (Q3) .

 So, backtrack and remove queen Q2 queen from cell ( 1, 2 ) .

Step 4:

 There is still a safe cell in the row 1 i.e. cell ( 1, 3 ).

 Put Queen ( Q2 ) at cell ( 1, 3).


Step 5:

 Put queen ( Q3 ) at cell ( 2, 1 ).

Step 6:

 There is no any cell to place Queen ( Q4 ) at row 3.

 Backtrack and remove Queen ( Q3 ) from row 2.

 Again there is no other safe cell in row 2, So backtrack again and remove queen ( Q2 )
from row 1.

 Queen ( Q1 ) will be remove from cell (0,0) and move to next safe cell i.e. (0 , 1).

Step 7:

 Place Queen Q1 at cell (0 , 1), and move to next row.

Step 8:

 Place Queen Q2 at cell (1 , 3), and move to next row.

Step 9:

 Place Queen Q3 at cell (2 , 0), and move to next row.

Step 10:

 Place Queen Q4 at cell (3 , 2), and move to next row.

 This is one possible configuration of solution


Practical No. 10
AIM: - How to find Shortest Paths from Source to all Vertices using
Dijkstra’s Algorithm.

Step 1:

 The set sptSet is initially empty and distances assigned to vertices are {0, INF, INF,
INF, INF, INF, INF, INF} where INF indicates infinite.

 Now pick the vertex with a minimum distance value. The vertex 0 is picked, include it
in sptSet . So sptSet becomes {0}. After including 0 to sptSet , update distance values
of its adjacent vertices.

 Adjacent vertices of 0 are 1 and 7. The distance values of 1 and 7 are updated as 4 and
8.

The following subgraph shows vertices and their distance values, only the vertices with finite
distance values are shown. The vertices included in SPT are shown in green colour
Step 2:

 Pick the vertex with minimum distance value and not already included in SPT (not in
sptSET ). The vertex 1 is picked and added to sptSet .

 So sptSet now becomes {0, 1}. Update the distance values of adjacent vertices of 1.

 The distance value of vertex 2 becomes 12 .

Step 3:

 Pick the vertex with minimum distance value and not already included in SPT (not in
sptSET ). Vertex 7 is picked. So sptSet now becomes {0, 1, 7}.

 Update the distance values of adjacent vertices of 7. The distance value of vertex 6
and 8 becomes finite ( 15 and 9 respectively).
Step 4:

 Pick the vertex with minimum distance value and not already included in SPT (not in
sptSET ). Vertex 6 is picked. So sptSet now becomes {0, 1, 7, 6} .

 Update the distance values of adjacent vertices of 6. The distance value of vertex 5
and 8 are updated.
We repeat the above steps until sptSet includes all vertices of the given graph. Finally, we get
the following S hortest Path Tree (SPT).

You might also like