8
0
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:
411S 370E
That is, with S
or N
appended to the latitude, and E
or W
appended to the longitude, with space(s) between the two components.
Goal
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.
Input/Output
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.
Scoring
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 bash
and sh
, it competes against programs in both languages).
Test cases
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
(maximal values)
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)
5I'm genuinely curious if this scoring mechanism will work out, but I feel like it's game-able. In particular, I could write a (suboptimal) solution at exactly 399 bytes in some crazy hard esolang (or one of my own) and even though it might be easily golfable, it would be somewhat unlikely that anyone else would be willing to learn the language just to beat my score in this challenge. – Martin Ender – 2016-05-04T07:34:58.520
I hope it's clear now. Please look for "preferred input format" in the text and ask for further clarification if it's still ambiguous. – anatolyg – 2016-05-04T08:54:52.760
2@anatolyg I find that paragraph very misleading. You talk about "flexibility" and a preferred input format, but then require all solutions to use exactly that format. Where is the flexibility and what is "preferred" about this format? I think for this challenge it's fine to require one very specific format, but then the specification should unambiguously say so. – Martin Ender – 2016-05-04T09:13:06.340
No unary input for me? – Leaky Nun – 2016-05-04T09:25:15.900
1@MartinBüttner The flexibility is in the output. Not much though. – anatolyg – 2016-05-04T10:01:37.857
@KennyLau No, sorry – anatolyg – 2016-05-04T18:41:42.520
I don't know why you're saying the Lua answer was winning when the most recent edit to the MATLAB answer was shorter by the time you'd posted the bounty, but hey, it produced more answers! Can't argue with that~ (edit: nvm I forgot that your criteria was not code golf) – Value Ink – 2016-09-01T02:23:05.450
A certain Befunge interpreter has a single line input field. If you paste text with a newline your given a space instead. Is this acceptable?
– Linus – 2016-09-01T21:45:01.853@Linus Seems reasonable – anatolyg – 2016-09-01T23:38:34.917
I am not quite sure what You are trying to achieve with your winning condition. You may want to put it to discussion in meta or open chat for it.
– Titus – 2016-09-06T16:04:30.710