Print "N NE E SE S SW W NW"

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.

Jonah

Posted 2019-06-09T16:39:14.690

Reputation: 8 729

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.957

1Ah, 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.863

If 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.653

1May 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

Answers

19

Canvas, 12 bytes

>X½+T)AuS{⁹‟

Try it here!

The string, simply compressed.

dzaima

Posted 2019-06-09T16:39:14.690

Reputation: 19 048

2Can you explain how this works in a little more detail? – Dillanm – 2019-06-10T12:51:26.713

2@Dillanm there isn't much more to say - Canvas has a built-in compressor (should be accessible with ctrl+o → string compress) that, here, simply stores the characters needed ("NESW ") and then in base-5 stores the individual characters. – dzaima – 2019-06-10T12:56:02.433

57

bash (24 bytes)

using brace expansion

echo N {N,,S}E S {S,,N}W

is the same length as hard coding

echo N NE E SE S SW W NW

however it becomes more interesting when outputing more points of the compass

echo N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW

brace expansion

echo N {{N,,E}N,,{E,,S}S}E S {{S,,W}S,,{W,,N}N}W

otherwise if order could be changed, (17 bytes), the trick is that without quotes the empy string parameter disappears

echo {N,,S}{W,,E}

Nahuel Fouilleul

Posted 2019-06-09T16:39:14.690

Reputation: 5 582

1That is interesting, I didn't know that you could have empty position is the brace expression! – flawr – 2019-06-10T11:19:26.363

1@flawr Useful when chrooting: mount -t proc{,,} – gronostaj – 2019-06-10T14:51:58.813

7Or cp file{,.bak} – Oliphaunt - reinstate Monica – 2019-06-10T21:52:11.050

44

Mornington Crescent, 4395 3823 bytes

Take Northern Line to Bank
Take District Line to Parsons Green
Take District Line to Paddington
Take Bakerloo Line to North Wembley
Take Bakerloo Line to Charing Cross
Take Bakerloo Line to Charing Cross
Take Bakerloo Line to Charing Cross
Take Bakerloo Line to Charing Cross
Take Northern Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Barbican
Take Circle Line to Bank
Take Circle Line to Aldgate
Take Circle Line to Embankment
Take Bakerloo Line to Charing Cross
Take Bakerloo Line to Charing Cross
Take Bakerloo Line to Charing Cross
Take Bakerloo Line to Charing Cross
Take Northern Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Bayswater
Take Circle Line to Hammersmith
Take Circle Line to Baker Street
Take Circle Line to Bank
Take Circle Line to Embankment
Take Northern Line to Stockwell
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Farringdon
Take Circle Line to Hammersmith
Take Circle Line to Blackfriars
Take Circle Line to Bank
Take Circle Line to Moorgate
Take Northern Line to Waterloo
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Westminster
Take Circle Line to Hammersmith
Take Circle Line to Tower Hill
Take Circle Line to Bank
Take Circle Line to Edgware Road
Take Circle Line to Liverpool Street
Take Central Line to Mile End
Take District Line to Victoria
Take Victoria Line to Seven Sisters
Take Victoria Line to Victoria
Take Circle Line to Victoria
Take District Line to Mile End
Take District Line to Bank
Take Circle Line to Bank
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Bank
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Barbican
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Bayswater
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Baker Street
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Farringdon
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Embankment
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Blackfriars
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Moorgate
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Westminster
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Tower Hill
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Hammersmith
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Aldgate
Take Circle Line to Paddington
Take Circle Line to Paddington
Take Circle Line to Edgware Road
Take Circle Line to Paddington
Take Circle Line to Bank
Take Circle Line to Bank
Take Northern Line to Mornington Crescent

Try it online!

Since it's a bit much to expect you to read all that, let me give a quick overview of my approach. The main idea is to store 3 copies of the characters N,E,S,W at various stations on the Circle line, via Bank - Hammersmith. These characters are constructed from the start of a station name at Charing Cross. Then, construct   from the middle of a well-chosen station name using Mile End and Charing Cross, and store it at Bank so that it can be collected at Hammersmith in the concatenation. Finally, concatenate the characters one by one at Paddington, copying them again via Bank - Hammersmith if they are need to be reused later.


I think the current solution is fairly close to optimal with this strategy, at least in terms of number of stations visited: just 2 times I used a station only for transit:

  1. to get to Seven Sisters (via Victoria station)
  2. and to get back to Mornington Crescent (via Bank).

All other station visits were, if I didn't forget one, either storing/retrieving something useful or (part of) using the stations ability.

As for the line lengths, I've tried to pick the shortest names on Circle Line, but there may be a minor improvement there. It's possible that storing something on District can shave off a few bytes.

Discrete lizard

Posted 2019-06-09T16:39:14.690

Reputation: 559

Two ideas to golf this some more: 1. take 'NE', 'SW', 'NW', 'SE' from a single station (Using e.g. Neasden, Swiss Cottage, Acton Town and Mansion House) 2. Try to exploit the fact that Paddington makes it easier to concatenate W rather than W. This does require some more overhead to 'refresh' Paddington, so it may not gain anything. – Discrete lizard – 2019-06-12T06:45:42.450

5Does this use Dollis Hill loop rules? If so, I think it can be improved by use of an Argyle Street parabola, and maybe even a slightly modified version of the Webb-Ellis protocol. – Richard Ward – 2019-06-12T13:38:40.750

27

PHP, 19 bytes

N NE E SE S SW W NW

Try it online!

Getting this out of the way. Someone will do it eventually.

640KB

Posted 2019-06-09T16:39:14.690

Reputation: 7 149

8Also works for HTML+JS. – Cœur – 2019-06-10T10:07:29.807

Polyglot with ///. – my pronoun is monicareinstate – 2019-06-12T04:30:24.277

25

brainfuck, 142 139 131 119 bytes

++++++++++[>+++>+++++++>++++++++>+++++++++<<<<-]>>>--.<<++.>>.<-.<.>.<.>>+++++.<.<.>>.<<.>>.>---.<<<.>>>.<<<.>>-----.>.

Try it online!

Simply loops 10 times to fill the cells with 30, 70, 80 and 90 then steps backward and forwards and adjusts the cell values to print out the required characters. Not much different from the standard "Hello world!".

ElPedro

Posted 2019-06-09T16:39:14.690

Reputation: 5 301

7Lol I've never understood how anyone can "golf" these obscure languages. Its hard enough to understand what the code does in the first place (this is said coming from C++ / Java background) – mackycheese21 – 2019-06-10T00:25:09.410

10@mackycheese21 what? C++ didn't teach you to love pointer manipulation? – candied_orange – 2019-06-10T05:13:50.273

12brainfuck might be esoteric, but I sure wouldn't call it obscure – Unrelated String – 2019-06-10T06:56:21.817

3@candied_orange C++ taught me to hate pointer manipulation and run away whenever someone mentioned std:: :) – mackycheese21 – 2019-06-10T15:41:40.633

1@UnrelatedString obscure, no. Obtuse, yes. – Rich – 2019-06-10T18:39:41.680

check out my answer with 118 :) – Helena – 2019-06-12T21:17:28.443

15

Brain-Flak, 204 bytes

((((((((((((((((()()()){}()){}){}())){}{}))<([([][]){}()]{})(([][]){}[])>)<([][]
()())>)[[]]()())<([]()()())>)<((([]())[][]){}[][()])>)<([][()()])>[[]()])<([][((
)()){}])>)((()()())){}{})<((()()()()()){})>)

Try it online!

James

Posted 2019-06-09T16:39:14.690

Reputation: 54 537

4Points deducted for wrapping. – Rich – 2019-06-10T18:40:28.127

13

MarioLANG, 249 221 bytes

+
+
+
+
+
+
+
+
+  ((+++++++++)))<
+>==============="
)++++++++)+++((-[!)--.)++.(.---------.).(.).)++.((.).).(.).++++.(.).(.(+++++++++.))
=================#================================================================.

Try it online!

Charlie

Posted 2019-06-09T16:39:14.690

Reputation: 11 448

11

Deadfish~, 188 183 bytes

-5 thanks to squid

iiissdddc{ddddd}iiiicdddd{iiiii}c{d}ic{dddd}iiicddd{iiii}c{dddd}iiic{iiiii}ic{d}ddddc{dddd}iiic{iiiii}ic{ddddd}dci{iiiii}ciiiic{ddddd}dddddciiiii{iiiii}c{ddddd}dddddcdddd{iiiii}c{i}dc

Try it online!

a stone arachnid

Posted 2019-06-09T16:39:14.690

Reputation: 1 053

1{i}dc at the end for 183 – Reinstate Monica – 2019-06-10T09:40:17.953

11

Excel Formula, 59 57 bytes

The following should be entered as an array formula (Ctrl+Shift+Enter):

=SUBSTITUTE(ADDRESS(1,{14,369,5,499,19,517,23,387},4),1,)

After entering the formula as an array formula, highlight it in the formula bar and evaluate it using F9 to return the result, for example:

Before:
Before formula evaluation

After:
Before formula evaluation

How it works

The ADDRESS function returns a string representing a reference based on two parameters, row and col. The third parameter controls what type of reference is returned, an absolute or relative reference. For example, =ADDRESS(1,2,4) returns "B1".

We can supply an array to ADDRESS and use it as an array formula to return multiple results, for example =ADDRESS(1,{1,2,3},4) returns "A1","B1","C1".

Therefore, in my answer, the array supplied to ADDRESS are just the column numbers relating to the required compass points, e.g. Column 14 is column N, Column 369 is column NE.

However, we are not finished here since all the returned references have the row included, for example, N1, NE1. Therefore, we simply use SUBSTITUTE to remove the 1 from all references.

i_saw_drones

Posted 2019-06-09T16:39:14.690

Reputation: 413

1Would =IF(1,"N NE E SE S SW W NW") be valid? – Reinstate Monica – 2019-06-10T20:20:11.943

3@squid Yes it would indeed! However, I was going for an alternative which didn't require the string to be quoted verbatim. – i_saw_drones – 2019-06-10T21:38:27.543

How does this work? – anatolyg – 2019-06-11T18:58:43.700

@anatolyg I've added an explanation section, hope it's understandable. – i_saw_drones – 2019-06-12T08:51:58.513

10

Triangularity, 71 bytes

..... .....
...."W"....
..."W N"...
.." SW "+..
." SE S"++.
"N NE E"+  

Try it online!

There are two spaces on the last line to hit the byte count Triangularity requires.

Reinstate Monica

Posted 2019-06-09T16:39:14.690

Reputation: 1 382

8

Charcoal, 14 bytes

”{⊟“�_Zn↖⦄RüΦ≦

Try it online! Link is to verbose version of code... which is just the string to be printed, as the auto-deverbosifier takes care of the string compression.

Printing the string uncompressed takes 19 bytes, since Charcoal prints printable ASCII literally. The best algorithmic answer I could come up with unfortunately takes 20 bytes:

E⁸ΦSNWE›³﹪⁻﹪⁺⁵×⁶μχι⁸

Try it online! Outputs using array format (would cost two bytes to join the elements on spaces). Works by noticing that the letters of the string SNWE are used only when the current outer index equals or is 1 away (modulo 8) in either direction from the corresponding element of the list of indices 4,0,6,2.

Neil

Posted 2019-06-09T16:39:14.690

Reputation: 95 035

8

brainfuck, 117 bytes

+++++[>++++++>+>+++>>++++>+++++<<<<<<-]>++[>++>++>+>++>++[<]>-]>>-.>.<.<.>>.<<.>>.>-.<<<.>>.>.<.>.>--.<<.>>.<<.<.>>>.

Try it online!

This code will first create the characters "EN SW" into the memory and then move back and forth to print them. The space is in the middle, because it is printed most often. N and S and W and E never appear together so they are on opposite sides of the memory. For optimization some of the final decrements happen during the output phase.

Helena

Posted 2019-06-09T16:39:14.690

Reputation: 321

1OK, that's a cool answer. Guess you beat me on this one. +1 for -1 :-) – ElPedro – 2019-06-12T21:30:39.797

1BTW, forgot to say, welcome to the Code Golf site. Looking forward to competing with you in the future ☺ – ElPedro – 2019-06-12T21:39:00.963

1Welcome! Consider adding an explanation or a link to an online interpreter for the program. See other answers for examples. Short code-only answers tend to get automatically flagged as low-quality. – mbomb007 – 2019-06-12T21:41:39.373

1Thanks, I can add a explanation of my code. I will also try to understand how the online links work. – Helena – 2019-06-13T17:35:40.397

1@Helena For the link you can check out the "Try it Online" link on my answer. If you paste your code in and run it you can then click on the link icon and get a perfectly formatted code golf answer that you can simply copy and paste here. Works like magic and supports many languages. Well worth a try. – ElPedro – 2019-06-13T17:49:07.387

7

Python 2, 62 61 58 53 bytes

i=8
while i:print'NESESWNW'[~i+(i==4):][:1+i%2],;i-=1

Try it online!

Not great, but at least not a plain print..

TFeld

Posted 2019-06-09T16:39:14.690

Reputation: 19 246

6

Jelly,  16  15 bytes

“¤œỵpq⁵’ṃ“NESW 

A full program printing the text

Try it online!


16...

“¥Þ¡¦¢¬£æ‘ṃ“¡ɱ⁻»

A niladic Link which yields a list of lists of (lowercase) characters.

Try it online!


Alternative 15 as a niladic Link which yields a list of (lowercase) characters (with spaces): “¡XÇŀqỵÑ’ṃ“¡⁴ṁ».

Jonathan Allan

Posted 2019-06-09T16:39:14.690

Reputation: 67 804

6

Commodore BASIC (TheC64Mini, C64, C128, VIC-20 etc.) 28 Tokenized BASIC bytes used

 0 PRINT"N NE E SE S SW W NW

In Commodore BASIC, you do not require the closing quotation mark on PRINT or LET statements as the interpreter will auto-close it, this saves one BASIC token.

Alternatively, one may simply use direct mode as follows:

Commodore BASIC 23 PETSCII characters (+ RETURN to execute)

?"N NE E SE S SW W NW

I'm not sure how to count the number of bytes used in this instance as according to the interpreter ? and PRINT use the same number of bytes, and there is no program stored in memory.

Shaun Bebbers

Posted 2019-06-09T16:39:14.690

Reputation: 1 814

1PRINT can be replaced with ? as well, saving four bytes. – James – 2019-06-12T04:08:00.947

1No, that's not true; PRINT and ? use the same amount of BASIC tokens. I'm not counting PETSCII characters as it's not very representative of how much of the available memory is being used by the interpreter. – Shaun Bebbers – 2019-06-12T08:52:34.880

1

After all of these years I'm still learning new stuff about the Commodore. Thanks Shaun! https://www.c64-wiki.com/wiki/BASIC_token

– James – 2019-06-13T10:07:28.277

Here's one I made earlier (for the C64) -> https://pastebin.com/NMYzTC7k

– Shaun Bebbers – 2019-06-13T12:23:12.190

5

Deadfish~, 138 bytes

{{i}i}c{{d}}cs{i}c{d}ic{{d}}iisicsic{{d}}iisicisddddddc{d}ddddc{{d}}iisicisddddddc{{iiii}}sicisddddddciiiic{{d}d}icisddc{{d}d}ics{i}c{i}dc

Try it online!

So, outputting in lower-case with newlines is better than default (upper-case with spaces).

This code was generated by my optimizer, written in C++ (thanks to squid for another optimization idea!):

#include <iostream>
#include <string>
#include <queue>
#include <vector>


int eval(const std::string& actions, int result)
{
    int mult = 1;

    for (int i = 0; i < (int)actions.length(); ++i)
    {
        switch (actions[i])
        {
        case 's':
            result *= result;
            if (result == 256)
                result = 0;
            break;

        case '{':
            mult *= 10;
            break;

        case '}':
            mult /= 10;
            break;

        case 'd':
            if (result > 256 && result - mult <= 256)
                result = (result - mult) % 256;
            else
                result -= mult;
            break;

        case 'i':
            if (result < 256 && result + mult >= 256)
                result = (result + mult) % 256;
            else
                result += mult;
            break;
        }
    }

    return result;
}

struct worse
{
    bool operator()(const std::string& a1, const std::string& a2)
    {
        return a1.length() > a2.length();
    }
};

std::string BestStr(int accumulator, int target)
{
    std::priority_queue<std::string, std::vector<std::string>, worse> actions;
    actions.push(std::string(""));
    while (true)
    {
        std::string a = actions.top();
        int new_acc = eval(a, accumulator);
        if (new_acc == target)
            return a + "c";

        actions.pop();

        int last_braces = 0;
        int i = a.length() - 1;
        while (i >= 0 && a[i] == '}' && last_braces < 2)
        {
            ++last_braces;
            --i;
        }
        bool is_last_i = (i >= 0 && a[i] == 'i');
        bool is_last_d = (i >= 0 && a[i] == 'd');
        bool may_add_braces = (i < 0 || a[i] == 's');
        bool may_add_c = (new_acc > 1 && new_acc < 30);

        if (may_add_c)
        {
            actions.push(a + "s");
        }
        if (may_add_braces)
        {
            actions.push(a + "{{}}");
            actions.push(a + "{}");
        }
        for (int braces_back = 0; braces_back <= last_braces; ++braces_back)
        {
            for (int c = 'd'; c <= 'i'; c += 'i' - 'd')
            {
                if ((!is_last_i || c == 'i') &&
                    (!is_last_d || c == 'd') ||
                    braces_back == 0)
                {
                    std::string new_actions = a;
                    new_actions.insert(new_actions.length() - braces_back, 1, (char)c);
                    actions.push(new_actions);
                }
            }
        }
    }
}

std::string DeadfishConvert(std::string s)
{
    std::string result;
    int accumulator = 0;

    for (int c: s)
    {
        result += BestStr(accumulator, c);
        accumulator = c;
    }
    return result;
}

int main()
{
    std::string s1 = DeadfishConvert("N NE E SE S SW W NW");
    std::cout << s1 << '\n';
    std::cout << s1.length() << '\n' << '\n';
    std::string s2 = DeadfishConvert("n ne e se s sw w nw");
    std::cout << s2 << '\n';
    std::cout << s2.length() << '\n' << '\n';
    std::string s3 = DeadfishConvert("N\nNE\nE\nSE\nS\nSW\nW\nNW");
    std::cout << s3 << '\n';
    std::cout << s3.length() << '\n' << '\n';
    std::string s4 = DeadfishConvert("n\nne\ne\nse\ns\nsw\nw\nnw");
    std::cout << s4 << '\n';
    std::cout << s4.length() << '\n' << '\n';
}

anatolyg

Posted 2019-06-09T16:39:14.690

Reputation: 10 719

1155 – Reinstate Monica – 2019-06-11T13:42:34.123

4

Japt, 16 bytes

Returns an array of lowercase strings. The compressed string was 18 bytes but using a as the delimiter instead and then splitting on that worked out shorter.

`nÂà!Z°°nw`qa 

Try it - footer formats the output.

Shaggy

Posted 2019-06-09T16:39:14.690

Reputation: 24 623

4

K (ngn/k), 23 22 bytes

-1 byte thanks to ngn!

"WNES"@5\7108085518230

Try it online!

J, 34 30 bytes

echo(#:3510)<;.1'NNEESESSWWNW'

Try it online!

Galen Ivanov

Posted 2019-06-09T16:39:14.690

Reputation: 13 815

Galen, for J echoing the literal would be shorter. I would love to see that beat... I haven’t managed to do it – Jonah – 2019-06-10T07:32:23.103

1Yes, echoing would be be 4+19 bytes. I don't have any better ideas to. – Galen Ivanov – 2019-06-10T07:40:15.107

1for k: if we swap " "<->"W" (0<->4 in base 5), the space will be at the end and we can remove it because out-of-bounds string indexing gives a space anyway: "WNES"@5\7108085518230 – ngn – 2019-06-17T14:01:14.663

@ngn Thank you! – Galen Ivanov – 2019-06-17T14:23:17.400

@ngn Good design choice for the out-of-bounds string indexing resulting in a space (at least for codegolf :) ) – Galen Ivanov – 2019-06-18T06:10:16.640

1

@GalenIvanov good for top-performance databases too :) arthur designed k as the underlying language for kdb+

– ngn – 2019-06-18T08:17:20.793

Can you explain how the ngn/k answer works? I can't get it to work in the k interpreter that comes with q. – Henry Henrinson – 2019-06-18T23:43:02.040

Nevermind, got it, you're representing the big number in base 5. ngn doesn't need the column for 5/:bla. Neat. – Henry Henrinson – 2019-06-18T23:52:22.507

@HenryHenrinson Yes, I index into the string of characters with indeces "packed" into a big number in base 5. ngn made his version of K to return as many positions as needed in the respective number base. – Galen Ivanov – 2019-06-19T06:08:53.693

@HenryHenrinson : in k4 (q), \ in k5, \ in k6, and it looks like it's gonna be : again in k7 (shakti). my dialect is close to k6 mostly – ngn – 2019-06-20T11:57:58.547

4

Batch File, 19 bytes

The question never stated that you had to output N NE E SE S SW W NW and nothing else, nor that it couldn't exit due to error after doing so this code only throws an error but does not exit due to it.

N NE E SE S SW W NW

Output

>N NE E SE S SW W NW
'N' is not recognized as an internal or external command,
operable program or batch file.

Batch File, 25 bytes

Only N NE E SE S SW W NW output with no errors or crashes.

@echo N NE E SE S SW W NW

BDM

Posted 2019-06-09T16:39:14.690

Reputation: 369

You could save a byte replacing cd with just quotes, like 'N NE E SE S SW W NW' - you'll get something like:

N NE E SE S SW W NW - command not found – Dewi Morgan – 2019-06-11T22:05:18.450

4

Python2, 59 bytes

''.join(' SEWN'[0xe0619042210504>>i*3&7]for i in range(19))

The magic number is the joined three-bit indexes into the character string, reverse order so we can start iterating at the LSB.


I spent a while trying to shrink the magic number, but repeating the character string via multiply to allow for extra indexes doesn't work out due to needing to encode for space - best I got for overlapping indexes in the lookup added more characters to the string than digits removed from the magic number (including a couple of unfortunate don't-cares in the middle):

''.join('WN S ES W xxE '[0x423659711>>i*2&15]for i in range(19))

Mostly Harmless

Posted 2019-06-09T16:39:14.690

Reputation: 359

Why make ir simple when you can make it complicated? :-) – G B – 2019-06-12T05:40:16.977

3

05AB1E, 14 bytes

.•2Àβ‡yÞJŒ¾oÒ8

Try it online!

This prints out the string except lowercase.

MilkyWay90

Posted 2019-06-09T16:39:14.690

Reputation: 2 264

Just remove the final for -1 – Grimmy – 2019-06-09T22:12:40.933

3

Brachylog, 19 bytes

"NNEESESSWWNW"ḍ₄ḍᵐc

Try it online!

Outputs as a list. ḍ₄ḍᵐc saves two bytes over writing out seven spaces and making the entire predicate a string literal, so at least it ties PHP...

"NNEESESSWWNW"         The string "NNEESESSWWNW"
              ḍ₄       split into quarters
                 ᵐ     with each quarter
                ḍ      split in half
                  c    and concatenated
                       is the output.

I tried to be clever with 3⟦{;"NESW"↺₍h₂a₀ᶠ}ᵐc, but it couldn't get SE or NW right, and is a byte longer anyhow.

Unrelated String

Posted 2019-06-09T16:39:14.690

Reputation: 5 300

3

MathGolf, 20 17 bytes

ÿnesw▒∙╫m+mÉîÄ╪^─

-3 bytes thanks to @maxb.

Try it online.

Explanation:

ÿnesw      # Push 4-char string "nesw"
           #  STACK: "nesw"
     ▒     # Split to a list of characters
           #  STACK: ["n","e","s","w"]
      ∙    # Triplicate it
           #  STACK: ["n","e","s","w"],["n","e","s","w"],["n","e","s","w"]
╫          # Rotate the top one once towards the left
           #  STACK: ["n","e","s","w"],["n","e","s","w"],["e","s","w","n"]
 m+        # Append the top two together
           #  STACK: ["n","e","s","w"],["en","se","ws","nw"]
   m       # Map the strings in the top list to:
    ÉîÄ╪   #  Rotate the string the 1-based index amount of times towards the right
           #   STACK: ["n","e","s","w"],["ne","se","sw","nw"]
^          # Zip; creating pairs with the top two lists
           #  STACK: [["n","ne"],["e","se"],["s","sw"],["w","nw"]]
 ─         # Flatten this list
           #  STACK: ["n","ne","e","se","s","sw","w","nw"]
           # (after which the entire stack is output implicitly as result)

Kevin Cruijssen

Posted 2019-06-09T16:39:14.690

Reputation: 67 575

117 bytes. This was a fun challenge. I tried it before, but ended up where you did. I think the most you could do from this is 1 byte more, but I couldn't find a shorter way. – maxb – 2019-06-12T07:58:21.070

@maxb Ah nice approach. I must admit that those code of block-size X (É and Ä in this case) still confuse me a bit sometimes.. Sometimes I'm not sure when I do or don't have to use those code-blocks. Your m+ doesn't use one for example. But your Ä is a code-block of size 1. I tried mÅî╪ just yet to see what happened, which is why I now understand why there is a code-block of size 1 Ä to begin with. :) ) Thanks for the -3 bytes, though. Still a lot to learn I see. – Kevin Cruijssen – 2019-06-12T08:20:58.257

1Nice explanation! I tried doing a solution without converting it to a list of chars, but the zip command was a bit wonky. For the code blocks, think of them as replacements, used instead of {}. mÅî╪ creates the mapping, but it doesn't have a for-loop inside the mapping. If you write m{î{╪}}, it is perhaps easier to see that the code is "map to: loop <index> times, and rotate the string each loop". The reason why m+ does not have one is that certain commands have implicit 1-byte blocks (map, filter, reduce, etc), but î is not a command meant to be used in combination with a block. – maxb – 2019-06-12T08:24:41.527

1@maxb I indeed knew the code-blocks were a shorter variant of {...}, but I kinda forgot integer{ is a for-loop. :) Now the îÄ╪ makes a lot more sense. Thanks for the explanation! – Kevin Cruijssen – 2019-06-12T08:30:32.613

3

Whitespace, 151 bytes

[S S S T    T   N
_Push_3_W][S S T    T   T   S N
_Push_-6_N][S S T   T   T   S T S S N
_Push_-52_space][S S S T    T   N
_Push_3_W][S T  S S T   N
_Copy_0-based_1st_(space)][S S S T  T   N
_Push_3_W][S S T    T   N
_Push_-1_S][S T S S T   S N
_Copy_0-based_2nd_(space)][S S T    T   N
_Push_-1_S][S T S S T   N
_Copy_0-based_1st_(space)][S S T    T   T   T   T   N
_Push_-15_E][S S T  T   N
_Push_-1_S][S T S S T   S N
_Copy_0-based_2nd_(space)][S T  S S T   S N
_Copy_0-based_2nd_(E)][S T  S S T   N
_Copy_0-based_1st_(space)][S T  S S T   N
_Copy_0-based_1st_(E)][S S T    T   T   S N
_Push_-6_N][S T S S T   S N
_Copy_0-based_2nd_(space)][S S T    T   T   S N
_Push_-6_N][N
S S N
_Create_Label_LOOP][S S S T S T S T S S N
_Push_84][T S S S _Add][T   N
S S _Print_as_character][N
S N
N
_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs, and new-lines only).

Explanation:

  1. Push the unicode values minus constant 84 for the characters "WN W WS S ES E EN N" to the stack (note that the string is pushed in reversed). In addition, I use a few copies of previously pushed values to save bytes where possible.
  2. Then start an infinite loop, which does the following:
    1. Add the constant 84 to the current unicode value
    2. Print it as character to STDOUT

The constant 84 is generated by this Java program which I wrote for another challenge I answered in Whitespace.

Kevin Cruijssen

Posted 2019-06-09T16:39:14.690

Reputation: 67 575

2

CSS, 42 39 bytes

(thanks to a stone arachnid for the revised version)

body:after{content:"N NE E SE S SW W NW"

roberrrt-s

Posted 2019-06-09T16:39:14.690

Reputation: 125

1-3 bytes: body:after{content:"N NE E SE S SW W NW" – a stone arachnid – 2019-06-12T04:08:59.373

Oh I forgot, that's valid as well ofc, updated :)! – roberrrt-s – 2019-06-12T09:40:16.953

2

Seed, 6014 bytes

27 32429737401852232227804295321578416370544555457622262891879921280324727410131817586348135470079420921373938348260737299348550007805068404867624897650263347568409592608258945989033792510474363164709158118555665232935403908551415888090695760298337219819413274977014408722140235669339108001709528995376914900494019798521214727367535169036319615676199584661126257462974800782884967804763256678000063025237472650538076831876942979826335539886276642624472204985016283691316313249488093825552581263195700506490263014623798470563718844847334940964632636436478404543496272112184140337568637349767918641524452384959486975049813859244670160569884744538279036643294867674161431756929550170395739925307134312406291063668809195567313928307910934660574895433141956111513050736041440669472422865481546405020220238818265794921314653725749392385549924210837964649297239381603259476675148489582680939048820717739905271461370132524025785160026801625672272913416389786086946626728842588663673416395169524016926695769334183833366462685756958054189820999370092892855665559717806826530952610964256124463840218293029538229042911551526509745973128558291005365222643503139067010483637086697955919587162384655443959408291567894061028044826636171014388153130769792397282335858985323269310727311039012381122390183102126191168963870116881629339035600546009305431793687183913979054151312200573069395058914262857368132993952655571167118263728070696377852599343989848263167312887211748226689125561718255196655446099711296568221690530717651328503948183228932786503716890383195810396161663632504174142420921735055441162618914957825032056019218584287089599270312541933094119409995775035365862244691419255488688879630142415739738796957474249592086989231999568273454247198389863139439897248192949030226324637037937607004428557202644332945222019553599908855943840883606735602486216245714280716148378430738983808375466562604692991701163078094015860708365913183037140180020776525026891135163345427911749533164462233906885068864798951466382247930357444595606617682531499045805835102155190109668901179666311163071611393282924908189215675892953256826649762594463293867383921972181952997833560371571545190945543033351108064265894854803319008655145213765667074789305055723258530694850418765677462165413557272747961130459219342146615095862014137406489375157766959799291089215740196734079295172946350338663239451562589633216908805028629767462044463310475859283605554743731396818983359527612902567406307270838160926586311672252276690909354125055468912844343806046309796590149977323343332039095076680537362333773750051043281967620781236684580688649899599894791764969639275247700776637892615729757899608628514791667795106390376246890330575517824338764219021396958188958235055290896924249770944905659304681507478975095888248103169710912376599445302527257479613158446721050489233911736089191439017996962182413511012900366501119556105789078275149705515012300827868862038071066912823449506913958912235923323638505757204526506327010926007595704417253684932596231606733027284263178479840785607928320603259662026791082244015829365605451084366715394628351636563955621161378688550003390556445245074739462307110100863024184316465734324401688465928827408449165190271528329602702373730346394803239394173490819727873116531045433457650881080122796159241596543253982402471104065237941729677594379317274541529006952959000152687275974001138315010176843925599438278290218390644740919129323109582279220437886915496736885058271413958305953151184342725824729076581370881383360210631877985352671536000503948280559301633936877162466145026758809907939645467704805892486147550057845773849575278620555906080753862688722846292689494961297512113753414009189522365247542490200336579292488067953461299023326925661887077747288500270026888774635820948696015812357241781814592351848858954139716506111479475207696790949277211077720834891880913260866501916732427370806066035548982017315826213049658915419681842381914237502216614528174237875875738156132703973666564945026254499265910704148825037630761619650949635972980035630316257135212349181639940504547722767898302879234673272154028964478458469466250102554612059368293497511404163963705442187242769706586819405113285219700159125119338601931670779192478917206878107091618448093140705173062420040261126935373689918208815797991761563304607704283868972915636425613833785564679990574095368828308776724486415005128506687942819070129022911666887363253202695416103545769073021185132010920185208632024811337544715055406031297413168802089421761798020616230024290524096396092608042069087607272534874457093977610919233750725135220581682913316085638068663247820037223692942067994551786014033707387642820855601334002540339334606906772532939337779748305357112540312103757754695577077583846897693527091162962000082213332051059005644562753372638247584982354478224403477604356150912451128591138652721098074872513196253790561736352841309810909110001754673250730698454675988798465247376421075019414107337634079281061629221783859449063069175434073835673063716565555614782886016441814199915418848976070834414782427725187820926042778984081922550398210353288229598805397201850487997254871012213762289412828417039945896819359898337616122446201299182152276549340911589671291124887672310931868023491872685227548726494469798568145715500153324646857181224645073236602344526749192704938665584870007079941922775292601106345725659322322536675461008337648982039319953181733660980694781559207671567197161027796266390879206526082137700937056380629087949633487181507979286568656291044492869916694352395542638882544967807857391058161838343109606346401310155771709714142586733985703451391374159045025205718989407293651441039802247981386993858491342422355232055341447145969376687615001834650283116652856369804298047720786536278306210551862061566639283704928517998916884505819581251906693306116531467413995747910736025576089721150597919824878333808115757216261812226145636769545796913912159437533454858286778214791559458862216426856243544801486923659355580455048265633089421966932180992

Generates following befunge program:

"WN W WS S ES E EN N">:#,_@

Krzysztof Szewczyk

Posted 2019-06-09T16:39:14.690

Reputation: 3 819

2

Hodor, 177 bytes

hodor.hod("HoOodoOorhodor  HoOodoOorhodor HooodorrHodor  HooodorrHodor  HODOR?!? HooodorrHodor  HODOR?!?  HODOR?!? Hooodorrhodor  Hooodorrhodor  HoOodoOorhodor Hooodorrhodor ");

Try it online!

steve

Posted 2019-06-09T16:39:14.690

Reputation: 2 276

2

Assembly (x86, Linux), 68 bytes

$ od -x a
0000000 457f 464c 0001 0000 0000 0000 0000 0500
0000020 0002 0003 001b 0500 001b 0500 0004 0000
0000040 13b2 31b9 0000 cd05 2580 0020 0001 cd40
0000060 4e80 4e20 2045 2045 4553 5320 5320 2057
0000100 2057 574e
0000104
$ ./a
N NE E SE S SW W NW$

Source:

BITS 32
org 0x05000000
db 127,"ELF"
dd 1,0
dd $$
dw 2,3
dd 0x0500001B,0x0500001B
dd 4
mov dl,19
mov ecx,m
int 128
db 37
dw 32,1
inc eax
int 0x80
m db 'N NE E SE S SW W NW'

Code mostly taken from Shortest ELF for "Hello world\n"?

steve

Posted 2019-06-09T16:39:14.690

Reputation: 2 276

1

Jelly, 16 bytes

“æṖØq’ḃ⁴ḃ4ị“NESW

Try it online!

With footer to print separated by space

A niladic link which returns a list of strings. 2 bytes shorter (and arguably more interesting) than the compressed string in Jelly.

Nick Kennedy

Posted 2019-06-09T16:39:14.690

Reputation: 11 829

1

Java, 24 bytes

Quick, gotta do it before anyone else

v->"N NE E SE S SW W NW"

Null is equivalent to no input
TIO

Benjamin Urquhart

Posted 2019-06-09T16:39:14.690

Reputation: 1 262

According to the meta it indeed is allowed to take an unused null argument when a challenge states no input. I suggest using the Void class as input, since it has no useful static calls nor purposes. Try it online. EDIT: Ah, I see you had that initially, so you could roll-back and perhaps add the meta-post. ;) – Kevin Cruijssen – 2019-06-11T13:38:04.960

@KevinCruijssen I rolled it back – Benjamin Urquhart – 2019-06-11T13:57:02.693

1

C# (Visual C# Interactive Compiler), 24 bytes

_=>"N NE E SE S SW W NW"

Try it online!

Embodiment of Ignorance

Posted 2019-06-09T16:39:14.690

Reputation: 7 014

7This also works in Javascript. – CalculatorFeline – 2019-06-10T04:19:49.583

Polyglot with Foo. – my pronoun is monicareinstate – 2019-06-12T04:29:07.637

what other characters are allowed besides '_' ? – Buda Florin – 2019-07-03T13:12:06.153

1

PowerShell, 21 bytes

'N NE E SE S SW W NW'

Try it online!

mazzy

Posted 2019-06-09T16:39:14.690

Reputation: 4 832

Same in Swift Playground, with "N NE E SE S SW W NW", if you want. But too trivial to post. – Cœur – 2019-06-10T10:03:19.283

4this is code golf. see not trivial in the edit history. – mazzy – 2019-06-10T12:04:21.057

1

R, 26 bytes

cat('N NE E SE S SW W NW')

Try it online!

Robert S.

Posted 2019-06-09T16:39:14.690

Reputation: 1 253

1

As input to Commodore BASIC, you can get it even shorter: (23 bytes)

0 ?"N NE E SE S SW W NW

? is shorthand for PRINT.

Greywolf

Posted 2019-06-09T16:39:14.690

Reputation: 11

? and PRINT use the same number of BASIC tokens so you are not saving any memory in your stored symbolic listing. – Shaun Bebbers – 2019-07-02T12:09:34.177

1

><>, 25 24 bytes

This is a pretty simple answer. Push the string in reverse, then print the stack. Exits with an error due to stack underflow.

"WN W WS S ES E EN N">o<

Try it online!

mbomb007

Posted 2019-06-09T16:39:14.690

Reputation: 21 944

You can remove the skip and it still works, doesn't it? – Reinstate Monica – 2019-06-11T15:35:51.827

@squid Indeed. I originally was using | instead of the arrows. – mbomb007 – 2019-06-11T18:10:23.090

If superfluous spaces are allowed, you can shave off one more byte "WN WWS SES EEN N">ooa<. – PidgeyUsedGust – 2019-06-18T09:33:32.607

1

Assembly (MIPS, SPIM), 71 70 bytes

.data
t:.ascii"N NE E SE S SW W NW"
.text
main:li $2,4
la $4,t
syscall

Try it online!

I haven't done anything with MIPS in a while, so if there's a shorter way please tell me!

Edit: used an ascii and not an asciiz string

qwertxzy

Posted 2019-06-09T16:39:14.690

Reputation: 101

1

k, 23 bytes

1_,/'$,/``N`S,/:\:``E`W

Henry Henrinson

Posted 2019-06-09T16:39:14.690

Reputation: 509

1

Keg, 19 bytes

Simply hard-coding the answer.

N NE E SE S SW W NW

user85052

Posted 2019-06-09T16:39:14.690

Reputation:

1

SQL, 28 26 bytes

On behalf of BradC:

PRINT'N NE E SE S SW W NW'

SELECT 'N NE E SE S SW W NW'

Jan Drozen

Posted 2019-06-09T16:39:14.690

Reputation: 491

You can save 2 bytes with PRINT'N NE E SE S SW W NW' – BradC – 2019-09-19T13:50:13.300

@BradC: Also thought about this, but I am not sure it matches the rules, because, yes, it prints desired result, but in principle returns nothing. But you may be right. – Jan Drozen – 2019-09-19T13:53:19.677

We pretty routinely use whichever of PRINT or SELECT is shorter/more useful for SQL-language challenges on CodeGolf, see the SQL language tips thread. Either way you can drop the space before the quote.

– BradC – 2019-09-19T14:43:20.053

1

Stax, 16 bytes

Ä\8←ΘåÑ¥▒Nx╚ø┼Çt

Run and debug it

Oliver

Posted 2019-06-09T16:39:14.690

Reputation: 7 160

0

Haskell, 21 bytes

I don't think it gets any shorter than this in Haskell.

"N NE E SE S SW W NW"

Try it online!

flawr

Posted 2019-06-09T16:39:14.690

Reputation: 40 560

0

Ruby, 22 bytes

p'N NE E SE S SW W NW'

Try it online!

Idva

Posted 2019-06-09T16:39:14.690

Reputation: 97

0

One more Python example:

for i in range(8):print''.join(c*((i+m)%8<3)for c,m in zip('NSEW',(1,5,7,3))),

I tried to use no cryptic operations, just normal math + boolean logic. Try it

Volodymyr Khoroz

Posted 2019-06-09T16:39:14.690

Reputation: 1

0

Stax, 16 bytes

Æ+góïr!½*ÄJ╓╨°╩Æ

Run and debug it

recursive

Posted 2019-06-09T16:39:14.690

Reputation: 8 616

0

Assembly (x86, GCC), 151 bytes

$ cat foo.s
.global _start
.text
_start:mov $1,%rax
mov $1,%rdi
mov $m,%rsi
mov $19,%rdx
syscall
mov $60,%rax
xor %rdi,%rdi
syscall
m:.ascii "N NE E SE S SW W NW"
$ gcc -c foo.s && ld foo.o && ./a.out
N NE E SE S SW W NW$

steve

Posted 2019-06-09T16:39:14.690

Reputation: 2 276

1Suggest mov $60,%al – ceilingcat – 2019-06-19T10:35:06.573

0

DC, 79 bytes

78sn7Dss69se87swAsblblwlnlblwlblwlslblslblelslblelblelnlblnPPPPPPPPPPPPPPPPPPPP

It loads the characters NESW and newline into registers, then loads them onto the stack and prints them all

FlexEast

Posted 2019-06-09T16:39:14.690

Reputation: 31

0

Underload, 22 bytes

(N NE E SE S SW W NW)S

Pretty self explanatory

Try it online!

EdgyNerd

Posted 2019-06-09T16:39:14.690

Reputation: 1 106

0

Befunge-93, 45 bytes

"WN W":" "\"S":" "\" ES E":" "\"N":" "\>:#,_@

Try it online!

ItsJ0el

Posted 2019-06-09T16:39:14.690

Reputation: 95

Or just hardcode the string

– Jo King – 2019-07-12T09:41:33.863

@JoKing I am aware that this is an option, but I didn't want to just hardcode it – ItsJ0el – 2019-07-12T11:26:29.533