| Title: | Mathematics at DEC | 
| Moderator: | RUSURE::EDP | 
| Created: | Mon Feb 03 1986 | 
| Last Modified: | Fri Jun 06 1997 | 
| Last Successful Update: | Fri Jun 06 1997 | 
| Number of topics: | 2083 | 
| Total number of notes: | 14613 | 
   This problem was one of a set given at my college as a contest between the
students and the professors, needless to say, the students killed'em.  Although,
not strictly mathematical in nature, it is an interesting problem.  Personally,
I thought it was very challenging but ever so 'simple' once I looked at it
in the 'right-way'.
   A carpet layer wants a program [algorithm] for computing the floor area for
any floor given only its outside dimensions and number of corners.  A floor
may be ANY shape [square, rectangle, "square spiral", etc] with the restriction
that all corners are right angles.  The data for the program is to be presented
in this fashion :
               XXX d1xx d2xx d3xx
where,
   XXX is the number of corners (data elements following XXX)
   d1xxx ... d3xx are direction/distance points as :
                      N02
    meaning North 2 units.
A sample floor of 5 by 4 units with an area of 20 would be :
                 +--+--+--+--+--+
                 |              |
                 +              +      The data would be :
                 |              |
                 +              +     04 N04 E05 S04 W05
                 |              |
                 +              +      The program should output 20
                 |              |
                 +--+--+--+--+--+
   I'm not sure what I want for an answer.  A general algorithm would be ok but
a working program all the better [it being an algorithm by definition].
 Joe
 -=-
| T.R | Title | User | Personal Name | Date | Lines | 
|---|---|---|---|---|---|
| 130.1 | TURTLE::GILBERT | Tue Jan 01 1985 03:42 | 25 | ||
| $ fn = -1
$ fs = -1
$ fe = +1
$ fw = +1
$ dxn =  0
$ dyn = +1
$ dxs =  0
$ dys = -1
$ dxe = +1
$ dye =  0
$ dxw = -1
$ dyw =  0
$ area = 0
$ x = 0
$ y = 0
$loop:
$ inq dn
$ d =  f$extract(0,1,dn)
$ n = 'f$extract(1,9,dn)
$ area = area + f'd * n * (x * dy'd + y * dx'd)
$ x = x + n * dx'd
$ y = y + n * dy'd
$ m = f$fao("Area = !SL/2, at (!SL,!SL)", area, x, y)
$ write sys$output m
$ goto loop
 | |||||