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.
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.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.Jawaban:
Canvas, 12 bytes
Try it here!
The string, simply compressed.
sumber
"NESW "
) and then in base-5 stores the individual characters.bash (24 bytes)
using brace expansion
is the same length as hard coding
however it becomes more interesting when outputing more points of the compass
brace expansion
otherwise if order could be changed, (17 bytes), the trick is that without quotes the empy string parameter disappears
sumber
mount -t proc{,,}
cp file{,.bak}
Mornington Crescent,
43953823 bytesTry 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, constructfrom 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:
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.
sumber
Ne
asden,Sw
iss Cottage, Acton Town
and Mansion House
) 2. Try to exploit the fact that Paddington makes it easier to concatenate ` W ` rather thanW
. This does require some more overhead to 'refresh' Paddington, so it may not gain anything.PHP, 19 bytes
Try it online!
Getting this out of the way. Someone will do it eventually.
sumber
brainfuck,
142139131119 bytesTry 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!".
sumber
Brain-Flak, 204 bytes
Try it online!
sumber
MarioLANG,
249221 bytesTry it online!
sumber
Deadfish~,
188183 bytes-5 thanks to squid
Try it online!
sumber
{i}dc
at the end for 183Excel Formula,
5957 bytesThe following should be entered as an array formula (Ctrl+Shift+Enter):
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
andcol
. 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 columnN
, Column 369 is columnNE
.However, we are not finished here since all the returned references have the row included, for example,
N1
,NE1
. Therefore, we simply useSUBSTITUTE
to remove the1
from all references.sumber
=IF(1,"N NE E SE S SW W NW")
be valid?Triangularity, 71 bytes
Try it online!
There are two spaces on the last line to hit the byte count Triangularity requires.
sumber
Charcoal, 14 bytes
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:
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 indices4,0,6,2
.sumber
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.
sumber
Python 2,
62615853 bytesTry it online!
Not great, but at least not a plain print..
sumber
Jelly,
1615 bytesA 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ỵÑ’ṃ“¡⁴ṁ»
.sumber
Commodore BASIC (TheC64Mini, C64, C128, VIC-20 etc.) 28 Tokenized BASIC bytes used
In Commodore BASIC, you do not require the closing quotation mark on
PRINT
orLET
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)I'm not sure how to count the number of bytes used in this instance as according to the interpreter
?
andPRINT
use the same number of bytes, and there is no program stored in memory.sumber
PRINT
can be replaced with?
as well, saving four bytes.PRINT
and?
use the same amount of BASIC tokens. I'm not counting PETSCII characters as it's not very representative of how much of the available memory is being used by the interpreter.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.Try it - footer formats the output.
sumber
Deadfish~, 138 bytes
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!):
sumber
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 sothis code only throws an error but does not exit due to it.Output
Batch File, 25 bytes
Only
N NE E SE S SW W NW
output with no errors or crashes.sumber
'N NE E SE S SW W NW'
- you'll get something like:N NE E SE S SW W NW - command not found
Python2, 59 bytes
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):
sumber
K (ngn/k),
2322 bytes-1 byte thanks to ngn!
Try it online!
J,
3430 bytesTry it online!
sumber
" "
<->"W"
(0
<->4
in base 5), the space will be at the end and we can remove it because out-of-bounds string indexing gives a space anyway:"WNES"@5\7108085518230
05AB1E, 14 bytes
Try it online!
This prints out the string except lowercase.
sumber
•
for -1Brachylog, 19 bytes
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...I tried to be clever with
3⟦{;"NESW"↺₍h₂a₀ᶠ}ᵐc
, but it couldn't get SE or NW right, and is a byte longer anyhow.sumber
Whitespace, 151 bytes
Letters
S
(space),T
(tab), andN
(new-line) added as highlighting only.[..._some_action]
added as explanation only.Try it online (with raw spaces, tabs, and new-lines only).
Explanation:
The constant
84
is generated by this Java program which I wrote for another challenge I answered in Whitespace.sumber
MathGolf,
2017 bytes-3 bytes thanks to @maxb.
Try it online.
Explanation:
sumber
É
andÄ
in this case) still confuse me a bit sometimes.. Sometimes I'm not sure when I do or don't have to use those code-blocks. Yourm+
doesn't use one for example. But yourÄ
is a code-block of size 1. I triedmÅî╪
just yet to see what happened, which is why I now understand why there is a code-block of size 1Ä
to begin with. :) ) Thanks for the -3 bytes, though. Still a lot to learn I see.{}
.mÅî╪
creates the mapping, but it doesn't have a for-loop inside the mapping. If you writem{î{╪}}
, it is perhaps easier to see that the code is "map to: loop <index> times, and rotate the string each loop". The reason whym+
does not have one is that certain commands have implicit 1-byte blocks (map, filter, reduce, etc), butî
is not a command meant to be used in combination with a block.{...}
, but I kinda forgotinteger{
is a for-loop. :) Now theîÄ╪
makes a lot more sense. Thanks for the explanation!CSS,
4239 bytes(thanks to a stone arachnid for the revised version)
sumber
body:after{content:"N NE E SE S SW W NW"
Seed, 6014 bytes
Generates following befunge program:
sumber
Hodor, 177 bytes
Try it online!
sumber
Assembly (x86, Linux), 68 bytes
Source:
Code mostly taken from Shortest ELF for "Hello world\n"?
sumber
Jelly, 16 bytes
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.
sumber
C# (Visual C# Interactive Compiler), 24 bytes
Try it online!
sumber