Data Structures and Algorithms (DSA) - LAPS-SOLS - home

kneewastefulAI and Robotics

Oct 29, 2013 (3 years and 9 months ago)

64 views

Logical Analysis and Problem Solving

-

Week 1

Page
1

of
4

Problem
Solving

P
roblem solving

is a highly sought after skill that
often
requires many
different
techniques
to be able to solve a
problem.
Problem solving may require logic skills, spatial skills, mathematical skills and general problem
solving skills.


The problems
below

cover a number of differing
types

of s
kill
.


Logic Puzzles

A snail is at the bottom of a 20m deep pit. Every day the snail climbs 5m but at night it slides back 4m. How
many days does it take before the snail reaches the top of the pit
?


Solution.

At the end of each day the snail will be 1 m further away from the bottom. Each day it will claim 5m up from its
starting point. So at the end of day 15 it will 15m up from the bottom. During day 16 it will climb 5m and so will
reach the top o
f the pit and hence be able to escape.


N.B. there is an assumption here that the snail will climb 5 m before slipping back during any one day.


Yesterday evening, Helen and her husband invited their two neighbours (couples) for a dinner at home. The six
sat at a round table. Helen tells you the following:




Victor sat on the left of the woman who sat on the left of

the man who sat on the left of Anna.



Esther sat on the left of the man who sat on the left of the woman, who sat on the left of the man who sa
t
on the left of the woman who sat on the left of my husband.



I did not sit beside my husband.



Jim sat on the left of the woman who sat on the left of Roger.


What is the name of Helen’s husband?



Solution.

Looking at the information given initially we ca
n see that there a number of people involved here, namely Helen,
Victor, Anna, Esther, Jim and Roger. Given that there are 6 people round the table the second statement helps us
arrange them as alternating pairs of man and woman. So on way of looking at th
is would be as follows:

-

statement 1: Victor sat on the left…..: , Anna, man, woman, Victor, man, woman.

-

statement 2: Esther sat on the left…..:
Helen’s Husband, woman, man, woman, man,
Esther.

-

Statement 3: I did not…: false to say Helen’s husband, Helen

or Helen Helen’s husband

-

Statement 4: Jim sat on the left…: woman, man, woman, Jim, woman, Roger.


Helen




Helen




Helen



Helen


Man


Man



Man


Man



Man


Victor


Jim

Victor


Woman

Woman



Woman

Esther



Anna


Esther


Anna


E
sther


Man




Man




Man



Roger


H Husband




H Husband



H Husband



H Husband






Spatial Puzzle

How many squares are there on a chess board?

How many rectangles are there on a chess board?

Simplify this puzzle by starting off w
ith a smaller board e.g. 3


3, 4


4 etc.


Solution.

Squares on a chess board.

Start with a single square, a one by one square or a 1 x 1 board has 1
2
squares.

A two by two square has 2 x 2 individual inner squares and 1 large outer square so has 5 square
s.

A three by three square has 3 x 3 individual squares, 2 x 2 two squares, and 1 large outer square so has 14
squares,

Logical Analysis and Problem Solving

-

Week 1

Page
2

of
4

A four by four square has 4 x 4 individual inner squares, 2 x 2 three squares, 3 x 3 two squares and one
large outer square and so has 3
0 squares.


A 2 x 2 square has 5 squares







A 3 x 3 square has 14 squares











1

1






3

3




1

1


2

2



3

3


4

4




2

2






4

4


If we see these as the number of individual squares i.e. 3
2
, plus the number of squares of size 2 i
.e. 4,
plus 1 for the outer square then we have the beginnings of a pattern.


Looking at a 4 x 4 square we can see that there will be 4
2

individual squares, 4 squares of size 3, 9
squares of size 2 plus 1 for the outer square. So there will be 16 + 4 + 9

+ 1 = 30 squares.

This is actually
4
2
+3
2
+2
2
+1.


For a chess board which is 8 x 8 then the number of squares is equal to 8
2
+ 7
2
+6
2
+5
2
+4
2
+3
2
+2
2
+1 = 64
+ 49 + 36 + 25 + 16 + 9 + 4 + 1 =
204


The Miller’s Stone.

A miller has a stone weighing 40 kilo
grams. He drops it and it breaks into 4 pieces which weigh 1kg, 3kg, 9kg
and 27kg.

That’s lucky
,

he said, I can now weigh everything between 1kg and 40kg. How does the miller do it?


Solution.

The key issue here is recognising that by putting stones on bo
th sides of a weighing machine you can
weigh all values (whole kilograms only) between 1 and 40


see below.

Wt

L

R

Wt

L

R

Wt

L

R

Wt

L

R

1

-

1

11

1

9 + 3

21

9

27+3

31

-

27+3+1

2

1

3

12

-

9 + 3

22

9

27+3+1

32

3+1

27+9

3

-

3

13

-

9+3+1

23

1+3

27

33

3

27+9

4

-

1 + 3

14

1+3+9

27

24

3

27

34

3

27+9+1

5

1 + 3

9

15

3+9

27

25

3

27+1

35

1

27+9

6

3

9

16

3+9

27+1

26

1

27

36

-

27+9

7

3

9 + 1

17

9+1

27

27

-

27

37

-

27+9+1

8

1

9

18

9

27

28

-

27+1

38

1

27+9+3

9

-

9

19

9

27+1

29

1

27+3

39

-

27+9+3

10

-

9 + 1

20

9+
1

27+3

30

-

27+3

40

-

27+9+3+1



Rectangles on a Chess Board.


To recognise the pattern here a good approach is to identify the dimensions of rectangles that could be
present in the overall square and then to work out how many rectangles of that size coul
d be represented
and then to create table to represent this. Remember a square is a special type of rectangle so the answer
will always be greater than the number of squares ( for all squares of size greater than 1 x 1). Look at the
following examples and
see if you can apply the approach for the 8 x 8 chess board.




Logical Analysis and Problem Solving

-

Week 1

Page
3

of
4




Here there 4 individual squares
, 1 outer square and 4 rectangles, 2 of size 2 x 1 vertically and also 2 of
the same size horizontally.

The table for this looks like:

Dimension


1

2


Posi
tions

2

1

1

2

4

2

2

1

2

1

Total



9


For a 3 x 3 square there are 9 individual squares, 1 outer square, 6 of size 3 x 2 horizontally and
vertically,
4 of size 2 x 2, 3 of size 3 x 1 both horizontally and vertically, 4 of size 2 x 3 both horizontally
a
nd vertically and 1 outer square = 9 + 12 + 6 + 8 + 1 = 36.


Dimension


1

2

3


Positions

3

2

1

1

3

9

6

3

2

2

6

4

2

3

1

3

2

1

Total




36


Can you extend this for a 4 x 4 and hence to the 8 x 8 chess board?


Letters for Numbers





F

O O

D








F

A

D

+





D I

E T

S


In the above addition
,

each letter stands for a different digit
, 0 to 9
. Find the digits corresponding to each letter.


So
lution

This is a problem that requires you to recognise some

simple

arithmetic points
. So far exam
ple F + O
must generate a carry because F + nothing generates a carry. So F must be a 9 since the carry cannot be
greater than 1, and I must be 0 since F + 1 must be 10 i.e. 0 and 1 to carry. Similarly if D is the carry
from F + 1 then D is 1. If D is 1 t
hen S must be 2. So we can restate that problem as:



9OO1




9A1

10ET2


Now the use of ‘O’ in 2 additions makes life a bit easier
. ‘O’ must be in the range 3 to 8, and we know
that ‘O + A’ = T and ‘O + 9 = E’.

If we assume ‘O’ is 3 then 3 + 9 = 12 hence

E must be 2 however we know that S is 2 so ‘O’ cannot be 3.
Suppose ‘O’ = 4 then 4 + 9 = 13 hence E is 3. ‘4 + ‘A’ = ‘T’.

If our assumption s that O = 4 and E = 3 then ‘A’ and ‘T’ must be in the range 5 to 8. However the
smallest value that ‘A’ can be is

5 and 4 + 5 is greater than the maximum value that ‘T’ can be. So our
assumption that ‘O’ is 4 must be wrong.

Assume ‘O’ = 5 then 5 + 9 = 14 hence E = 4. Returning to ‘O + A = T’ we now have ‘4 + A = T’ where
A and T can be any of the values [3, 6,7,8].
A
ssume ‘A’ = 3 then ‘4 + 3 = T’ means T = 7. These values
all work.



9441



931


_____


10372

Exercise

Using the decision tree Excel file, create a plan for how you solved the number of rectangles on the chess board.


ELIZA

Program

Logical Analysis and Problem Solving

-

Week 1

Page
4

of
4

This module

is taken to give students background knowledge in computing. A major issue within computing is
whether developers can create intelligent systems. What represents an intelligent system?


A program ELIZA was created in the 1960’s to simulate the behaviour

of a therapist, in an intelligent manner.


Have a look at the ELIZA program on web site:

http://www
-
ai.ijs.si/eliza/eliza.html


Try to, initially, use

the program in a realistic way.

Is ELIZA intelligent?


Try to use ELIZA with unusual answers to questio
ns. What rules do you think ELIZA has built into it?

Try to write down what rules might be built
-
in to ELIZA.


Exercise

Using the rules that you think might be built
-
in to ELIZA
,

capture screen shots of questions and answers, using
Hypercam or by pressing

the Alt key and Print Screen buttons
,

and pasting the screen shots as required

in
Microsoft Word, or similar
, and add commentary to the screen shots.