Given the ASCII art of two vectors, find the resultant vector's magnitude and degree.
This can be received via STDIN, read from a local file, or provided through a function call. Here is an example of a two vector input:
^------> | | | x
This represents a change of 4 units north and 7 units east. Every input's starting point will be represented by an
All vectors are horizontal or vertical lines.
Each vector has one of these four endpoints:
^v<>, and is made up of either a dash (
-, decimal 45) or a vertical bar (
|, decimal 124).
Empty points on the plane are filled with spaces (
, decimal 32).
The input may be a single
Adjacent vectors are always perpendicular to each other.
All vectors are tip-to-tail.
This will be the displacement of the resulting point (distance from the starting point) and the degree to which it has moved, relative to the starting point.
For the above input, the output should be
8.06 units and
60.3 degrees. Each should have exactly 3 significant figures. Here are a few examples of numbers with 3 significant digits:
All unit measurements will be
These numbers should be output in the below format. This is using the numbers from above.
8.06 units @ 60.3 degrees
This may be followed by a single trailing space or newline.
If the input is a single
x, with no displacement and hence no angle of displacement, the output should be either an empty line (a single newline character) or in the following format:
0 units @ - degrees
If you're trying to qualify for the bonus, the direction should be
- as well.
In the case that bonuses 2, 3, or both are completed, the output should follow the below model and abide by the same restrictions as the above.
8.06 units @ 60.3 degrees NE
Degrees should be measured according to the standard plane.
90 135 | 45 \|/ 180 ---x---- 0 /|\ 225 | 315 270
0 degrees is east,
1 - 89 degrees is northeast,
90 is north, etc.
The following are worth a total of -50%.
Take a -10% bonus for each additional vector that can be handled. This bonus can be applied to up to 3 times. Vectors will never overlap or cross.
Take a -10% bonus if your output includes the cardinal direction of the angle (north, south, east, west).
Take a -10% bonus if your output includes the intermediate directions of the angle (northeast, northwest, southeast, southwest).
x----> | v
5.39 units @ 338 degrees
<--------------^ | | x
15.3 units @ 169 degrees
x | |<-----^ | | v------>
2.24 units @ 297 degrees
Examples (multiple vectors)
x---> | | v----------->
16.3 units @ 349 degrees
<-------^ | | | | v | | | x
8.54 units @ 159 degrees
^--> | | | v | <--------x
6.32 units @ 162 degrees