28 Answers
28

Pyth, 22 21 bytes

-1 byte by @Sp3000

fn%Chz3%sCMT2sM*<G8S8

Under the function %Chz3, dark hashes to 1, light to 0, and both to 2. If we take the parity of the sum of the ords of a chess square (that is, a1 -> [97, 33] -> (97 + 33)%2 = 0, dark squares go to 0, and light to 1. This allows us to filter by inequality.

fn%Chz3%sCMT2sM*<G8S8 implicit: z=input
* Cartesian product of
<G8 first 8 letters in G (alphabet)
S8 with [1,...,8] implicitly stringified
sM*<G8S8 ['a1','a2,...,'a8','b1'...'h8']
f T Filter that by gives truthy result to lambda T:
sCMT The sum of the ords of the chars in T,
% 2 modulo 2
n does not equal
Chz ord of the first char in z,
% 3 modulo 3
Implicitly print the list.

Bash + GNU Utilities, 74

{a..h}{1..9} is a bash brace expansion that produces all the coordinates for an 8x8 board, plus an extra column 9. This is important because it makes the row length odd which allows the chequerboard effect.

The printf simply formats each coordinate, one per line.

The built sed expression then deletes all x9 coordinates and then prints either even or odd or both input lines, according to the script input.

Pyth, 48 39 bytes

Still longer than the other Pyth solution, but I don't think I can beat this with my algorithm.

Explanation

First we generate a list of all squares on the board and assign it to Y. Then we filter this list so that only light squares remain and assign this list to J. After that we evaluate the input and print:

Y if input was both

J if input was light

Y-J if the input was dark

Determining if a square is light works as follows:

Map the char to a number from 1-8 (a->1, b->2), results in 18 for a8, etc.

\$\begingroup\$Welcome to PPCG! This is a good answer, but you'll get more votes if you add an explanation.\$\endgroup\$
– lirtosiastFeb 16 '16 at 20:47

\$\begingroup\$I think you can replace$s==2 with $s-1. If $s=2, and -1, it's 1, which is truthy and will continiue\$\endgroup\$
– MartijnFeb 17 '16 at 8:12

\$\begingroup\$And I think $c=0 can be $c, it'll give a bunch of notices, but at least for dark it works fine\$\endgroup\$
– MartijnFeb 17 '16 at 8:42

\$\begingroup\$Thank you, Martijn! I forgot to remove the braces too, -6 bytes for now. And I don't know why, but $s-1 doesn't work, but it should. Thanks for this great idea! I'll debug that later.\$\endgroup\$
– killerbees19Feb 17 '16 at 11:23

\$\begingroup\$I'm new to this site, but error messages because of undefined $c variable? That sounds a bit strange and invalid. Or not?\$\endgroup\$
– killerbees19Feb 17 '16 at 11:26

'`'8\[1+8\:]Yy1-\?8\['1'v8\[vD1+vr?]vX]i'h'-)[88*\[Z?aO]]i'r'-)[?1m]i'g'-)[1m]
'`' Push ` to the stack. (this is 1 less than a in ASCII)
8\[ ] Do the stuff in brackets 8 times.
1+ Add one on every recursion (this gets a, b, c, d...)
8\: Clone the stack 8 times. (This gets 8 of each a, b, c...)
Y Remove the current stack.
y1-\? Go one stack to the left (I really need to builtin this)
8\[ ] Do the stuff in brackets 8 times.
'1' Push character literal 1 to the stack.
v Save it as a temporary variable.
8\[ ] Do the stuff in brackets 8 times.
v Push the temporary variable to the stack.
D Duplicate the top item of the stack.
1+ Add one to it (this gives us 1, 2, 3, 4...)
v Capture the top item of the stack as a temporary variable.
r Reverse the stack.
? Go a stack to the right.
vX Clear the temporary variable slot.
i'h')[ ] If the last character of the input is 'h', do the stuff in brackets
88*\[ ] Do the stuff in brackets 64 times.
Z Output everything in the stack as a character.
? Rotate right a stack.
aO Output a newline.
i'r')[?1m] If the penultimate character of the input is 'r', rotate over a
stack, then execute the first index of lines of code.
1m Execute the first index of lines of code.

Explanation of the second line:

84*\[Z??aO]
84*\[ ] Do the stuff in brackets 32 times.
Z Output everything in the stack as a char.
?? Rotate two stacks over.
aO Output a newline.

There will be bonus trailing newlines for 'dark' and 'both'. Requires that only 'dark', 'both', or 'light' will be input.

PowerShell v3+, 142 129 bytes

Takes input $a and sets two variables for if we're to output $dark or $light squares based on the first letter of the input.

Then, we loop over a-h and 1-8 and uses the same trick as on Determine the color of a chess square to parse whether it's a light or dark square (setting helper variable $q in the first test) and add that square to the pipeline if appropriate. After execution, the elements on the pipeline are output one per line.

Requires v3 or newer for the -in operator.

Edit - Saved 13 bytes by eliminating the switch and by changing equality testing order

\$\begingroup\$I don't think the n-loop is necessary. I think nested for loops for i and j would trim a few bytes off. The (i+j)%2 approach is really clever. I hadn't thought of that.\$\endgroup\$
– W.K.SFeb 17 '16 at 7:48

\$\begingroup\$I just notice that (i//8+i%8)%2 is the same as (i//8+i)%2 so you can win some bytes if you remove the definition of j=n%8\$\endgroup\$
– ErwanFeb 17 '16 at 9:03

Therefore, $x modulo 9 yields the column number and $x / 9 yields the row number, which I convert to a letter using chr. The code $z<c|$z>k^$x&1 yields true for input both ($z<c) and in the case of light or dark only for the even or odd cells respectively ($z>k ^ $x&1). The result of this expression determines whether or not the cell coordinates will then be printed. Finally, if $x modulo 9 results in 0, I skip that non-existant cell.

Saved 18 17 bytes (fixed a bug) by having only 1 loop, converting the number to a char instead of the other way around

Saved 3 bytes by combining the condition for dark and light with a xor

Saved 3 bytes by comparing against the full input instead of the first char

Saved 2 bytes because no longer need to subtract .125 in the expression $x/9+69.9 to get the correct row number before converting to a char

Oracle SQL 11.2, 192 180 bytes

WITH v AS
(
SELECT CEIL(LEVEL/8)x, DECODE(MOD(LEVEL,8),0,8,MOD(LEVEL,8))y
FROM DUAL CONNECT BY LEVEL<=64
)
SELECT CHR(64+x),y
FROM v
WHERE (:1='dark' AND MOD(x+y,2)=0)OR(:1='light' AND MOD(x+y,2)=1)OR(:1='both');

The v view generate the coordinates of each square. If the sum of the coordinates is even then the square is black, else it's white.

\$\begingroup\$This one doesn't seem to give the correct squares. "dark" is giving x1,x3,x5,x7 for every letter x, but that corresponds to 4 columns, not the black squares.\$\endgroup\$
– EsteematorFeb 17 '16 at 14:10

CJam, 29

q read the input
ci convert to (first) character then to integer
3% modulo 3; results for d(ark), l(ight) and b(oth) are 1, 0, 2
:X; store in X and pop
8Ym* generate all pairs (Y=2) of numbers from 0 to 7
{…}, filter using the condition block
~ dump the current pair on the stack
+2% calculate the sum modulo 2
X- subtract X; if the result is not 0, the pair is kept
"a1 "f.+ vectorized-add "a1 " to each remaining pair
this means the character 'a' is added to the first number,
the character '1' is added to the second number,
and then the space character is appended
the contents of the stack are automatically printed at the end

\$\begingroup\$How about c>0 for c==1 and c<1 for c==0? Saves two bytes.\$\endgroup\$
– Michael KleinFeb 19 '16 at 6:39

\$\begingroup\$Fantastic, we got it under 100! Thank you Michael.\$\endgroup\$
– joeytwiddleFeb 19 '16 at 6:48

1

\$\begingroup\$You're welcome. I got a bit sucked in and got it down to 86 bytes by refactoring a bit: f r=[[[a,b]|a<-['a'..'h'],b<-['1'..'8']]!!i|i<-[0..63],even i||r<"l",odd i||r!!0/='d']\$\endgroup\$
– Michael KleinFeb 19 '16 at 7:21

1

\$\begingroup\$That's very nice, a rethought approach. Although I'm sorry to say that odd and even i do not give us diagonal stripes. Some solve this with i+i`div`8 (like x+y). Others start with ['1'..'9'] and [0..71] and then retain only the i`mod`9<8 results later, for 96 bytes. However, this hybrid of our two approaches does well at 91 bytes: l=[0..7];f r=[["abcdefgh"!!x,"12345678"!!y]|x<-l,y<-l,odd(x+y)||r<"l",even(x+y)||r!!0/='d']\$\endgroup\$
– joeytwiddleFeb 19 '16 at 9:28

\$\begingroup\$Ah, well that's still a good bit better\$\endgroup\$
– Michael KleinFeb 19 '16 at 9:54

If a == 1, then a square will always be black if the "oddness" of row and column is the same, i.e. both are odd or both are even. The opposite is true for white squares, where row and column will always differ in oddness.

After that, it's just a matter of combining row and column loops, as well as consulting a table of operator precedence until a sufficient level of incomprehensibility has been reached.

Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Code Golf Stack Exchange is a site for recreational programming competitions, not general programming questions. Challenges must have an objective scoring criterion, and it is highly recommended to first post proposed challenges in the Sandbox.