Determine the color of a chess square
Python 2, 41 38 bytes
print'ldiagrhkt'[int(input(),35)%2::2]
3 bytes thanks to Mego for string interlacing
Takes input like "g6"
. That's light and dark intertwined.
GS2, 17 15 bytes
de♦dark•light♠5
The source code uses the CP437 encoding. Try it online!
Verification
$ xxd -r -ps <<< 6465046461726b076c696768740635 > chess.gs2
$ wc -c chess.gs2
15 chess.gs2
$ gs2 chess.gs2 <<< b1
light
How it works
d Add the code points of the input characters.
e Compute the sum's parity.
♦ Begin a string literal.
dark
• String separator.
light
♠ End the string literal; push as an array of strings.
5 Select the element that corresponds to the parity.
Hexagony, 34 32 bytes
,},";h;g;;d/;k;-'2{=%<i;\@;trl;a
Unfolded and with annotated execution paths:
Diagram generated with Timwi's amazing HexagonyColorer.
The purple path is the initial path which reads two characters, computes their difference and takes it modulo 2. The <
then acts as a branch, where the dark grey path (result 1
) prints dark
and light grey path (result 0
) prints light
.
As for how I compute the difference and modulo, here is a diagram of the memory grid (with values taken for the input a1
):
Diagram generated with Timwi's even more amazing Esoteric IDE (which has a visual debugger for Hexagony).
The memory pointer starts on the edge labelled row, where we read the character. }
moves to the edge labelled col, where we read the digit. "
moves to the edge labelled diff where -
computes the difference of the two. '
moves to the unlabelled cell where we put the 2
, and {=
moves to the cell labelled mod where we compute the modulo with %
.
This might be golfable by a few bytes by reusing some of the ;
, but I doubt it can be golfed by much, certainly not down to side-length 3.