Tantangan
Masukan yang diberikan dalam bentuk di <n1>, <n2>
mana angka bisa -1, 0, atau 1, kembalikan arah mata angin yang sesuai . Bilangan positif bergerak ke Timur di sumbu x dan Selatan di sumbu y, Angka negatif bergerak ke Barat di sumbu x dan Utara di sumbu y.
Output harus dalam bentuk South East
, North East
, North
. Ini case-sensitive.
Jika inputnya 0, 0, program Anda harus kembali That goes nowhere, silly!
.
Masukan / Keluaran Sampel:
1, 1
-> South East
0, 1
-> South
1, -1
-> North East
0, 0
-> That goes nowhere, silly!
Ini adalah kode-golf , jawaban terpendek dalam byte menang.
code-golf
string
kolmogorov-complexity
Matias K
sumber
sumber
Jawaban:
Japt ,
5551 bytePenjelasan
Cobalah online!
sumber
Python,
10187 byteSolusi yang benar-benar naif.
Terima kasih kepada @Lynn karena telah menghemat 14 byte! Perubahan: Menggunakan metode string.split sebenarnya membuatnya lebih lama; _; Dan juga, indeks negatif ada di python.
sumber
lambda x,y:('','South ','North ')[y]+('','East','West')[x]or'That goes nowhere, silly!'
lambda x,y:'North htuoS'[::x][:6]+'EastseW'[::y][:4]
Edit: sepertinya sekarang akan terlalu lama, tetapi Anda dapat membuat irisan kedua[:6*x**2]
, demikian juga untuk string Timur / Barat, jika Anda dapat menghindari kesalahan pada irisan pertama.lambda x,y:('North ','South ')[y+1]+('West','East')[x+1]or'That goes nowhere, silly!'
lebih pendek 2 byteSouth East
untuk(0, 0)
. Terima kasih!PHP, 101 Bytes
sumber
Perl 6, 79 bytes
Try it
Diperluas:
sumber
JavaScript (ES6),
1061009793 bytesIt's a very simple approach. It consists of a few ternary operators nested together -
Test Cases
sumber
a!=0
can be replaced by justa
, since 0 is falsy and all other values are truthy. Also, taking input in currying syntax is shorter, and the array appoach is also shorter.f=a=>b=>
and calling the function likef(1729)(1458)
; which is thecurrying syntax
that @Luke mentioned.a|b
instead ofa||b
. Assuming that the input only consists of -1, 0 or 1 (which is unclear to me), you could replacea>0
andb>0
with~a
and~b
.a?(...):""
/b?(...):""
Batch, 156 bytes
The
for
loop acts as a lookup table to filter when the (possibly negated) parameter equals -1, and concatenating the matching words. If nothing is selected then the silly message is printed instead.sumber
JavaScript (ES6), 86 bytes
Explanation
Call it with currying syntax (
f(a)(b)
). This uses array indices. If botha
andb
are 0, the result is a falsy empty string. In that case, the string after the||
is returned.Try it
Try all test cases here:
sumber
GNU sed, 100 + 1(r flag) = 101 bytes
By design, sed executes the script as many times as there are input lines, so one can do all the test cases in one run, if needed. The TIO link below does just that.
Try it online!
Explanation:
The remaining pattern space at the end of a cycle is printed implicitly.
sumber
05AB1E,
484543 bytesTry it online!
Explanation
sumber
Jelly, 40 bytes
Try it online!
sumber
Japt, 56 bytes
Try it online! | Test Suite
Explanation:
sumber
00
is exactly the same as0
, as the extra digit gets removed ;)Retina,
848281 bytes1 byte saved thanks to @seshoumara for suggesting
0...?
instead of0\w* ?
Try it online!
sumber
Nor
andSou
)0...?
.Swift 151 bytes
sumber
PHP, 95 bytes.
This simply displays the element of the array, and if there's nothing, just displays the "default" message.
This is meant to run with the
-r
flag, receiving the coordenates as the 1st and 2nd arguments.sumber
C#,
95102 bytesGolfed
Ungolfed
Ungolfed readable
Full code
Releases
+ 7 bytes
- Wrapped snippet into a function.95 bytes
- Initial solution.Notes
I'm a ghost, boo!
sumber
(a,b)=>{...}
bita=>b=>
, might not need the()
around thea|b
, you might be able to use interpolated strings to get the string built up nicer as well()
around thea|b
, I do need it, otherwiseOperator '|' cannot be applied to operands of type 'int' and 'bool'
. I've also tried the interpolated strings, but didn't give much though due to the""
giving me errors.Scala, 107 bytes
Try it online
To use this, declare this as a function and call it:
How it works
sumber
C, 103 bytes
sumber
Java 7, 130 bytes
Explanation:
Test code:
Try it here.
Output:
sumber
CJam, 68 bytes
Try it online! or verify all test cases
Prints one trailing space on
[0 -1]
or[0 1]
(North
orSouth
).Explanation
sumber
Röda, 100 bytes
Try it online!
This is a trivial solution, similar to some other answers.
sumber