A fortress has been built to protect the queen. It consists of a collection of
walls built in circular arcs around the queen's throne. Each arc is described
by the directions from
the throne to its two ends. Directions are specified using N,E,W,S to indicate
the four compass points. NE, NW, SE, SW indicate the directions half way
between. Every other direction is specified by preceding one of these four 2-letter
directions with a sequence of letters, each of which matches one of the direction's
final 2 letters.
For example, ENE is the direction
halfway between NE and E. NENE is the direction halfway between ENE and the
next more northern direction which can be expressed in 3 or fewer letters (NE).
SWWWSSW is halfway between WWWSSW and the next more
southerly direction that can be expressed in 6 or fewer letters (WSSW).
No more than 10 letters are ever used to name a direction. That means that
there are exactly 2048 directions.
This diagram shows all of the directions in the Northeast quadrant that can
be expressed in 4 or fewer letters.
N
| NNNE
| NNE
| ENNE
| NE
| NENE
| ENE
| EENE
-----------+-----------------E
|
|
|
|
|
Create a class NENE that contains the method vulnerable that takes the ends of
the circular arcs as inputs, and returns the first direction counterclockwise
from East which is not protected. Return the String "SAFE" if
all legal directions are protected. A wall does protect the directions at its
endpoints.
The ends are input as String[] cw and String[] ccw. Corresponding
elements of cw and ccw give the directions of the clockwise and
counterclockwise ends of a wall. The wall extends less than 360 degrees, going counterclockwise from its cw end to its ccw end.
|