24
\$\begingroup\$

The 32 points of the compass are:

N, NbE, NNE, NEbN, NE, NEbE, ENE, EbN, E, EbS, ESE, SEbE, SE, SEbS, SSE, SbE, S, SbW, SSW, SWbS, SW, SWbW, WSW, WbS, W, WbN, WNW, NWbW, NW, NWbN, NNW, NbW

(SEbE is pronounced "Southeast by east"...)

Write a program or function that outputs all of these, in any order.

Input

None

Output

Each point of the compass must be output as correctly-cased string of 1-4 characters length, and must be separated from the other points of the compass in some manner (so a single string like 'NNENESE...' is not ok). Other than that, anything goes.

(Outputting letters that are not part of the points of the compass, or outputting points of the compass twice, is not allowed.)

Scoring

Code golf. Standard rules apply.

\$\endgroup\$
10
  • 2
    \$\begingroup\$ Shame the points aren't N, NNNE, NNE, ENNE, NE, NENE, ENE, EENE, E etc. \$\endgroup\$ Commented Apr 30 at 5:52
  • 2
    \$\begingroup\$ Nicola, order is up to you. \$\endgroup\$ Commented Apr 30 at 12:52
  • 1
    \$\begingroup\$ Oh, so that means even not sequential? Thanks, I hadn't realized that. I have also only now noticed that you addressed order in your post. \$\endgroup\$ Commented Apr 30 at 12:53
  • 1
    \$\begingroup\$ @SteveBennett Is a C (132) puts("N,NbE,NNE,NEbN,NE,NEbE,ENE,EbN,E,EbS,ESE,SEbE SE,SebS,SSE,SbE,S,SbW,SSW,SwbS,SW,SwbW,WSW,WbS,W,WbN,WNW,NwbW,NW,NwbN,NNW,NbW"); too trivial? \$\endgroup\$ Commented Apr 30 at 14:48
  • 1
    \$\begingroup\$ @chux Looks like a valid solution to me. Non-triviality is not a requirement. But can you go shorter? \$\endgroup\$ Commented May 1 at 1:31

25 Answers 25

9
\$\begingroup\$

JavaScript (Node.js), 90 bytes

_=>a+a.split`E`.join`W`+'N S' a=`NbE NNE NEbN NE NEbE ENE EbN ` a+=a.split`N`.join`S`+'E ' 

Try it online!

Port of Jan Blumschein's .bat answer

JavaScript (Node.js), 96 bytes

_=>`NE SE NW SW N E S W`.replace(/../g,n=>`0b1 001 01b0 01 01b1 101 1b0`.replace(/\d/g,c=>n[c])) 

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ I'm not sure that new answer is really valid, is it? It's three separate expressions. It only works in TIO with the extra header and footer code. To make it valid, you'd need to add commas and parentheses: (a=NbE NNE NEbN NE NEbE ENE EbN ,a+=a.splitN.joinS+'E ',_=>a+a.splitE.joinW+'N S') (Well, in my understanding of the rules anyway.) \$\endgroup\$ Commented May 2 at 1:10
  • \$\begingroup\$ @SteveBennett For practical programming, a=...;a+=...;f=_=>a+... is used; Here f= can be omitted by rules, so code typically rearranged such that the f= can move to header \$\endgroup\$ Commented May 2 at 2:30
  • \$\begingroup\$ Yeah, each of those things individually is fine, I'm questioning whether you can do both of them. You can omit f= when the expression as a whole returns a function. But in your case, it doesn't. \$\endgroup\$ Commented May 2 at 3:31
6
\$\begingroup\$

Python, 81 bytes

*x,=11*" EWEW" for x[51:51]in"NSSN":print(b'%#{r;r{27#{2sr3r'.hex().translate(x)) 

Attempt This Online!

Python, 86 bytes

*x,=9*"WE bNSEW" for j in b"6464":print(b'CbDbF4$bF6&F&4'.hex().translate(x),x.pop(j)) 

Attempt This Online!

Python, 88 bytes

print(*"NWSE",*[b"CRDRE4$RE5%E%4".hex().translate(26*" b"+x+y)for x in"NS"for y in"EW"]) 

Attempt This Online!

\$\endgroup\$
1
  • \$\begingroup\$ Ew, ew, what a solution... \$\endgroup\$ Commented May 4 at 7:28
5
\$\begingroup\$

x86_64 Machine Code, 64 bytes

Requires a CPU with AVX512VBMI2. Unfortunately, that also means it can't run on any online demos I know of. It is a function that outputs into a buffer whose pointer is passed in rdi, with each compass direction delimited by a newline.

Hexdump:

48 b8 a5 97 a7 96 b1 b2 9b 00 c4 e1 fb 92 c8 b8 00 00 62 0a 48 ba 4e 45 53 45 53 57 4e 57 66 89 d0 62 f2 7d 48 7c c0 62 f2 7d 49 63 07 48 83 c7 1f 48 c1 ea 10 75 e7 c6 47 fe 45 c6 47 df 57 c3 

Disassembled and annotated:

compass: mov rax,0x9bb2b196a797a5 ; call this constant k1 kmovq k1,rax mov eax,0xa620000 ; template = "\0\0b\n" mov rdx,0x574e57534553454e ; directions = "NESENWSW" loop0: mov ax,dx ; template[15:0] = directions[15:0] (e.g. "NEb\n") vpbroadcastd zmm0,eax ; set zmm0 to repeat template (e.g. "NEb\nNEb\nNEb\nNEb\n" ... 16 times total) vpcompressb [rdi]{k1},zmm0 ; each set bit of k1 -> corresponding element from zmm0 stored to buffer contiguously add rdi,31 ; each chunk stored is 31 bytes shr rdx,16 jnz loop0 ; shift directions by 16b and loop until 0 mov byte ptr[rdi-2],'E' ; code outputs N,S twice and E,W no times, fix that mov byte ptr[rdi-33],'W' ret 
\$\endgroup\$
5
\$\begingroup\$

Wolfram Language (Mathematica), 51 bytes

One hard-earned byte saved thanks to infinitezero!

ResourceFunction["CompassPoint"][29E#,32]&~Array~32 

Gotta love a builtin…! This program outputs

{"EbN", "SSE", "SWbW", "NW", "NEbN", "ESE", "SbW", "W", "NbW", "ENE", "SEbS", "SW", "NWbW", "NNE", "EbS", "S", "WbS", "NNW", "NEbE", "SE", "SWbS", "WNW", "NbE", "E", "SbE", "WSW", "NWbN", "NE", "SEbE", "SSW", "WbN", "N"} 

which is every 7th entry from the full list of compass directions, taken cyclically until ending at "N". To explain the code, let's start with the initial 52-byte version

ResourceFunction["CompassPoint"][45#/4,32]&~Array~32 

which outputs the compass directions in the order from the OP except "N" is at the end rather than the beginning. The first 32 in the code tells CompassPoint to use this list of fine-grained outputs (rather than just N/S/E/W say), while the second 32 calls the function 32 times. It doesn't work at TIO because TIO won't load the resources needed for ResourceFunction.

The number 45/4 in the original code is the 360 degrees of a circle divided by the 32 points we want to sample. It can be replaced by any odd multiple of itself—that just permutes the output. infinitezero found that \$29e \approx 78.83\$ is close enough to \$7\times\frac{45}4 = 78.75\$ that the compass directions all still round to the same things, which is how the btye was saved.

\$\endgroup\$
5
  • \$\begingroup\$ @infinitezero When I substitute either E^E# or 9# for 45#/4, the code produces some compass directions more than once and others not at all. Am I misunderstanding the idea? \$\endgroup\$ Commented May 1 at 22:53
  • \$\begingroup\$ is 5e^3 shorter? it's .8 off of 101.25 (also e2^7 is .8 off 348.75) (and 6e^4 is 1.3 off 326.25) for more see seq 11.25 22.5 348.75 | xargs -L1 ries -Nfp -s \$\endgroup\$ Commented May 2 at 2:32
  • 1
    \$\begingroup\$ It's the same length (4 one-character bytes). And it turns out it's not quite close enough to 101.25 to make all the outputs unique; I didn't work it out in the post, but I think the margin of error is 0.175. \$\endgroup\$ Commented May 2 at 2:38
  • 1
    \$\begingroup\$ @GregMartin turns out it is I that misunderstood the Complement function I used to check the result. I now used //Sort and compared manually. 29E does the trick, which is 78.8302 compared to 7*11.25 = 78.75 \$\endgroup\$ Commented May 2 at 5:21
  • 1
    \$\begingroup\$ @infinitezero Love it! Answer edited with your improvement. \$\endgroup\$ Commented May 2 at 6:52
4
\$\begingroup\$

cmd.exe, 84 75 73 bytes

set N=NbE NNE NEbN NE NEbE ENE EbN set N=%N%%N:N=S%E echo %N%%N:E=W%N S 

(Note whitespace: Trailing blank after first and second line, no linefeed after last line, other lines separated by <LF>.)

\$\endgroup\$
5
  • \$\begingroup\$ It seems to me that you could use set S=%N%%N:N=S% and then you can remove the %N%%N:E=W% for an overall saving of 7 bytes. \$\endgroup\$ Commented Apr 30 at 8:55
  • \$\begingroup\$ Good point, thank you! This saves even two more bytes by having to write out only one of E and W. \$\endgroup\$ Commented Apr 30 at 9:13
  • \$\begingroup\$ i just tested it and cmd.exe supports "linux encoding" of newlines by default, so you can save 2 bytes by simply using \n instead of \n\r. \$\endgroup\$ Commented Apr 30 at 9:18
  • \$\begingroup\$ @Themoonisacheese Thank you ‒ so I hope this will work on any platform featuring some variant of cmd.exe... \$\endgroup\$ Commented Apr 30 at 9:38
  • \$\begingroup\$ The consensus around here is that the interpreter makes the language. if there is an interpreter that accepts \n, then you are allowed to take advantage of that fact, even if the answer is not necessarly portable to windows 3.1. You'll sometimes see people abusing the edge-case behaviors of specific C compiler versions for the same reason, and that's also perfectly allowed. \$\endgroup\$ Commented Apr 30 at 9:40
4
\$\begingroup\$

Jelly, 26 bytes

⁾NSp⁾EW;€”b“¢£¦¿ÇŒç./‘ṃⱮẎQ 

A niladic Lik that yields a list of lists of characters.

Try it online! (The result is sorted alphabetically and pretty-printed for ease of comparison.)

How?

⁾NSp⁾EW;€”b“...‘ṃⱮẎQ - Link: no arguments ⁾NS - "NS" ⁾EW - "EW" p - {"NS"} Cartesian product {"EW"} ;€”b - concatenate 'b' to each -> CharacterSets = ["NEb", "NWb", "SEb", "SWb"] “...‘ - code-page indices -> MagicNumbers = [1, 2, 5, 11, 14, 19, 23, 46, 47] Ɱ - map across {CharacterSet in CharacterSets} with: ṃ - {MagicNumbers} base decompress {CharacterSet} Ẏ - tighten Q - deduplicate (since we made two of each cardinal direction) 
\$\endgroup\$
4
\$\begingroup\$

Python, 99 bytes

print(a:="N NbE NNE NEbN NE NEbE ENE EbN W WbN WNW NWbW NW NWbN NNW NbW",a.translate('bS.E .W'*40)) 

Attempt This Online!

\$\endgroup\$
4
\$\begingroup\$

brainfuck, 209 bytes (196 without newlines)

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

Try it online!

Developed at https://minond.xyz/brainfuck/ which doesn't like use of cells with negative index (hence an additional >>>>> would be needed at the start of the program.) TIO.run accepts negative cells so this is not required. Newlines are not essential and are added for clarity.

Commented code

To minimise the use of negative indices, this commented code assumes the pointer starts at cell 4. ! is used to represent newline.

->>--->>->>>>->>>>- Initialize cells 4;8;12;16 to 255 Subtract 3 from cell 6 (this will help adjust the cell to E) [[---<+<+<+>>>]<--<++<+++<] Reduce cell 16 to 0 setting the 3 cells to the left to 255/3=85: modify to ASCII XWS: shift 4 left and repeat until empty cell 0 reached. <+++++[-> Set cell -1 to 5 and loop 5 times adjusting cells 1 to 16 >++>--->->++>++>--->>++ Adjust cells 1..8 to bHN!bES! >++>>->++>++>>>++[<]<]> Adjust cells 9..16 to bWN!bWS! (return pointer to -1 at the end of each iteration using the 0 in cell 0) >>---.>>.<.>.< Adjust cell 2 from H to E and output E!N! [.<<.>.>>. Loop 4 times outputting NbE! <..<.>>. NNE! <.<.<.>>.>. NEbN! <.<.>>. NE! <.<.<.>.>>. NEbE! <<.>.<.>>. ENE! <<.<.>>.>.>>>] EbN! etc; advancing 4 cells each iteration <<<<.>.<<. Output S!W 

tinyBF, 281 characters (70.25 bytes when compressed)

+>>=+++=>>+>>>>+>>>>+||+++=>=+=>=+=>=+>>>=|>++>=++=>=+++=>|>+++++=|+>>++>=+++=>=+=>++>++>=+++=>>++>++>>=+=>++>++>>>++|=>|>|=>>>=+++===>>===>===>===>=|===>>===>==>>===>====>===>>===>==>==>===>>==>===>==>===>>===>==>==>===>==>>===>>===>===>===>>===>>==>===>>==>==>>>=|>>>>===>===>>== 

Try it online!

A cross-compile of the above answer (the signs of some counters were changed to reduce the length of the TinyBF code.)

TinyBF is an encoding of Brainfuck using only 4 symbols (this allows 4 symbols to fit in a byte.) The encoding is as below:

 Tiny BF Brianfuck = switch between the symbols below + + or - > > or < | ] or [ == . (switching twice does nothing, so is used as output symbol) |=| , (Brainfuck infinite loop [] is used as input symbol) 
\$\endgroup\$
4
  • \$\begingroup\$ That's impressively short. \$\endgroup\$ Commented May 2 at 1:28
  • \$\begingroup\$ @SteveBennett Thanks, an upvote would be appreciated LOL. Nice challenge BTW. There are no conditionals (only loops) required so with a bit of thought Brainfuck does quite well. \$\endgroup\$ Commented May 2 at 6:41
  • \$\begingroup\$ Done :) Yeah, just amazing that it's barely twice as long as a competitive JavaScript solution. \$\endgroup\$ Commented May 2 at 6:43
  • \$\begingroup\$ @SteveBennett Conversion to TinyBF yields 70.25 bytes when compressed, which beats my rather mediocre Ruby answer and all other mainstream language answers so far. It can't touch the golfing languages, machine code or Wolfram though. \$\endgroup\$ Commented May 3 at 3:36
3
\$\begingroup\$

Charcoal, 29 bytes

⪫NEWSψFEWFNS⍘⍘F@=RdCaFeγ⟦bικ 

Try it online! Link is to verbose version of code. Explanation:

⪫NEWSψ 

Output the four cardinals spaced out.

FEWFNS 

Loop over the four pairs of cardinals.

⍘⍘F@=RdCaFeγ⟦bικ 

Decode the string RdCaFeγ as base 95 using printable ASCII as a custom character set, then encode as base 4 using a custom character set of b = 0, E/W = 1, N/S = 2 and space = 3. This outputs all of the intermediate compass points between the two cardinals.

\$\endgroup\$
3
\$\begingroup\$

Python, 107 bytes

a="N|NbE|NNE|NEbN|NE|NEbE|ENE|EbN|E|EbS|ESE|SEbE|SE|SEbS|SSE|SbE|" print(a+a.translate("W"*70+"S"*9+"N"*5)) 

Attempt This Online!


Just 26 bytes shorter than a raw literal print. I'm sure there are better Python approaches, but I'll leave an initial one here.


@Lucenaposition improved on this significantly in their own answer

\$\endgroup\$
1
  • 2
    \$\begingroup\$ 99 bytes \$\endgroup\$ Commented Apr 30 at 22:51
3
\$\begingroup\$

05AB1E, 32 27 bytes

•Rв₄DŠ`•48в„NS„EWâ'bìδÅвJ˜ê 

-5 bytes porting @JonathanAllan's approach in his Jelly answer, using both \$1\$ (binary 1) and \$2\$ (binary 10) for the single-character compass-directions with an uniquify at the end

Try it online.

Explanation:

•Rв₄DŠ`• # Push compressed integer 29417449383887 48в # Convert it to base-48 as list: [1,2,5,11,14,19,23,46,47] „NS # Push "NS" „EW # Push "EW" â # Cartesian product of the two: ["NE","NW","SE","SW"] 'bì '# Prepend "b" before each: ["bNE","bNW","bSE","bSW"] δ # Apply double-vectorized over both lists: Åв # Convert the integers to a base-string list, # aka, convert it to a base-length list, and index into the string J # Join each inner character-list to a string ˜ # Flatten this list of lists of strings ê # Uniquify (and sort) these strings # (after which the result is output implicitly) 

See this 05AB1E tip of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •Rв₄DŠ`• is 29417449383887 and •Rв₄DŠ`•48в is [1,2,5,11,14,19,23,46,47].

\$\endgroup\$
3
\$\begingroup\$

Python 3, 98 bytes 91 bytes

-7 thanks to xnor

print(*'NEWS',*['b b b    b'.translate([n,o]*4)for o in'NS'for n in'EW']) 

91 Byte Try it online!

print(['N E W S']+['b b b    b'.translate({7:o,6:n})for o in 'NS'for n in 'EW']) 

98 Byte Try it online!

This uses the template string XbY YbX XYbX XY XXY YXY XYbY to generate most of the output and appends N E W S separate because I could not find a way to include them cleanly in the template. It uses unprintable chars BEL (0x07) and ACK (0x06) in place of X and Y in order to save two one bytes in making the translation table (as X and Y are 88 and 89, which are two digits each) by not requiring a table length greater than 18.

The output is now a cleanly printed space separated string of directions. The second asterisk may not be strictly necessary in terms of 'anything goes' separating each direction, but it makes the output a lot nicer.


The output is a list of space delimited strings (['N E W S', 'NbE EbN NEbN NE NNE ENE NEbE', 'NbW WbN NWbN NW NNW WNW NWbW', 'SbE EbS SEbS SE SSE ESE SEbE', 'SbW WbS SWbS SW SSW WSW SWbW']), taking full advantage of the 'just separate the directions somehow, anything goes' policy.

If I really wanted to, I could drop the square brackets around the 'N E W S' and change the plus to a comma, saving two bytes and making the output even uglier...

Additionally, the current old version of the logic can run standalone in the REPL without the print, making it a 91 byte one-liner there.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Nice answer! You can tuple unpack and cut spaces before quotes: Try it online! \$\endgroup\$ Commented May 2 at 2:44
  • \$\begingroup\$ translate can take a list argument [n,o]*4 \$\endgroup\$ Commented May 2 at 2:49
3
\$\begingroup\$

Python, 91 89 87 bytes

b="NE NNE ENE NbE NEbE EbN NEbN ";b+=b.replace(*"EW");print(*"NESW",b+b.replace(*"NS")) 

Attempt This Online!

As the order does not matter, simple replacement is shorter than the string.translate() trick.

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

Perl 5, 74 bytes

say'N S E W ',$_="NbE NNE NEbN NE NEbE ENE EbN ",y/N/S/r,y/E/W/r,y/NE/SW/r 

Try it online!

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

Retina 0.8.2, 76 bytes

 NbE,NNE,NEbN,NE,NEbE,ENE,EbN ^ N,$'¶E, ^ $'¶ T`N`S`¶.+¶.+ T`\E`W`.+¶.+$ S`, 

Try it online! Explanation:

 NbE,NNE,NEbN,NE,NEbE,ENE,EbN 

Insert the intermediate points between N and E.

^ N,$'¶E, 

Duplicate this list, but prefix N to the first copy and E to the second.

^ $'¶ 

Duplicate both lists.

T`N`S`¶.+¶.+ 

Change N to S in the middle two copies.

T`\E`W`.+¶.+$ 

Change E to W in the bottom two copies.

S`, 

Split each point onto its own line.

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

C++, 162 bytes

#include<cstdio> int main(){puts("N NbE NNE NEbN NE NEbE ENE EbN E EbS ESE SEbE SE SEbS SSE SbE S SbW SSW SWbS SW SWbW WSW WbS W WbN WNW NWbW NW NWbN NNW NbW")}; 
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to CGCC! 150 bytes \$\endgroup\$ Commented Jun 17 at 23:11
2
\$\begingroup\$

Vyxal 3, 51 bytes

"ᛞA _.⧖dᏐ①%g4xT≠a∧⟒Aξƶ▲⅟xZ⎊↯ƓṪ∩tᐕ8⎂⩔⎇j⟒▦½“"WN bES"⊢ 

-18 bytes by using a better compression technique

Vyxal It Online!

"ᛞA _.⧖dᏐ①%g4xT≠a∧⟒Aξƶ▲⅟xZ⎊↯ƓṪ∩tᐕ8⎂⩔⎇j⟒▦½“"WN bES"⊢­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‎⁢⁠⁡‏⁠‎⁢⁠⁢‏⁠‎⁢⁠⁣‏⁠‎⁢⁠⁤‏⁠‎⁢⁠⁢⁡‏⁠‎⁢⁠⁢⁢‏⁠‎⁢⁠⁢⁣‏⁠‎⁢⁠⁢⁤‏⁠‎⁢⁠⁣⁡‏⁠‎⁢⁠⁣⁢‏⁠‎⁢⁠⁣⁣‏⁠‎⁢⁠⁣⁤‏⁠‎⁢⁠⁤⁡‏⁠‎⁢⁠⁤⁢‏⁠‎⁢⁠⁤⁣‏⁠‎⁢⁠⁤⁤‏⁠‎⁢⁠⁢⁡⁡‏⁠‎⁢⁠⁢⁡⁢‏⁠‎⁢⁠⁢⁡⁣‏⁠‎⁢⁠⁢⁡⁤‏⁠‎⁢⁠⁢⁢⁡‏⁠‎⁢⁠⁢⁢⁢‏⁠‎⁢⁠⁢⁢⁣‏⁠‎⁢⁠⁢⁢⁤‏⁠‎⁢⁠⁢⁣⁡‏⁠‎⁢⁠⁢⁣⁢‏⁠‎⁢⁠⁢⁣⁣‏⁠‎⁢⁠⁢⁣⁤‏⁠‎⁢⁠⁢⁤⁡‏⁠‎⁢⁠⁢⁤⁢‏⁠‎⁢⁠⁢⁤⁣‏⁠‎⁢⁠⁢⁤⁤‏⁠‎⁢⁠⁣⁡⁡‏⁠‎⁢⁠⁣⁡⁢‏⁠‎⁢⁠⁣⁡⁣‏⁠‎⁢⁠⁣⁡⁤‏⁠‎⁢⁠⁣⁢⁡‏⁠‎⁢⁠⁣⁢⁢‏‏​⁡⁠⁡‌⁢​‎‎⁢⁠⁣⁤⁣‏‏​⁡⁠⁡‌⁣​‎‎⁢⁠⁣⁢⁣‏⁠‎⁢⁠⁣⁢⁤‏⁠‎⁢⁠⁣⁣⁡‏⁠‎⁢⁠⁣⁣⁢‏⁠‎⁢⁠⁣⁣⁣‏⁠‎⁢⁠⁣⁣⁤‏⁠‎⁢⁠⁣⁤⁡‏⁠‎⁢⁠⁣⁤⁢‏‏​⁡⁠⁡‌­ "ᛞA # ‎⁡compressed integer 118527397431132348315259064471309367980399198767544169918914239830184073459407054382133548256390 _.⧖dᏐ①%g4xT≠a∧⟒Aξƶ▲⅟xZ⎊↯ƓṪ∩tᐕ8⎂⩔⎇j⟒▦½“ ⊢ # ‎⁢converted to base "WN bES" # ‎⁣literal string "WN bES" 💎 

Created with the help of Luminespire.

<script type="vyxal3"> "ᛞA _.⧖dᏐ①%g4xT≠a∧⟒Aξƶ▲⅟xZ⎊↯ƓṪ∩tᐕ8⎂⩔⎇j⟒▦½“"WN bES"⊢ </script> <script> args=[] </script> <script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>

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

Ruby, 76 bytes

p %w{S N NE AEW}.map{|i|'NbE,NNE,NEbN,NE,NEbE,ENE,EbN,'.tr(i,"SW")+i[-1]}*?, 

Try it online!

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

JavaScript (Node.js), 90 bytes

(x='NbE NNE NEbN NE NEbE ENE EbN ',y=x+x.split`N`.join`S`)=>y+y.split`E`.join`W`+'N E S W' 

Try it online!

JavaScript (Node.js), 92 bytes

(x='NbE NNE NEbN NE NEbE ENE EbN ',y=x+x.replace(/N/g,'S'))=>y+y.replace(/E/g,'W')+'N E S W' 

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Thanks @l4m2 for the split/join idea. \$\endgroup\$ Commented May 2 at 1:12
1
\$\begingroup\$

Plain TeX, 85 bytes

N S E W\def~#1#2{ #1b#2 #1#1#2 #1#2b#1 #1#2 #1#2b#2 #2#1#2 #2b#1}~N E~N W~S E~S W\bye 

Example

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

Python, 95 bytes

b='b' print(*'NESW') for z in'NE','SE','SW','NW':x,y=z;print(z,z+b+x,z+b+y,x+z,y+z,x+b+y,y+b+x) 

Attempt This Online!

Output:

N E S W NE NEbN NEbE NNE ENE NbE EbN SE SEbS SEbE SSE ESE SbE EbS SW SWbS SWbW SSW WSW SbW WbS NW NWbN NWbW NNW WNW NbW WbN 
\$\endgroup\$
0
\$\begingroup\$

C# 12 - 197 bytes

f=()=>{List<string>v=["N","S"],h=["E","W"];var o="";for(int i=0;i<2;i++){o+=$"{v[i]},{h[i]},";for(int j=0;j<2;j++)o+=$"cbn,ccn,cnbc,cn,cnbn,ncn,nbc,".Replace("c",v[i]).Replace("n",h[j]);}return o;} 

Ungolfed:

f = () => { List<string> v = ["N", "S"], h = ["E", "W"]; var o = ""; for (int i = 0; i < 2; i++) { o += $"{v[i]},{h[i]},"; for (int j = 0; j < 2; j++) o += $"cbn,ccn,cnbc,cn,cnbn,ncn,nbc,".Replace("c", v[i]).Replace("n", h[j]); } return o; } ``` 
\$\endgroup\$
1
  • 4
    \$\begingroup\$ Good luck with improving your entry! Currently, I'm sorry to point out that returning the raw literal solution directly would beat your solution (it requires just 133 bytes) \$\endgroup\$ Commented Apr 30 at 10:25
0
\$\begingroup\$

cQuents, 85 bytes

#32&b@N;@W;k,b@N;@E;k+1,b@S;@E;k,b@S;@W;k+1 :A,A~@b~B,B~@b~A,A~Z,A~B,A~Z,B~Y,X~@b~B,B 

Try it online!

Have some other ideas, but they're starting to get pretty wacky so I'll call it a night here :D

Output:

N,NbE,S,SbW,NbW,EbN,SbE,WbS,WbN,NEbN,EbS,SWbS,NWbN,NE,SEbS,SW,NW,NNE,SE,SSW,NNW,ENE,SSE,WSW,WNW,NEbE,ESE,SWbW,NWbW,E,SEbE,W 

Verify output: Try it online!

Explanation

I tried a few patterns, but the pattern I ended up with was:

X, XbY, YbX, XYbX, XY, XXY, YXY, XYbY, Y 

This can be repeated 4 times to generate all 32 points. However, the X term must always be the N/S side of the compass. Additionally, it will over-generate the cardinal directions, so I have to ensure I pull X from the front twice, and Y from the back twice, to correctly generate N/S/E/W all once.

The order is also relevant - string literals are a bit expensive in cQuents, so YbX and XY are positioned so that the follow-up terms can back-reference instead of building the term from scratch.

Mapped to the corresponding X,Y pairs 4 times, this pattern leads to:

N, NbE, NNE, NEbN, NE, NEbE, ENE, EbN, E N, NbW, NNW, NWbN, NW, NWbW, WNW, WbN, W S, SbW, SSW, SWbS, SW, SWbW, WSW, WbS, W S, SbE, SSE, SEbS, SE, SEbE, ESE, EbS, E 

Below is the code explanation. The second line implements the pattern above. The first line is the main sequence, which will have 32 terms. For every k = 1 to 8, it will call the second line (the X/Y pattern) for each set of cardinal X/Y pairs (N,W, N,E, S,E, S,W), but for the second and fourth pairs, it offsets the k by 1, to get the other cardinal direction.

#32&b@N;@W;k,b@N;@E;k+1,b@S;@E;k,b@S;@W;k+1 line 1 #32 n = 32, k = 1 & , , , mode sequence 2 - given input n, output first n terms b ; ; next term = line 2 ( , , ) @N "N" @W "W" k k b@N;@E;k+1 next term = line 2 ( "N" , "E" , k+1 ) b@S;@E;k next term = line 2 ( "S" , "E" , k ) b@S;@W;k+1 next term = line 2 ( "S" , "W" , k+1 ) reset to first term, k += 1 :A,A~@b~B,B~@b~A,A~Z,A~B,A~Z,B~Y,X~@b~B,B line 2 : , , , , , , , , mode sequence 1 - given input n, output nth term inputs = A, B, n A next term = first input A next term = first input ~ concat @b "b" ~ concat B second input B~@b~A next term = second input concat "b" concat first input A~Z next term = first input concat previous term A~B next term = first input concat second input A~Z next term = first input concat previous term B~Y next term = second input concat 2 terms previous X~@b~B next term = 3 terms previous concat "b" concat second input B next term = second input 

100 bytes

#32&b@W;@N;'NW';k,b@N;@E;'NE';k,b@E;@S;'SE';k,b@S;@W;'SW';k :A,B~C,A~C,A~@b~B,C,C~@b~A,C~@b~B,B~@b~A 

Try it online!

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

C, 132 [bytes]

puts("N,NbE,NNE,NEbN,NE,NEbE,ENE,EbN,E,EbS,ESE,SEbE SE,SEbS,SSE,SbE,S,SbW,SSW,SWbS,SW,SWbW,WSW,WbS,W,WbN,WNW,NWbW,NW,NWbN,NNW,NbW"); 

A trivial starting point.

Now to consider a better algorithmic one...

\$\endgroup\$
-2
\$\begingroup\$
print("\n".join(["N","NbE","NNE","NEbN","NE","NEbE","ENE","EbN","E","EbS","ESE","SEbE","SE","SEbS","SSE","SbE","S","SbW","SSW","SWbS","SW","SWbW","WSW","WbS","W","WbN","WNW","NWbW","NW","NWbN","NNW","NbW"])) 
\$\endgroup\$
4
  • 3
    \$\begingroup\$ You should include the name of the language and the byte count at the top of your submission. \$\endgroup\$ Commented Apr 30 at 12:41
  • 3
    \$\begingroup\$ A plain print("N NbE NNE NEbN NE NEbE ENE EbN E EbS ESE SEbE SE SEbS SSE SbE S SbW SSW SWbS SW SWbW WSW WbS W WbN WNW NWbW NW NWbN NNW NbW") would be shorter... \$\endgroup\$ Commented Apr 30 at 13:00
  • 4
    \$\begingroup\$ Welcome to the site. It seems your answer has been downvoted at least in part due to formatting, which I think is a little unfair. If you paste your code into TIO.run or Attempt This Online (you need to pick the language) you can get your answer autoformatted and provide a demonstration. You can see that other answers have done this. \$\endgroup\$ Commented Apr 30 at 15:39
  • \$\begingroup\$ I assume this is JavaScript (though see my thoughts on print() in JavaScript). \$\endgroup\$ Commented May 1 at 5:54

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.