C#, 95 102 bytes
Golfed
(a,b)=>(a|b)==0?"That goes nowhere, silly!":(b<0?"North ":b>0?"South ":"")+(a<0?"West":a>0?"East":"");
Ungolfed
( a, b ) => ( a | b ) == 0
? "That goes nowhere, silly!"
: ( b < 0 ? "North " : b > 0 ? "South " : "" ) +
( a < 0 ? "West" : a > 0 ? "East" : "" );
Ungolfed readable
// A bitwise OR is perfomed
( a, b ) => ( a | b ) == 0
// If the result is 0, then the 0,0 text is returned
? "That goes nowhere, silly!"
// Otherwise, checks against 'a' and 'b' to decide the cardinal direction.
: ( b < 0 ? "North " : b > 0 ? "South " : "" ) +
( a < 0 ? "West" : a > 0 ? "East" : "" );
Full code
using System;
namespace Namespace {
class Program {
static void Main( string[] args ) {
Func<Int32, Int32, String> f = ( a, b ) =>
( a | b ) == 0
? "That goes nowhere, silly!"
: ( b < 0 ? "North " : b > 0 ? "South " : "" ) +
( a < 0 ? "West" : a > 0 ? "East" : "" );
for( Int32 a = -1; a <= 1; a++ ) {
for( Int32 b = -1; b <= 1; b++ ) {
Console.WriteLine( $"{a}, {b} = {f( a, b )}" );
}
}
Console.ReadLine();
}
}
}
Releases
- v1.1 -
+ 7 bytes
- Wrapped snippet into a function.
- v1.0 -
95 bytes
- Initial solution.
Notes
I'm a ghost, boo!