56
\$\begingroup\$

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.

\$\endgroup\$
10
  • 10
    \$\begingroup\$ Perhaps allowing them to be output in any order would be slightly more interesting \$\endgroup\$
    – Jo King
    Jun 10, 2019 at 0:14
  • 3
    \$\begingroup\$ @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. \$\endgroup\$
    – Jonah
    Jun 10, 2019 at 1:27
  • 3
    \$\begingroup\$ @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. \$\endgroup\$
    – Jonah
    Jun 10, 2019 at 18:04
  • 1
    \$\begingroup\$ Ah, 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. \$\endgroup\$ Jun 11, 2019 at 2:26
  • 4
    \$\begingroup\$ It feels like entries should also show the naive "echo this string" version in their language for comparison, and judging be done on the % shortened? \$\endgroup\$ Jun 11, 2019 at 22:07

59 Answers 59

1
2
2
\$\begingroup\$

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"?

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ Well done! (Fill) \$\endgroup\$
    – Jonah
    Feb 1, 2022 at 18:57
2
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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

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

Try it online!

\$\endgroup\$
3
  • 9
    \$\begingroup\$ This also works in Javascript. \$\endgroup\$ Jun 10, 2019 at 4:19
  • \$\begingroup\$ Polyglot with Foo. \$\endgroup\$ Jun 12, 2019 at 4:29
  • \$\begingroup\$ what other characters are allowed besides '_' ? \$\endgroup\$ Jul 3, 2019 at 13:12
1
\$\begingroup\$

R, 26 bytes

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ ? and PRINT use the same number of BASIC tokens so you are not saving any memory in your stored symbolic listing. \$\endgroup\$ Jul 2, 2019 at 12:09
1
\$\begingroup\$

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

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 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. ;) \$\endgroup\$ Jun 11, 2019 at 13:38
  • \$\begingroup\$ @KevinCruijssen I rolled it back \$\endgroup\$ Jun 11, 2019 at 13:57
1
\$\begingroup\$

><>, 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!

\$\endgroup\$
4
  • \$\begingroup\$ You can remove the skip and it still works, doesn't it? \$\endgroup\$
    – squid
    Jun 11, 2019 at 15:35
  • \$\begingroup\$ @squid Indeed. I originally was using | instead of the arrows. \$\endgroup\$
    – mbomb007
    Jun 11, 2019 at 18:10
  • \$\begingroup\$ If superfluous spaces are allowed, you can shave off one more byte "WN WWS SES EEN N">ooa<. \$\endgroup\$ Jun 18, 2019 at 9:33
  • \$\begingroup\$ @PidgeyUsedGust codegolf.stackexchange.com/questions/186582/… \$\endgroup\$
    – mbomb007
    Jun 18, 2019 at 14:27
1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

k, 23 bytes

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

Keg, 19 bytes

Simply hard-coding the answer.

N NE E SE S SW W NW
\$\endgroup\$
1
\$\begingroup\$

Stax, 16 bytes

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

Run and debug it

\$\endgroup\$
1
\$\begingroup\$

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'

\$\endgroup\$
3
  • \$\begingroup\$ You can save 2 bytes with PRINT'N NE E SE S SW W NW' \$\endgroup\$
    – BradC
    Sep 19, 2019 at 13:50
  • \$\begingroup\$ @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. \$\endgroup\$
    – Jan Drozen
    Sep 19, 2019 at 13:53
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – BradC
    Sep 19, 2019 at 14:43
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
6
  • \$\begingroup\$ This doesn’t appear to be in the correct order \$\endgroup\$
    – Jonah
    May 20, 2021 at 1:49
  • \$\begingroup\$ I thought your comment alluded to relaxing that requirement \$\endgroup\$
    – Zaid
    May 20, 2021 at 1:49
  • \$\begingroup\$ It’s a bit confusing, but read the last two sentences of the comment and it should be clear. \$\endgroup\$
    – Jonah
    May 20, 2021 at 1:52
  • 1
    \$\begingroup\$ The first part of that was referring to a now deleted comment about disallowing snippets \$\endgroup\$
    – Jo King
    May 20, 2021 at 2:48
  • \$\begingroup\$ How is this 14 bytes? \$\endgroup\$
    – emanresu A
    Feb 22, 2022 at 9:11
1
\$\begingroup\$

Thunno 2, 13 bytes

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

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

Screenshot

Screenshot

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
0
0
\$\begingroup\$

Ruby, 22 bytes

p'N NE E SE S SW W NW'

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

Stax, 16 bytes

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

Run and debug it

\$\endgroup\$
0
\$\begingroup\$

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$
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Suggest mov $60,%al \$\endgroup\$
    – ceilingcat
    Jun 19, 2019 at 10:35
  • \$\begingroup\$ lea can save you some $. (e.g. lea 1,%eax) \$\endgroup\$ May 20, 2021 at 19:52
0
\$\begingroup\$

DC, 79 bytes

78sn7Dss69se87swAsblblwlnlblwlblwlslblslblelslblelblelnlblnPPPPPPPPPPPPPPPPPPPP

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

\$\endgroup\$
0
\$\begingroup\$

Underload, 22 bytes

(N NE E SE S SW W NW)S

Pretty self explanatory

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Befunge-93, 45 bytes

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

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Or just hardcode the string \$\endgroup\$
    – Jo King
    Jul 12, 2019 at 9:41
  • 1
    \$\begingroup\$ @JoKing I am aware that this is an option, but I didn't want to just hardcode it \$\endgroup\$
    – ItsJ0el
    Jul 12, 2019 at 11:26
0
\$\begingroup\$

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??

\$\endgroup\$
0
\$\begingroup\$

Red, 25 bytes

prin"N NE E SE S SW W NW"

Try it online!

My first Red answer and first answer this month.

\$\endgroup\$
1
  • \$\begingroup\$ Already beating your python answer ;) \$\endgroup\$
    – Wezl'
    Jun 1, 2021 at 12:56
0
\$\begingroup\$

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
\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.