+ All Categories
Home > Documents > Mathematics and I.T. || Investigating with LOGO. Part Four: Paths and Paving Stones

Mathematics and I.T. || Investigating with LOGO. Part Four: Paths and Paving Stones

Date post: 23-Dec-2016
Category:
Upload: trevor-fletcher
View: 212 times
Download: 0 times
Share this document with a friend
3
Investigating with LOGO. Part Four: Paths and Paving Stones Author(s): Trevor Fletcher Source: Mathematics in School, Vol. 22, No. 5, Mathematics and I.T. (Nov., 1993), pp. 36-37 Published by: The Mathematical Association Stable URL: http://www.jstor.org/stable/30215052 . Accessed: 08/04/2014 16:52 Your use of the JSTOR archive indicates your acceptance of the Terms & Conditions of Use, available at . http://www.jstor.org/page/info/about/policies/terms.jsp . JSTOR is a not-for-profit service that helps scholars, researchers, and students discover, use, and build upon a wide range of content in a trusted digital archive. We use information technology and tools to increase productivity and facilitate new forms of scholarship. For more information about JSTOR, please contact [email protected]. . The Mathematical Association is collaborating with JSTOR to digitize, preserve and extend access to Mathematics in School. http://www.jstor.org This content downloaded from 81.23.53.34 on Tue, 8 Apr 2014 16:52:27 PM All use subject to JSTOR Terms and Conditions
Transcript

Investigating with LOGO. Part Four: Paths and Paving StonesAuthor(s): Trevor FletcherSource: Mathematics in School, Vol. 22, No. 5, Mathematics and I.T. (Nov., 1993), pp. 36-37Published by: The Mathematical AssociationStable URL: http://www.jstor.org/stable/30215052 .

Accessed: 08/04/2014 16:52

Your use of the JSTOR archive indicates your acceptance of the Terms & Conditions of Use, available at .http://www.jstor.org/page/info/about/policies/terms.jsp

.JSTOR is a not-for-profit service that helps scholars, researchers, and students discover, use, and build upon a wide range ofcontent in a trusted digital archive. We use information technology and tools to increase productivity and facilitate new formsof scholarship. For more information about JSTOR, please contact [email protected].

.

The Mathematical Association is collaborating with JSTOR to digitize, preserve and extend access toMathematics in School.

http://www.jstor.org

This content downloaded from 81.23.53.34 on Tue, 8 Apr 2014 16:52:27 PMAll use subject to JSTOR Terms and Conditions

INVES WI

logo

PART FOUR by Trevor Fletcher

Paths and Paving Stones Glynis Drinkwater's article on "Paths and Paving Stones" (1992) has aroused considerable interest. To add to the discussion here are some suggestions for using Logo to follow up the line of enquiry in Dave Faulkner's article of the same name (1993).

APPENDIX MAKE "d 50 TO V REPEAT 2 [FD :d LT 90 FD 2 " :d LT 90] FD :d END TO H LT90 FD 2*:d LT 180 VV LT90 FD 2*" :d END

The original problem concerned laying a footpath of width two units and length N units, using paving stones measuring one unit by two. At any stage of the construction the path may be extended by adding a pair of longitudinal stones or a single transverse stone. Faulkner is particularly concerned with calculating the number of recognisably different paths of length N, using varying numbers H of longitudinal pairs of stones. He uses the term "horizontal" to describe these; the meaning is clear and we will continue to speak of "horizontal pairs" and "vertical singles". In Drinkwater's original situation all of the stones were horizontal because they were placed on the ground; but we will be drawing them on a computer screen where Faulkner's terminology is appropriate.

We will first use the list handling capability of Logo to construct lists to describe the configurations which Drinkwater and Faulkner draw in their diagrams. If we denote a horizontal pair by H and a vertical single by V the problem is to produce the appropriate lists of Hs and Vs.

With many combinatorial problems it is helpful to think of having a hand of cards of some kind, and laying them down on the table as in a game of patience, the rules of which embody the problem in question. In this case imagine holding a hand of cards some bearing a letter H and the others bearing a letter V. At some given time we have laid a few of the cards on the table and we then have to lay another one. If we have any Hs left we can lay an H, or if we have any Vs we can lay a V. If we wish to construct all possible paths both possibilities have to be explored if both types of card are available.

If no more cards are available the list is complete (for that experiment) and we can declare what it is.

This leads to a repeatedly branching line of argument, and it is precisely at this stage that computers manage better than we do! We have to write a Logo procedure which embodies the situation just described.

Let us call the cards which we have placed on the table so far the "list", and suppose that h H-cards and v V-cards remain. Translating the situation into Logo terms, when we consider placing the next card down our thoughts are as follows:-

TO NEXT_TERM :h :v:list IF :h+:v= O [SHOW :list STOP] IF:h>O [USE_H] IF:v>O EUSE V] END

In this particular situation there is some freedom as to the order in which we write the lines - you can experiment with this later. Experience shows that it is good practice to put lines containing a STOP instruction early in the procedure, if the logic allows you to. But what is involved in USE H and USE _ V?

TO USE_ H NEXT TERM (:h-l) :v (LPUT "H :list) END

If we play an H-card we once again face the NEXT _TERM situation, but with an H at the end of the previous list and with one less H than before. Likewise,

TO USEV NEXTTERM :h (:v-1) (LPUT "V :list) END

36 Mathematics in School, November 1993

This content downloaded from 81.23.53.34 on Tue, 8 Apr 2014 16:52:27 PMAll use subject to JSTOR Terms and Conditions

The brackets in these two procedures are not essential, but using them makes clear the three inputs which NEXTTERM requires. These three short procedures are enough to produce the numbers in Faulkner's tables (as far as 2x1 paving stones are concerned).

If we enter at the command line

NEXT _TERM 2 3 [] the computer produces 10 possible lists, corresponding to the entry for N= 7 and H= 2 in Faulkner's table; and

NEXT_ TERM 3 3 []

produces the 20 possible arrangements for Faulkner's N= 9, H= 3. (N= 2H+ V).

These procedures exemplify the astonishing power of Logo. Five lines of programming generate the paving patterns for any values of N and H, limited only by the memory available in the computer. But whilst the pro- cedures are short they are very sophisticated. NEXTTERM calls the other two other procedures USE_H and USE_V, and each of these in turn refers back to NEXT _ TERM. This generates a complex branch- ing tree. To realise the power of Logo you have to use recursion.

There is a further matter of notation to discuss. We have used the link character (_) to join words. (On a Model B computer this is on the same key as the a sign, on some other keyboards it is on the same key as the minus sign.) Spaces carry very definite meanings in Logo. Procedure names cannot contain spaces, and whilst one can write names such as NEXT_ TERM some people find it easier to read such names if the link character is used. Logo can be used not only to communicate with machines, it can also be used to communicate with people. As one grows familiar with the language one comes to appreciate the advantages (and the difficulties) of using it for human communication.

It is appropriate to write some more procedures. These are to call the procedures we have already written more conveniently, to generate all the paving stone layouts for some given N, and to produce diagrams as well as lists.

We saw above that calling the NEXT _ TERM procedure involved not only inputting the values of h and v which interested us, but also putting in an empty list to get the procedure started off correctly. We can start off more easily if we define

TO SHOW_ LISTS :h :v NEXT_TERM :h :v [ ] END

Now SHOW_ LISTS 2 3 and SHOW-_LISTS 3 3 produce the two sets of lists described above.

We want a way of generating all the lists for some given value of N, using just one command. We should not need to step through all the values of H, the machine should do that for us. How can we develop a command, SHOW_ALL_LISTS (say), which will work given just the value of N? First we can modify the definition of SHOW-_LISTS so that when it has worked with some particular value of h it goes on automatically to work with the next value of h, at the same time adjusting the value of v appropriately. Let us define a new version as follows.

TO SHOW_ LISTS2 :h :v PR SE [h=] :h NEXT_TERM :h :v [ ] IF :v>l [SHOW_LISTS2 (:h+l) (:v-2)] END

The last line says that we want to step on with h increased by one; but this entails decreasing v by 2, and we can only do this if v is currently greater than one. We have inserted an extra print instruction so that the printout is easier to understand. The print instruction displays the current value of h just as the diagrams do in Faulkner's article. Now define

TO SHOW_ALL_ LISTS :n SHOW_LISTS2 0 :n PR [FINISHED!] END

and the command SHOW_ALL _ LISTS followed by some value of n produces a truly impressive printout.

When you see this you will certainly get over-excited and make typing mistakes as you try larger and larger values of n. So to reduce typing when you experiment define

TO T:n SHOW _ ALL_ LISTS :n END

Now something like T 10 is quickly typed and you can sit back and watch the 89 cases speed by.

So far we have concentrated on the list handling capabilities of Logo. The most widely known aspect of the language is the turtle graphics. How can we persuade the computer to draw the appropriate diagrams?

To start with it is a standard exercise in turtle graphics to define procedures H and V to draw a pair of horizontal tiles and a single vertical one. But take care! Each procedure has to be defined so that it can take over with the turtle where the previous procedure left it - and it has to leave the turtle conveniently for the next command. We leave it as a problem for the reader to design procedures which will do (see appendix).

These procedures can be used from the command line. Clear the screen, turn the turtle RT 90, and type in a sequence of Hs and Vs (with spaces and no brackets). After carriage-return the computer draws the appropriate path with the paving stones properly placed.

But the Hs and Vs can be used another way. Logo has the most useful command RUN. At the command line type in

CS RT 90 RUN [H H V V H]

(The square brackets are essential.) After carriage-return the machine RUNs the list of instructions as if it had been typed into the command line (without square brackets). This can be used to modify our procedures so that they draw the diagrams as well as displaying the lists. One way of doing this is to modify NEXTTERM, making the second line

IF:h+:v =0 [CS SHOW:list RT 90 RUN :list STOP]

Finally you can experiment with further refinements. You may wish, for example, to insert pauses so that the various lists and diagrams do not just whizz past bewilder- ingly. Simple ways of doing this can be found in elementary introductions to Logo. M

References 1. Drinkwater, G. (1992) Paths and Paving Stones, Mathematics in School,

21, 1. 2. Faulkner, D. (1993) Paths and Paving Stones, Mathematics in School,

22, 1. 3. Gilder, J. (1993) Fibonacci and Footpaths, Mathematics in School, 22, 1.

Mathematics in School, November 1993 37

This content downloaded from 81.23.53.34 on Tue, 8 Apr 2014 16:52:27 PMAll use subject to JSTOR Terms and Conditions


Recommended