MathCAD

       

Fig. 6.22. The Fishermen's Problem: 'unprogrammed' Mathcad solution (6_21_fisherman.mcd)


This problem can be solved in Mathcad without resorting to programming. Fig. 6.22 shows how this might be done how by successive manual approximations, with Mathcad just automating the division procedure. We set a first guess at 50 fish and see if the division works; if not, we try 49; and so on, decrementing the guess by one if the division produces a non-integer at any stage. Eventually, we guess at 25 fish, and this proves to be a solution. The first fisherman throws away a fish, and takes eight, leaving 16 (eight each for the others, he thinks). The second (not knowing what the first has done) leaves ten; and the third, six.

This solves the task – but by applying 'manual' work in setting the value of the variable Catch and decrementing the value of the variable Answer. (Note that duplicating the block of operators fixing the actions of the three fishermen, though done for clarity in Fig 6.22, isn't necessary. It's sufficient to decrement Answer

and keep track of Catch).

Let's try to automate the search for a solution to this task.

'1 Initial unstructured BASIC program

Input "Guess"; Answer

label: Catch = Answer

            For Fisherman = 1 To 3

                        Catch = Catch – 1

                        Catch = Catch - Catch / 3

                        If Catch > Int(Catch) Then Answer = Answer - 1: Goto label

            Next

Print



"Answer "; Answer; “fish”

'2. First stage of structuralization: a start

Input

"Guess"; Answer

Answer = Answer + 1 ‘ step backward

label: Answer = Answer - 1 ‘ step forward

            Catch = Answer

            For

Fisherman = 1 To 3

                        Catch = Catch – 1

                        Catch = Catch - Catch / 3

                        If Catch > Int(Catch) Goto label

            Next

Print

"Answer "; Answer; “fish”

 

'3. Second stage of structuralization: addition of an attribute

Input

"Guess"; Answer

Answer = Answer + 1


label: Answer = Answer – 1

Catch = Answer

            Divided = "yes" ’ indicates catch divided

            For

Fisherman = 1 To 3

                        Catch = Catch – 1

                        Catch = Catch - Catch / 3

                        If Catch > Int(Catch) Then Divided = “no”

            Next

If Divided = “no" Goto label

Print

"Answer "; Answer; “fish”

4. Third step of structuralization: disposal of the label

Input

"Guess"; Answer

Answer = Answer + 1

Do ’ start loop with checking on exit

            Answer = Answer – 1

            Catch = Answer

            Divided = "yes"

            For

Fisherman = 1 To 3

                        Catch = Catch – 1

                        Catch = Catch - Catch / 3

                        If Catch > Int(Catch) Then Divided = “no”

            Next

Loop Until Divided = "yes" ’ end loop

Print

"Answer "; Answer; “fish”


Ñîäåðæàíèå ðàçäåëà