48
7
This seems almost trivial, but since after some effort I was not able to beat the literal solution in J, I thought it might make a decent challenge (though, to be clear, this is not a J-specific challenge).
Title says it all. You simply need to write a program, or function (taking no arguments) that returns or prints:
N NE E SE S SW W NW
You may use newlines in place of spaces.
A no-argument function returning an array of strings such as
['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW']
is also acceptable.
The letters may be upper or lower case, but may not be mixed.
9Perhaps allowing them to be output in any order would be slightly more interesting – Jo King – 2019-06-10T00:14:16.070
3@JoKing Sure, I'll remove that. Honestly, I didn't expect anyone to submit answers that used the full literal value -- that's not in the spirit of the question. As I state, it came up because I wasn't able to beat the literal in J, despite the string having regularity and structure of a sort. The whole point is to exploit that regularity to beat a literal answer. Bad on me for not being more explicit. Allowing them any order defeats that as well, so I don't want to make that change. – Jonah – 2019-06-10T01:27:24.803
Well, even though everything's been a literal, compressed literal, or base conversion, I do still like the idea here... maybe a new challenge with the cardinal directions spelled out could do better? I feel like raw dictionary compression, or maybe base conversion with dictionary compression, would probably end up being the shortest, but at least languages without good compression tools would be able to go algorithmic with it. – Unrelated String – 2019-06-10T07:34:34.333
3@UnrelatedString The most promising idea I've had is to note that the directions correspond to i raised to the powers
0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5
. Unfortunately the J code required to then map those results into letters ended up being more expensive than a literal. – Jonah – 2019-06-10T18:04:21.9571Ah, smart! I wonder if the mapping might work better for the Gaussian integers
1, 1+i, i, -1+i, -1, -1-i, -i, 1-i
so you've got one real or imaginary part per cardinal direction instead of two. It's probably harder to generate those though, unless there's some way you could round those powers of i away from 0? I don't know how easy or hard that would be in J, but it's an idea. – Unrelated String – 2019-06-11T02:26:40.863If returning an array of strings, are spaces acceptable in those strings? e.g.
[' W', ' E', 'N ', 'NW', 'NE', 'S ', 'SW', 'SE']
– Sok – 2019-06-11T08:50:55.6531May we have additional spaces between directions, e.g.
N NE E SE S SW W NW
? – Adám – 2019-06-11T09:22:36.463@Adám Sorry on further consideration I think that should be illegal – Jonah – 2019-06-11T12:45:50.167
@Sok Sorry yours isn’t allowed either (but nice answer if it has been) – Jonah – 2019-06-11T12:48:39.567
3It feels like entries should also show the naive "echo this string" version in their language for comparison, and judging be done on the % shortened? – Dewi Morgan – 2019-06-11T22:07:10.563