Coordinates in the flat-Earth world consist of latitude (x) and longitude (y), which are integers in the range 0...9999. Much like Gaussian integers, but they are always written using this notation:
That is, with
N appended to the latitude, and
W appended to the longitude, with space(s) between the two components.
Write a program (not a function) that reads two coordinates, separated by whitespace, and outputs their sum. The first coordinate is a starting point, the second one is a displacement, and the output is the resulting position.
Since this challenge is partially about formatting, I'll try to define the input and output formats unambiguously.
The preferred input format has 1 space between the coordinate components, no leading zeros, and a newline character between the two coordinates. The program must be able to read the preferred format.
The output can contain any amount of whitespace and leading zeros. If it's different from the preferred input format, the program must be able to read this format too.
Just to make it clear, the input cannot (will not) contain any additional formatting characters. Just spaces and newlines where needed.
This is an experiment on a new winning condition. I'll choose the winner by accepting an answer in a few weeks. If a better answer appears afterwards, I'll change the accepted answer.
The score for the program is its byte count. The winning program is one that is shorter than 400 bytes, has the fewest byte count, but is written in the most verbose programming language. To determine the winner:
- Remove programs with byte count 400 or more (they can participate but cannot win)
- Consider only the shortest program for each programming language
- The longest program wins
Polyglots compete against programs in all languages in which they are valid (e.g. if a program is valid in both
sh, it competes against programs in both languages).
In the test cases, the first two lines are the input, and the third line is the output.
0S 0E 0S 0W 0N 0E
(the direction of zero doesn't matter, both in input and output)
0S 9999E 9999N 9999W 9999N 0E
42S 314W 42N 2718W 0N 3032W
(the direction of zero doesn't matter in the output)
5555N 8888W 7777S 0E 2222S 8888W
(no negative values; change the direction if you need to change the sign)
0001N 4545W 0999N 5454W 1000N 9999W
(if the program outputs leading zeros and several spaces, it must be able to read them; it must also be able to read input that doesn't contain them)
8888N 8888W 9999N 9999W
(invalid input - any behavior is acceptable, including crash and infinite loop)