title: Print "N NE E SE S SW W NW"

text:
# Question
Title: Print "N NE E SE S SW W NW"
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.

# Answer
> 20 votes
# Canvas, 12 bytes

```
＞X½+Ｔ）ＡuS{⁹‟

```

Try it here!

The string, simply compressed.

# Answer
> 59 votes
# 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}

```

# Answer
> 48 votes
# 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.

# Answer
> 30 votes
# 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.

# Answer
> 27 votes
# 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!".

# Answer
> 15 votes
# Brain-Flak, 204 bytes

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

```

Try it online!

# Answer
> 14 votes
# MarioLANG, 249 221 bytes

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

```

Try it online!

# Answer
> 13 votes
# 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:

After:

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

# Answer
> 11 votes
# 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!

# Answer
> 10 votes
# 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.

# Answer
> 9 votes
# 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.

# Answer
> 8 votes
# Charcoal, 14 bytes

```
”{⊟“�_Ｚn↖⦄ＲüΦ≦

```

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:

```
Ｅ⁸Φ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`.

# Answer
> 8 votes
# 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..

# Answer
> 6 votes
# 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ỵÑ’ṃ“¡⁴ṁ»`.

# Answer
> 6 votes
# 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.

# Answer
> 6 votes
# Vyxal, 13 bytes

```
«ƛ.←√Fǎ⁰ɾ@=½•

```

Try it Online!

-1 thanks to AaronMiller

Vyxal forever lads, it has crushed 05AB1E and Jelly I am so proud

# Answer
> 5 votes
# 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';
}

```

# Answer
> 4 votes
# 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.

# Answer
> 4 votes
# K (ngn/k), ~~23~~ 22 bytes

-1 byte thanks to ngn!

```
"WNES"@5\7108085518230

```

Try it online!

# , ~~34~~ 30 bytes

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

```

Try it online!

# Answer
> 4 votes
## 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

```

# Answer
> 4 votes
# 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)

```

# Answer
> 4 votes
# 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.

# Answer
> 4 votes
# CSS, 42 39 bytes

(thanks to a stone arachnid for the revised version)

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

# Answer
> 4 votes
## 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))

```

# Answer
> 4 votes
# Seed, 4251 bytes

```
27 [encoded data, 4248 characters]

```

Try it online!

# Answer
> 4 votes
# Hodor, 177 bytes

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

```

Try it online!

# Answer
> 3 votes
# 05AB1E, 14 bytes

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

```

Try it online!

This prints out the string except lowercase.

# Answer
> 3 votes
# Brachylog, 18 bytes

```
"NeSw"it;?↺₍h₂a₀oụ

```

Try it online!

Semi-port of my Jelly solution. Generates each direction.

```
"NeSw"                Let the input variable be "NeSw".
      i               Take a pair [element, 0-index] from it,
       t              extract the index,
        ;?↺₍          and rotate the input variable left by that many places.
            h₂        Keep only the first two elements of the rotation,
              a₀      take a prefix (nonempty, shortest first) of it,
                o     sort (putting uppercase before lowercase),
                 ụ    and fold to uppercase.

```

Barely beats my original...

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

```

# Answer
> 3 votes
# JSFuck, 8529 bytes

```
[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+(+[![]]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]+(+(!+[]+!+[]+!+[]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([]+[])[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]][([][[]]+[])[+!+[]]+(![]+[])[+!+[]]+((+[])[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]+[])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]]](!+[]+!+[]+!+[]+[!+[]+!+[]])+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]])()([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+([]+[])[(![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]()[+!+[]+[!+[]+!+[]]]+((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+[+!+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+[!+[]+!+[]+!+[]+!+[]]+(!![]+[])[+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]]+[+[]]+(!![]+[])[+[]]+[!+[]+!+[]+!+[]+!+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+(+[![]]+[])[+[]]+(!![]+[])[+[]]+[!+[]+!+[]+!+[]+!+[]]+[+[]]+(+[![]]+[])[+[]]+(!![]+[])[+[]]+[+!+[]]+[+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]]+(!![]+[])[+[]]+[!+[]+!+[]+!+[]+!+[]]+[+[]]+(!![]+[])[+[]]+[+!+[]]+[+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]]+(!![]+[])[+[]]+[!+[]+!+[]+!+[]+!+[]]+[+[]]+(!![]+[])[+[]]+[+!+[]]+[!+[]+!+[]]+[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+[+!+[]]+[+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]]+(!![]+[])[+[]]+[!+[]+!+[]+!+[]+!+[]]+[+[]]+(!![]+[])[+[]]+[+!+[]]+[!+[]+!+[]]+[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+[!+[]+!+[]+!+[]+!+[]]+[+[]]+(!![]+[])[+[]]+[+!+[]]+[!+[]+!+[]]+[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+[+!+[]]+[!+[]+!+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+(!![]+[])[+[]]+[!+[]+!+[]+!+[]+!+[]]+[+[]]+(!![]+[])[+[]]+[+!+[]]+[!+[]+!+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+(!![]+[])[+[]]+[!+[]+!+[]+!+[]+!+[]]+[+[]]+(+[![]]+[])[+[]]+(!![]+[])[+[]]+[+!+[]]+[!+[]+!+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+(!![]+[])[+[]]+[!+[]+!+[]+!+[]+!+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+(!![]+[])[+[]]+[!+[]+!+[]+!+[]+!+[]+!+[]]+[+!+[]])[(![]+[])[!+[]+!+[]+!+[]]+(+(!+[]+!+[]+[+!+[]]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([]+[])[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]][([][[]]+[])[+!+[]]+(![]+[])[+!+[]]+((+[])[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]+[])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]]](!+[]+!+[]+!+[]+[+!+[]])[+!+[]]+(![]+[])[!+[]+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(!![]+[])[+[]]]((!![]+[])[+[]])[([][(!![]+[])[!+[]+!+[]+!+[]]+([][[]]+[])[+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(!![]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]]()+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([![]]+[][[]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]](([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]][([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+(![]+[+[]])[([![]]+[][[]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]]()[+!+[]+[+[]]]+![]+(![]+[+[]])[([![]]+[][[]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]]()[+!+[]+[+[]]])()[([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[+[]])[([![]]+[][[]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]]()[+!+[]+[+[]]])+[])[+!+[]])+([]+[])[(![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(!![]+[])[+[]]+([][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+(!![]+[])[+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]()[+!+[]+[!+[]+!+[]]])())

```

Just for the fun of it

# Answer
> 2 votes
# PowerShell, 21 bytes

```
'N NE E SE S SW W NW'

```

Try it online!

# Answer
> 2 votes
# 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"?

# Answer
> 2 votes
# Pip `-s`, 20 bytes

Just *barely* shorter than printing the literal string.

```
"NESW"WV<>"NESESWNW"

```

Attempt This Online!

### Explanation

```
"NESW"WV<>"NESESWNW"
      WV              Weave
"NESW"                the characters of this string
                      with
          "NESESWNW"  this string
        <>            taken in blocks of 2 characters each
                      Result: ["N";"NE";"E";"SE";"S";"SW";"W";"NW"]
                      Autoprint, space-separated (-s flag)

```

I added the unary version of `<>` because of this challenge, although I'm sure it will be useful elsewhere too.

# Answer
> 2 votes
# A0A0, 69 bytes

```
P78P32P83
P32P83P87
P78P69P32
P69P32P87
P32P83P32
P69P32P78
G-6G-6P87

```

Not much to this one, `Px` prints the character corresponding to ascii value `x`, so we just print the correct values. `G-6` jumps back to the top. Splitting the code into three columns is optimal for saving bytes on new lines, while not using too many bytes on additional jumps. Two columns gives the same amount of bytes, but three columns is nicer to display on this site.

# Answer
> 2 votes
# Malbolge, ~~151~~ ~~126~~ ~~118~~ 115 bytes

```
(&<`@#!\}5Y9z1Uv4tQsr)M-n%I#"!&DBe/R-`_<ts[Jp$5WUk1ShmPkd*uts%G#bE`lkW\>-Y+:utT`R5P2HMk/-h++@d'&%;:^8~6}Y32V0T.uQ+N

```

Try it online!

# Answer
> 1 votes
# 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.

# Answer
> 1 votes
# 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

# Answer
> 1 votes
# C# (Visual C# Interactive Compiler), 24 bytes

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

```

Try it online!

# Answer
> 1 votes
# , 26 bytes

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

```

Try it online!

# Answer
> 1 votes
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**.

# Answer
> 1 votes
# \>\<\>, ~~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!

# Answer
> 1 votes
# 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

# Answer
> 1 votes
# k, 23 bytes

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

```

# Answer
> 1 votes
## Keg, 19 bytes

Simply hard-coding the answer.

```
N NE E SE S SW W NW

```

# Answer
> 1 votes
# 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'

# Answer
> 1 votes
# Stax, 16 bytes

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

```

Run and debug it

# Answer
> 1 votes
# Perl 5, 21 bytes

```
<N {N,,S}E S {S,,N}W>

```

Standard `glob` function emulating \*nix shell. See `perldoc -f glob` for more details.

### Alternative, 21 bytes

```
<N NE E SE S SW W NW>

```

Didn't need to use `qw` since `glob` splits on whitespace and treats each pattern separately.

# Answer
> 1 votes
# Jelly, 14 bytes

```
8ḶHị“eSwN”Ṣ€Œu

```

Try it online!

Niladic link returning a list of strings.

```
  H               Halve
8Ḷ                each number in 0 .. 7,
   ị“eSwN”        and modular 1-index each into “eSwN”.
                  Not only is ị modular, but it also handles fractional indices by flooring and ceiling them, returning a list of both elements.
          Ṣ€      Sort each, placing lowercase letters after uppercase.
            Œu    Uppercase.

```

~~Come to think of it, this returns a ragged array of characters, rather than a real list of strings, so I guess you can slap a `K` on the end and call it a full program if that’s an issue.~~ I guess the  actually does wrap non-list arguments.

# Answer
> 1 votes
# Thunno 2, 13 bytes

```
“£ḂA⁷<ọŒ⁼Ẓ2Ẏ®

```

Simple compressed string. Add the  flag if you want it in uppercase.

#### Screenshot

# Answer
> 0 votes
# 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!

# Answer
> 0 votes
# Ruby, 22 bytes

```
p'N NE E SE S SW W NW'

```

Try it online!

# Answer
> 0 votes
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

# Answer
> 0 votes
# Stax, 16 bytes

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

```

Run and debug it

# Answer
> 0 votes
# 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$

```

# Answer
> 0 votes
# **DC, 79 bytes**

```
78sn7Dss69se87swAsblblwlnlblwlblwlslblslblelslblelblelnlblnPPPPPPPPPPPPPPPPPPPP

```

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

# Answer
> 0 votes
# Underload, 22 bytes

```
(N NE E SE S SW W NW)S

```

Pretty self explanatory

Try it online!

# Answer
> 0 votes
# Befunge-93, 45 bytes

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

```

Try it online!

# Answer
> 0 votes
# Python 2, 26 bytes

```
print'N NE E SE S SW W NW'

```

Try it online!

Why make things complicate when we can do simple??

# Answer
> 0 votes
# Red, 25 bytes

```
prin"N NE E SE S SW W NW"

```

Try it online!

My first Red answer and first answer this month.

# Answer
> 0 votes
# Smalltalk, 37 bytes

```
Transcript show:'N NE E SE S SW W NW'

```

26 bytes if you don't mind surrounding quotes:

```
'N NE E SE S SW W NW'print

```

---
Tags: code-golf, string, kolmogorov-complexity
---


title: Double trace of a square matrix

text:
# Question
Title: Double trace of a square matrix
*Inspired by a question (now closed) at Stack Overflow.*

Given a square matrix, let its *double trace* be defined as the sum of the entries from its main diagonal and its anti-diagonal. These are marked with `X` in the following examples:

```
X · · X
· X X ·
· X X ·
X · · X

```

```
X · · · X
· X · X ·
· · X · ·
· X · X ·
X · · · X

```

Note that for odd `n` the central entry, which belongs to both diagonals, is counted only once.

### Rules

* The matrix size can be any positive integer.
* The matrix will only contain non-negative integers.
* Any reasonable input format can be used. If the matrix is taken as an array (even a flat one) its size cannot be taken as a separate input.
* Input and output means are flexible as usual. Programs or functions are allowed. Standard loopholes are forbidden.
* Shortest wins.

### Test cases

```
5
   ->  5

```

```
3 5
4 0
     ->  12

```

```
 7  6 10
20 13 44
 5  0  1
          ->  36

```

```
4 4 4 4
4 4 4 4
4 4 4 4
4 4 4 4
          ->  32

```

```
23  4 21  5
24  7  0  7
14 22 24 16
 4  7  9 12
             ->  97

```

```
22 12 10 11  1
 8  9  0  5 17
 5  7 15  4  3
 5  3  7  0 25
 9 15 19  3 21
                -> 85

```

Inputs in other formats:

```
[[5]]
[[3,5],[4,0]]
[[7,6,10],[20,13,44],[5,0,1]]
[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]]
[[23,4,21,5],[24,7,0,7],[14,22,24,16],[4,7,9,12]]
[[22,12,10,11,1],[8,9,0,5,17],[5,7,15,4,3],[5,3,7,0,25],[9,15,19,3,21]]

```

```
[5]
[3 5; 4 0]
[7 6 10; 20 13 44; 5 0 1]
[4 4 4 4; 4 4 4 4; 4 4 4 4; 4 4 4 4]
[23 4 21 5; 24 7 0 7; 14 22 24 16; 4 7 9 12]
[22 12 10 11 1; 8 9 0 5 17; 5 7 15 4 3; 5 3 7 0 25; 9 15 19 3 21]

```

```
[5]
[3,5,4,0]
[7,6,10,20,13,44,5,0,1]
[4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4]
[23,4,21,5,24,7,0,7,14,22,24,16,4,7,9,12]
[22,12,10,11,1,8,9,0,5,17,5,7,15,4,3,5,3,7,0,25,9,15,19,3,21]

```

# Answer
> 7 votes
# Jelly, 8 bytes

```
TżU$Ṭḋ⁸S

```

Try it online!

```
T         -- truthy indices of the argument, since every row is non-empty, this is [1 .. len(z)]
 żU$      -- zip with its reverse
    Ṭ     -- for each pair of integers, create a list with 1's at those two indices
     ḋ⁸   -- for each resulting list, take the dot product with the corresponding row vector of the input matrix
       S  -- sum the results

```

# Answer
> 8 votes
# APL (Dyalog 18.0), ~~17~~ 16 bytes

−1 thanks to Vadim Tukaev.

Anonymous lambda.

```
{≢⍸⍵×∨∘⌽⍨∘.=⍨⍳≢⍵}

```

Try it online!

`{``}`dfn; argument is

`⍴⍵` shape (number of rows and columns) in the argument

**i**ndices of an array of that size

`=/¨` equality-reduction of each row-column pair (gives identity matrix)

`∨∘⌽⍨` OR with mirrored self (indicates both diagonals)

`⍵×` multiply with argument

`≢⍸` sum (lit. length of list of indices where each index is repeated as many times as its corresponding number in that)

# Answer
> 6 votes
# , 47 bytes

```
function(m)sum(m[(z=diag(y<-nrow(m)))|z[y:1,]])

```

Try it online!

# Answer
> 6 votes
# K (ngn/k), 15 bytes

```
{+//x*|/|:\=#x}

```

Try it online!

Useful to have an identity matrix primitive.

Explanation:

```
{+//x*|/|:\=#x}
           =#x    / identity matrix with size of x
        |:\       / append reverse
      |/          / OR both matrices
    x*            / multiply by original matrix
 +//              / sum all elements

```

# Answer
> 5 votes
# Python 3.10, 58 bytes

```
lambda m,i=0:sum(r[i:=i-1]+r[~i]*(~i!=len(m)+i)for r in m)
```

Attempt This Online!

---

# Python 3, 62 bytes

```
lambda m:sum(r[i]+r[~i]*(i!=len(m)+~i)for i,r in enumerate(m))

```

Try it online!

## Explanation

```
lambda m:
                                      for i,r in enumerate(m)  # iterate m with i = row index and r = row
                 +r[~i]*(i!=len(m)+~i)                         # add r[len(m) - i - 1] if the index does not equal i
             r[i]                                              # add r[i]
         sum(                                                ) # sum numbers generated by the loop

```

# Answer
> 4 votes
# Octave, ~~36~~ 34 bytes

This uses logical indexing. As an index we use an identity matrix of the size of the input and `or` it with it's flipped version. Thanks @LuisMendo for -2 bytes!

```
@(x)sum(x(flip(e=eye(size(x)))|e))

```

Try it online!

# Answer
> 4 votes
# MATL, ~~13~~ 11 bytes

This uses logical indexing. As an index we use an identity matrix of the size of the input and or it with it's flipped version, just like in my Octave answer. Thanks @LuisMendo for -2 bytes:)

```
tZyXytPY|)s

```

**Explanation**

```
t            push input twice to stack
 Zy          get size of matrix
   Xy        get an identity matrix of that size
     t       duplicate the identity matrix
      P      flip one of the identty matrices
       Y|    logical OR the two identity matrices
         )   perform (logical) indexing to the original matrix
          s  compute the sum

```

Try it online!

# Answer
> 3 votes
# Vyxal, 8 bytes

```
LÞ□Ḃ⋎*∑∑

```

Try it Online!

```
 Þ□      # Identity matrix of size...
L        # len(input)
    ⋎    # OR with...
   Ḃ     # itself reversed
     *   # Multiply by input
      ∑∑ # Sum

```

# Answer
> 2 votes
# Pari/GP, 42 bytes

```
m->sum(i=1,#m,m[i,i]+m[i,j=#m+1-i]*(i!=j))

```

Try it online!

# Answer
> 2 votes
# C (gcc), <sup>~~81~~ \\$\cdots\\$ ~~71~~</sup> 59 bytes

```
i;f(m,l)int*m;{for(i=l*l;--i;)*m+=i%~l&&i%~-l?0:m[i];l=*m;}

```

Try it online!

*Saved a bytes thanks to att!!!*
*Saved 12 bytes thanks to AZTECCO!!!*

Inputs a pointer to a flattened square array and the number of rows (because pointers in C carry no length info).
Returns its double trace.

# Answer
> 2 votes
# 05AB1E, 9 bytes

```
āDδQÂ~*˜O

```

Try it online!

-1 thanks to @KevinCruijssen

Wish to have the identity matrix builtin

```
g               Length
 L              Range
  D             Dup
   δ            Outer product with
    Q           Equals?
     Â          Bifurcate
      ~         Bitwise OR
       *        Multiply with input
        ˜       Flatten
         O      Sum

```

# Answer
> 2 votes
# Ruby, 64 bytes

```
->m{(r=0...l=m.size).sum{|y|r.sum{|x|x==y||x-~y==l ?m[y][x]:0}}}

```

Try it online!

```
->m{              # lambda taking a 2d array and returning diagonal sum
(r=0...l=m.size)  # range 0..length
.sum{|y|r.sum{|x| # sum the result of passing each coordinates

x==y||x-~y==l ?   # if on diagonals
m[y][x]:0         # take value else 0

```

# Answer
> 2 votes
# Pip `-x`, ~~24~~ ~~21~~ 20 bytes

```
YEY#a$+$+a*HV:y+1+Ry

```

Attempt This Online! The matrix should be given as a command-line argument in the following form:

```
[[7;6;10];[20;13;44];[5;0;1]]

```

Or, verify all test cases.

### Explanation

```
YEY#a$+$+a*HV:y+1+Ry
   #a                 Size of the matrix
 EY                   Identity matrix of that size
Y                     Yank into the y variable
                  Ry  y reversed (backward identity matrix)
                1+    Add 1 to each value
              y+      Add to y (identity matrix)
           HV:        Each value halved (rounded down)
                      This creates a matrix where both diagonals are 1's and
                      everything else is 0's
         a*           Multiply the input matrix itemwise by the 1/0 matrix
       $+             Fold on addition (sum each column)
     $+               Fold on addition (sum that list of sums)

```

# Answer
> 2 votes
# tinylisp, ~~132~~ 109 bytes

```
(load library
(d L length
(d f(q((M)(s(a(trace M)(trace(reverse M)))(*(odd?(L M))(nth(nth M(/(L M)2))(/(L M)2

```

Try it online!

-23 bytes thanks to DLosc.

# Answer
> 2 votes
# Japt `-mx`, 11 bytes

```
gV +J´gUhVT

```

Try it

```
gV +J´gUhVT     :Implicit map of each row U at 0-based index V in implicit input array
gV              :Index V into U
   +            :Add
    J           :  Initially -1
     ´          :  Postfix decrement
      g         :  Index into
       UhV      :    U with the character at index V replaced with
          T     :    0
                :Implicit output of sum of resulting array

```

# Answer
> 1 votes
# JavaScript (ES6), 51 bytes

```
m=>m.reduce((t,r,i)=>t+r[i]+r.reverse(r[i]=0)[i],0)

```

Try it online!

### Commented

```
m =>         // m[] = matrix
m.reduce(    // reduce():
  ( t,       //   t   = sum
    r,       //   r[] = current row
    i        //   i   = row index, used as a column index
  ) =>       //
  t + r[i] + //   add r[i] to t
  r.reverse( //   reverse r[] ...
    r[i] = 0 //     ... but only once r[i] has been cleared
             //     so that it's not counted twice
  )[i],      //   add r[i] again
  0          //   start with t = 0
)            // end of reduce()

```

---

# JavaScript ES2022, 46 bytes

Suggested by @tsh:

```
m=>m.reduce((t,r,i)=>t+r[i]+r.at(~i,r[i]=0),0)

```

(Doesn't work on TIO.)

# Answer
> 1 votes
# Charcoal, 18 bytes

```
ＩΣＥθΣΦι∨⁼κμ⁼⁺κμ⊖Ｌθ

```

Try it online! Link is to verbose version of code. Explanation: Filters out elements not on either main diagonal, then takes the sum.

```
   θ                Input matrix
  Ｅ                 Map over rows
      ι             Current row
     Φ              Filtered where
         κ          Row index
        ⁼           Equals
          μ         Column index
       ∨            Logical Or
             κ      Row index
            ⁺       Plus
              μ     Column index
           ⁼        Equals
                 θ  Input matrix
                Ｌ   Length
               ⊖    Decremented
    Σ               Take the sum
 Σ                  Take the sum
Ｉ                   Cast to string
                    Implicitly print

```

# Answer
> 1 votes
# Pyth, 18 bytes

```
s.e+@bk&-hyklb@_bk

```

Try it online!

## Explanation

```
s.e+@bk&-hyklb@_bk
 .e                 # Iterate through implicit input with (b = row, k = index)
    @bk             # b[k]
       &-hyklb      # if ((2 * k) + 1) - len(b) != 0
   +          @_bk  #   plus b[::-1][k]
s                   # sum results from the iteration

```

The `((2 * k) + 1) - len(b)` is derived from rearranging `k - (len(b) - (k + 1))`

# Answer
> 1 votes
# Raku, 43 bytes

```
{sum .kv.flatmap:{@^v[unique $^k,@v-$k-1]}}

```

Try it online!

A function which takes its input in `$_` as a list-of-lists.

* `.kv` returns an interleaved sequence of each row's index and the row, ie: `0`, the first row, `1`, the second row, etc.
* `.flatmap: { ... }` passes the key and value to the brace-delimited anonymous function and flattens the return values. That function takes the index of each row in `$k` and the row itself in `@v`, each argument declared with a "twigil" `$^`/`@^` on its first lexical appearance.
* `$k` and `@v - $k - 1` are the indices of the elements of each row that go into the double trace. `@v`, the row, evaluates to its number of elements in a numerical context (the subtraction operator).
* `unique` selects only the unique indices. This eliminates the double index at the center of the matrix, if it has an odd dimension.
* `@v[...]` is a slice that returns the row elements at the unique indices.

---
Tags: code-golf, array, integer, matrix
---


title: Appending Numbers

text:
# Question
Title: Appending Numbers
A fairly simple challenge: You will receive two inputs, a string and a number (the number may be taken as a string, ie `"123"` instead of `123`)

If the string does not end in a number (ie, it does not match the regex `\d$`), just append the number to the end of the string.

If the string does end in a number (ie, it matches the regex `\d+$`), you should first delete that and then append the number.

Neither of the inputs will ever be invalid or empty (invalid is defined by the numerical input not containing only digits)

The number will never contain a `-` or a `.`.

The string will never contain a newline, or unprintable non-whitespace characters.

## Test Cases:

```
abc123 + 345 -> abc345
123 + 1 -> 1
hello + 33 -> hello33
123abc123 + 0 -> 123abc0
ab3d5 + 55 -> ab3d55
onetwo3 + 3 -> onetwo3
99ninenine + 9999 -> 99ninenine9999

```

# Answer
> 10 votes
# Retina, 5 bytes

```
\d*¶

```

Takes two strings as input, separated by a newline.

Try it online!

# Answer
> 7 votes
# Python 2, 30 bytes

```
lambda a,b:a.rstrip(`56**7`)+b

```

Try it online!

# Answer
> 6 votes
# PHP, 37 36 35 33 bytes

```
<?=chop($argv[1],3**39),$argv[2];

```

Saved 1 byte thanks to Jörg Hülsermann.

# Answer
> 5 votes
## Perl 5, 12 bytes

**11 bytes code + 1 for `-p`.**

```
s/\d*$/<>/e

```

Try it online!

# Answer
> 5 votes
# Java 8, 32 bytes

```
a->b->a.replaceAll("\\d*$","")+b

```

Takes input `a` as a String, and for `b` it doesn't matter whether it's a String or integer (although I use Integer in the TIO-link below).

Try it here.

# Answer
> 4 votes
# Japt, 10 bytes

```
r"%d*$" +V

```

Try it online!

```
 r"%d*$" +V
Ur"%d*$" +V # Implicit input (U and V)
 r          # Remove
  "%d*$"    #   any trailing digits
U           #   from the first input
         +V # And append the second input
            # Implicit output

```

# Answer
> 4 votes
# Python 2, ~~44~~ ~~41~~ 39 bytes

**EDIT:** -4 bytes thanks to @Dom Hastings. I don't use regular expressions much.

**EDIT 2**: -2 bytes thanks to @totallyhuman pointing out that the number could be taken as a string

Had to be expected...

```
lambda x,y:re.sub("\d*$",y,x)
import re

```

Just removes the digits at the end of the string and appends the number

Try it online!

# Answer
> 4 votes
# Pip, ~~9~~ 7 bytes

```
a<|XD.b

```

*@DLosc saved me 2 bytes!*

Try it online!

Explanation

```
a<|         Strip all matches off the end of 'a' (the first cmd line arg)
   XD         of the pattern \d (ordinarily, a regex would be entered as '\d', but digits
              have a pre-existing constant XD)
     .b     Then concatenate 'b' (the second cmd line arg)
            PIP implicitly prints the results of the last operation.

```

# Answer
> 4 votes
# Python 2, 32 bytes

```
import re
re.compile("\d*$").sub

```

Try it online!

Takes the inputs in reverse order, both as string.

# Answer
> 4 votes
# 05AB1E, 9 bytes

```
DvTFNÜ}}«

```

Try it online! Probably a bad solution but it's the best I could come up with

### Explanation

```
DvTFNÜ}}«
Dv     }  # For each character in input1
  TF  }   # 10 times
    NÜ    # Get 0-9 and trim it from input1
        « # Concatenate with input2

```

# Answer
> 3 votes
# Ruby, 21 bytes

```
->a,b{a=~/\d*$/;$`+b}

```

Takes two strings in input.

Try it online!

# Answer
> 3 votes
# Jelly, 5 bytes

```
œrØD;

```

Try it online!

### How it works

```
œrØD;  Main link. Left argument: s. Right argument: t

  ØD   Digits; yield "0123456789".
œr     Trim these characters from the right of s.
    ;  Append t.

```

# Answer
> 3 votes
# JavaScript (ES6), ~~28~~ ~~26~~ 25 bytes

```
x=>y=>x.replace(/\d*$/,y)

```
* 1 byte saved thanks to Neil reminding me why I shouldn't golf early in the morning!

# Answer
> 3 votes
# C#, 45 bytes

```
s=>n=>s.TrimEnd("0123456789".ToCharArray())+n

```

Explanation:

```
s=>n=>                                        // Take input
      s.TrimEnd(                              // Trim the end of the string with the specified chars
                "0123456789"                  // Create a string of the digits
                            .ToCharArray())   // Turn the string into a char array
                                           +n // Append the integer onto the end

```

# Answer
> 3 votes
# , ~~7~~ 4 bytes

```
óä*î

```

Try it online!

This uses the same regex as the Retina answer above:

```
s:/\d*\n//

```

# Answer
> 2 votes
# Perl 6, 20 bytes

```
->$_,\n{S/\d*$/{n}/}

```

# Answer
> 2 votes
## Tcl 32 bytes

```
proc s a\ b {regsub \\d*$ $a $b}

```

I'm not sure about the expected interface. This is done as a procedure that accepts the two inputs as call arguments. To turn it to a standalone script that reads input from stdin and outputs the result to stdout, one would need the extra line:

```
puts [s [gets stdin] [gets stdin]]

```

or would do it all "inline":

```
puts [regsub \\d*$ [gets stdin] [gets stdin]]

```

regsub takes an RE, the original string and a string to replace the matching part with.

# Answer
> 2 votes
# Carrot, ~~16~~ 21 bytes

```
$^//^.*?(?=\d*$)/S0^#

```

Try it online! (input is linefeed separated)

### Explanation

```
$^                Set the stack-string to be equal to the first line in the input
/                 Set the stack-array to be equal to the matches of this regex:
 /^.*?(?=\d*$)/   The beginning of the string followed by non-digit characters at the end that are not included in the match.
S0                Convert to a string with 0 as the delimiter
^#                Append the rest of the input to the stack-string

```

I had to increase the bytecount by 5 because the code did not work for testcases like `a5b3` with multiple digits.

# Answer
> 2 votes
## Mathematica, 48 bytes

There is already a Mathematica solution (84 bytes).

```
StringDrop[StringTrim["."<>#,_?DigitQ..]<>#2,1]&

```

# Answer
> 2 votes
# Haskell, ~~75 bytes~~ ~~95 bytes~~ ~~91~~ ~~79~~ 61 bytes

```
b=(`notElem`['0'..'9'])
r=reverse
d#e=r(snd$break b$r d)++e

```

I tried doing this without regex so maybe that would be a dramatically improved answer. Also there are a couple ways I could go about this so I am unsure if I can shave a few bytes with a different approach.

UPDATE: I went up in bytes because I realized I was failing the test case where numbers exist in the string that are not the suffix. Now I am sure that regex would provide a much better answer.

UPDATE2: After some great feedback, more bytes were golfed!

# Answer
> 2 votes
# AWK, 18 bytes

```
sub("[0-9 ]*$",$2)

```

Try it online!

This just replaces a string composed of any number of digits and spaces that ends the arguments to the command with the second argument to the command. It's effectively stripping the commandline and adding back the second argument. And since there's guaranteed to be a non-empty second argument, the result is truthy and `$0` is printed, which is the modified commandline arguments.

# Answer
> 1 votes
# Mathematica, 84 bytes

```
(k=#;T=ToCharacterCode;L=T@k;While[47<Last@L<58,w=k~StringDrop~-1;k=w;L=T@w];w<>#2)&

```

input 2 strings

> \["ab3d5", "55"\]

output

> ab3d55

# Answer
> 1 votes
# Noether, 11 bytes

```
I"\d+$"-I+P

```

**Try it here!**

When inputting a string, enclose it in quotation marks

***Explanation:***

```
I       - Push input to stack
"\d+$"  - Push string to stack
-       - Remove characters from first string which match the regex
I       - Push input to stack
+       - Append to the first string
P       - Print top item of stack

```

# Answer
> 1 votes
# C (gcc), ~~99~~ ~~98~~ ~~96~~ 95 bytes

Should be able to golf this down a bit...

```
main(c,v)char**v;{for(c=strlen(v[1]);~c*isdigit(v[1][--c]);v[1][c]=0);printf(v[1]),puts(v[2]);}

```

Try it online!

# Answer
> 1 votes
# Arturo, 25 bytes

```
$=>[++replace&{/\d+$}""&]

```

Try it

# Answer
> 1 votes
# Go, 77 bytes

```
import."strings"
func a(s,n string)string{return TrimRight(s,"0123456789")+n}

```

Attempt This Online!

# Answer
> 0 votes
# 05AB1E, 8 bytes

```
DþRvyÜ}«

```

Try it online!

**Explanation:**

```
DþRvyÜ}«
D        Duplicate input.
 þ       Get the digits of the input.
  R      Reverse the digits of the input.
   v  }  For each of the digits in the input:
    y        Push the current digit
     Ü       Trim that from the right of the input.
       « Concatenate to 2nd input.

```

# Answer
> 0 votes
# Google Sheets, 28 bytes

```
=REGEXREPLACE(A1,"\d+$",)&B1

```

---
Tags: code-golf, string
---