46
\$\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\$
  • 9
    \$\begingroup\$ Perhaps allowing them to be output in any order would be slightly more interesting \$\endgroup\$ – Jo King Jun 10 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 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 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\$ – Unrelated String Jun 11 at 2:26
  • 3
    \$\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\$ – Dewi Morgan Jun 11 at 22:07

48 Answers 48

1
\$\begingroup\$

PowerShell, 21 bytes

'N NE E SE S SW W NW'

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Same in Swift Playground, with "N NE E SE S SW W NW", if you want. But too trivial to post. \$\endgroup\$ – Cœur Jun 10 at 10:03
  • 4
    \$\begingroup\$ this is code golf. see not trivial in the edit history. \$\endgroup\$ – mazzy Jun 10 at 12:04
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\$
  • \$\begingroup\$ ? and PRINT use the same number of BASIC tokens so you are not saving any memory in your stored symbolic listing. \$\endgroup\$ – Shaun Bebbers Jul 2 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\$
  • \$\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\$ – Kevin Cruijssen Jun 11 at 13:38
  • \$\begingroup\$ @KevinCruijssen I rolled it back \$\endgroup\$ – Benjamin Urquhart Jun 11 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\$
  • \$\begingroup\$ You can remove the skip and it still works, doesn't it? \$\endgroup\$ – squid Jun 11 at 15:35
  • \$\begingroup\$ @squid Indeed. I originally was using | instead of the arrows. \$\endgroup\$ – mbomb007 Jun 11 at 18:10
  • \$\begingroup\$ If superfluous spaces are allowed, you can shave off one more byte "WN WWS SES EEN N">ooa<. \$\endgroup\$ – PidgeyUsedGust Jun 18 at 9:33
  • \$\begingroup\$ @PidgeyUsedGust codegolf.stackexchange.com/questions/186582/… \$\endgroup\$ – mbomb007 Jun 18 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\$
  • \$\begingroup\$ You can save 2 bytes with PRINT'N NE E SE S SW W NW' \$\endgroup\$ – BradC Sep 19 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 at 13:53
  • \$\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 at 14:43
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
\$\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\$
  • 1
    \$\begingroup\$ Suggest mov $60,%al \$\endgroup\$ – ceilingcat Jun 19 at 10:35
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\$
  • \$\begingroup\$ Or just hardcode the string \$\endgroup\$ – Jo King Jul 12 at 9:41
  • \$\begingroup\$ @JoKing I am aware that this is an option, but I didn't want to just hardcode it \$\endgroup\$ – ItsJ0el Jul 12 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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