06.09.2021 Views

Mind, Body, World- Foundations of Cognitive Science, 2013a

Mind, Body, World- Foundations of Cognitive Science, 2013a

Mind, Body, World- Foundations of Cognitive Science, 2013a

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

first solving a smaller version <strong>of</strong> the same kind <strong>of</strong> problem. To move a stack <strong>of</strong> n discs<br />

to location C, we first move the smaller stack <strong>of</strong> n – 1 discs to location B. “Moving the<br />

stack” is the same kind <strong>of</strong> procedure for the n discs and for the n – 1 discs. The whole<br />

approach is recursive in the sense that to move the big stack, the same procedure<br />

must first be used to move the smaller stack on top <strong>of</strong> the largest disc.<br />

The recursive nature <strong>of</strong> the solution to the Tower <strong>of</strong> Hanoi is made obvious if<br />

we write a pseudocode algorithm for moving the disks. Let us call our procedure<br />

MoveStack (). It will take four arguments: the number <strong>of</strong> discs in the stack to be<br />

moved, the starting location, the “spare” location, and the goal location. So, if we<br />

had a stack <strong>of</strong> three discs at location A, and wanted to move the stack to location C<br />

using location B as the spare, we would execute MoveStack (3, A, B, C).<br />

The complete definition <strong>of</strong> the procedure is as follows:<br />

MoveStack (N, Start, Spare, Goal)<br />

If N = 0<br />

Exit<br />

Else<br />

MoveStack (N – 1, Start, Goal, Spare)<br />

MoveStack (1, Start, Spare, Goal)<br />

MoveStack (N – 1, Spare, Start, Goal)<br />

EndIf<br />

Note the explicit recursion in this procedure, because MoveStack () calls itself to<br />

move a smaller stack <strong>of</strong> disks stacked on top <strong>of</strong> the disk that it is going to move. Note<br />

too that the recursive nature <strong>of</strong> this program means that it is flexible enough to work<br />

with any value <strong>of</strong> N. Figure 3-2 illustrates an intermediate state that occurs when<br />

this procedure is applied to a five-disc version <strong>of</strong> the problem.<br />

3<br />

2<br />

4<br />

A<br />

C<br />

0<br />

1<br />

B<br />

Figure 3-2. An intermediate state that occurs when MoveStack () is applied to a<br />

five-disc version <strong>of</strong> the Tower <strong>of</strong> Hanoi.<br />

Elements <strong>of</strong> Classical <strong>Cognitive</strong> <strong>Science</strong> 63

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!