Build a checkerboard

For this challenge you will print the coordinates and color of each piece at the start of a game of checkers.

Enter the x and y (comma seperated) for every square (indexed 0-7) on a checkerboard, followed by a "r" or "b" (for red or black) where the top of the board (closer to y=0) is red and the bottom is black. newlines between pieces are required and no spaces are necessary.

This is so answers are scored in bytes with fewer bytes being better.

Trailing newlines are allowed but not necessary and the order must be exactly of that below.

Desired output:

0,0r
0,2r
0,4r
0,6r
1,1r
1,3r
1,5r
1,7r
2,0r
2,2r
2,4r
2,6r
5,1b
5,3b
5,5b
5,7b
6,0b
6,2b
6,4b
6,6b
7,1b
7,3b
7,5b
7,7b

• Is there a particular reason you skip x=3 and x=4? – HyperNeutrino Sep 27 '17 at 22:35
• @HyperNeutrino because a checkerboard has only the top and bottom 3 rows filled (at the start of the game) – Justin Sep 27 '17 at 22:36
• So that's basically the starting position of Checkers, aka English Draughts. Is that correct? – Arnauld Sep 27 '17 at 22:47
• Welcome to PPCG.SE! A feature of this site that some of us like to use is the sandbox. You don't have to use it, but it is a useful channel through which to get feedback about any new challenge ideas you have, without having to go through the whole downvote/closevote misery. – Digital Trauma Sep 27 '17 at 23:06
• Can the coordinates be separated by a delimiter other than a new-line? I.e. 0,0r;0,2r;0,4r;0,6r;1,1r;1,3r;1,5r;1,7r;2,0r;2,2r;2,4r;2,6r;5,1b;5,3b;5,5b;5,7b;6,0b;6,2b;6,4b;6,6b;7,1b;7,3b;7,5b;7,7b? – Kevin Cruijssen Sep 28 '17 at 11:52

05AB1E, 26 bytes

2ÝD5+«v4Fy',N·yÉ+„bry3‹èJ,


Try it online!

Explanation

2Ý                           # push [0,1,2]
D5+                        # duplicate and add 5: [5,6,7]
«                       # concatenate
v                      # for each y in [0,1,2,5,6,7] do:
4F                    # for each N in [0 ... 3] do:
y                   # push y
',                 # push ","
N·yÉ+            # push N*2+isOdd(y)
„br         # push "br"
y3‹è     # index into the string with y<3
J,   # join everything to a string and print

• I feel like [0,1,2,5,6,7] could be pushed in less bytes... but all I could think of was 7Ý34SK so I guess not. – Magic Octopus Urn Sep 29 '17 at 16:50

JavaScript (ES6), 66 bytes

Includes a trailing newline.

f=(n=24)=>n--?f(n)+[2*(x=n>11)+(y=n>>2),n%4*2+y%2+'rb'[+x]]+
:''


Demo

f=(n=24)=>n--?f(n)+[2*(x=n>11)+(y=n>>2),n%4*2+y%2+'rb'[+x]]+
:''

console.log(f())

Perl 5, 53 bytes

//&map{say"$',",$_+$'%2,$'<4?r:b}0,2,4,6for 0..2,5..7


Try it online!

C (gcc), 838179 78 bytes

• Saved two bytes thanks to Tahg; golfing x/4+2*(x/12) to x/4+x/12*2.
• Saved two bytes thanks to Kevin Cruijssen; golfing x%8*2%8 to x*2%8.
• Saved a byte thanks to ceilingcat.
x;main(){for(;x<24;)printf("%d,%d%c\n",x/4+x++/12*2,x*2%8+x/4%2,114-x/12*16);}


Try it online!

• You can do x/4+x/12*2 and get rid of the () – Tahg Sep 28 '17 at 11:29
• x%8*2%8 can be x*2%8 – Kevin Cruijssen Sep 28 '17 at 11:37
• @ceilingcat Thank you. – Jonathan Frech Sep 14 at 14:15

Python 2, 7473 67 bytes

for i in 0,1,2,5,6,7:j=i%2;exec"printi+','+j+'rb'[i>4];j+=2;"*4


Try it online!

• in(...): -> in ...:. – Jonathan Frech Sep 28 '17 at 12:09

Java 8, 102969593 91 bytes

v->{for(int i=0;i<24;System.out.printf("%d,%d%c%n",i/4+i/12*2,i*2%8+i/4%2,i++<12?114:98));}


Port from @JonathanFrech's C answer, after which I golfed 5 bytes myself.

Try it here.

Explanation:

v->{                    // Method without empty unused parameter and no return-type
for(int i=0;i<24;     //  Loop from 0 to 24 (exclusive)
System.out.printf("%d,%d%c%n",
//   Print with format:
//   (%d=digit; %c=character; %n=new-line)
i/4+i/12*2,       //    Print first coordinate
i*2%8+i/4%2,      //    Print second coordinate
i++<12?114:98)    //    Print either 'r' or 'b'
);                    //  End of loop
}                       // End of method


Bash, 59 bytes

Not the shortest, but a fun one:

printf %s\\n {{0,2,6}\,{0,2,4,6}r,{1,5,7}\,{1,3,5,7}b}|sort


Try it online!

APL (Dyalog Classic), 38 bytes

(⍕⍪4/3 4~⍨⍳8),',',(⍕⍪24⍴⍋8⍴⍳2),12/'rb'


Try it online!

8Ḷḟ3ḟ4µḂr7m2ṭ€µ€Ẏµḣ1<3Ḣị⁾rbṭj”,$µ€Y  Try it online! Full program taking no arguments Explanation 8Ḷḟ3ḟ4µḂr7m2ṭ€µ€Ẏµḣ1<3Ḣị⁾rbṭj”,$µ€Y  Main link; no arguments
8                                    8
Ḷ                                   Push 0 .. 8 - 1
ḟ                                  Remove all instances of
3                                 3
ḟ                                Remove all instances of
4                               4
€                    For each in [0, 1, 2, 5, 6, 7]
µḂr7m2ṭ€µ                     Generate all of the piece coordinates across that row
Ḃ                            row number % 2
r                           inclusive range up to
7                          7
m                         modular; take every   elements
2                                            2
€                      For each column coordinate
ṭ                       Tack the row coordinate (reverse append)
Ẏ                   Tighten; flatten once
€   For each piece coordinate (in the right order now)
µḣ1<3Ḣị⁾rbṭj”,$µ Convert to its final output ḣ Head; take the first element(s) 1 1 < Less Than; compare each element to 3 3 Ḣ Head; take the comparison out of the list ị Index (1-indexed) into ⁾rb "rb" ṭ Tack the color character behind j”,$     The coordinates joined by a comma
j        Join with separator
”,      ","
Y  Separate by newlines


Java 8, 97 bytes

o->{int i=0,g;for(;i<8;i+=i==2?3:1)for(g=i%2;g<8;g+=2)System.out.println(i+","+g+(i<5?"r":"b"));}


JavaScript (ES6), 64 bytes

This seems sufficiently different from @Arnauld's to warrant posting:

f=(n=0,y=n>>3,c=y>2)=>y<6?[y+c*2,n%8+y%2+'rb'[+c]]+
+f(n+2):''


Explanation:

f=(n = 0,            //the numbered square on checkerboard
y = n >> 3,       //current row (n / 8 rounded)
c = y > 2         //false if red pieces, true if black
) =>
y < 6 ?            //if y less than 6
[                //  using an array automatically adds the comma
y + c * 2,      //  0 - 2 if red pieces, 5 - 7 if black
n%8 + y%2 +     //  n%8 returns 0, 2, 4, or 6.
//  y%2 returns 0 or 1.
//  added, they return the appropriate position (0 - 7)
'rb'[+c]        //  'r' if red, 'b' if black.  Plus sign coerces boolean to number.
]+              //  new line
+
f(n+2) :         //  recurse on n+2
''               //else return an empty string


Snippet:

f=(n=0,y=n>>3,c=y>2)=>y<6?[y+c*2,n%8+y%2+'rb'[+c]]+
+f(n+2):''

console.log(f());

Python 2, 63 bytes

x=0;exec"printx/8+x/24*2+','+x%8+x/8%2+'rb'[x/24];x+=2;"*24


Try it online!

APL (Dyalog), 45 44 bytes*

-1 thanks to ngn.

Niladic function which assumes 0-based indexing (⎕IO←0) which is default on many systems. Prints to STDOUT.

↑' '⎕R','⊃,/(8 ¯8↑¨⊂⍕¨⍸∘.=⍨2|⍳8),¨¨'rb'


Try it online!

(),¨¨'rb' append "r" to each of the first group of items and "b" to each of the second:

⍳8 zero through eight

2| division remainder when halved

∘.+⍨ plus table with itself on along both axes

⍸ indices of true values

⍕¨ format each (converts to strings with the pattern d d where each d is a digit)

⊂ enclose (so we can reuse it for each…)

8 ¯8↑¨ take the first nine and the last nine

now we have two lists of d d strings

,/ catenation reduction (combine the two lists)

⊃ disclose (because the reduction reduced the rank from 1 to 0)

' '⎕R',' PCRE Replace spaces with commas

↑ mix (the all the lists into a single matrix)

* In Dyalog Classic, counting ⍸ as ⎕U2378.

• ~2|∘.+⍨⍳8 could be ∘.=⍨2|⍳8 – ngn Sep 30 '17 at 9:58
• you shouldn't output rows x=3 and x=4 – ngn Sep 30 '17 at 10:03
• @ngn 2⍴⊂'Thanks' – Adám Oct 2 '17 at 11:55

00000000: 15ca b101 0030 0400 c1de 2c0a 2462 1f23  .....0....,.$b.# 00000010: d8bf 886f ae3a 531b 310d b8f0 465c 1d0e ...o.:S.1...F\.. 00000020: 24d4 48ec 5b02 2eec 4bf5 5e0e 2454 cb53$.H.[...K.^.$T.S 00000030: 8380 0baf a5d4 e140 42f5 07 .......@B..  Try it online! • This is the hexdump, right? – Stan Strum Sep 28 '17 at 16:37 • @StanStrum Yes this is the hexdump of the actual source. By using the hexdump no unprintables get lost. The actual source doesn't add anything to the answer IMO. – ovs Sep 28 '17 at 16:44 • Okay, I was just wondering. Thanks – Stan Strum Sep 28 '17 at 16:59 Pyth, 3736 35 bytes isaacg wouldn't be proud V+U3}5 7FG4p++N\,+yG?!%N2Z1?<N5\r\b  Explanation: V+U3}5 7 For in the array [0, 1, 2, 5, 6, 7] as N FG4 For in the array [0, 1, 2, 3] as G p Print without newline: ++N\,+yG?!%N2Z1 N, (2 * G) + 1 if N is even, else 0 ?<N5\r\b Output with newline "r" if N < 5 else "b"  This uses a simple pattern I cut down a bit. As follows: If the X coord is even, use the even numbers 0, 2, 4, 6. Else, 1, 3, 5, 7 for Y. If the X coord is less than 5, the color (r or b) is r. Else, it is b. Try it online! edit: overnight got +40 rep on 3 different answers w00t SOGL V0.12, 31 bytes ⁰¹²⁵⁶⁷’{A4∫«Ha2\⌡HaOļ,pƧbra4>Wo  Try it Here! Javascript (89 bytes): for(x=y=0,r="r";x<7|y<8;console.log(x+","+y+r),y+=2){if(y>7)y=++x%2;if(x==3){x+=2;r="b"}}  Readable: for(var x = y = 0, red = true; x < 7 || y < 8; y += 2) { if(y > 7) { //new row x++; y = x % 2; } if(x == 3) { //new color x += 2; red = false; } console.log(x + "," + y + (red ? "r" : "b") ); }  Try it online! • Please note that it is discouraged to answer your own challenge just after posting it. – Arnauld Sep 27 '17 at 22:22 • Ok. Should I take it down and possibly post later? – Justin Sep 27 '17 at 22:24 • Ok will do. Thanks for the heads up – Justin Sep 27 '17 at 22:26 • This might sound stupid but how do I delete a post on mobile? – Justin Sep 27 '17 at 22:27 • @Justin You can't delete posts on mobile. It is an annoyance to many. – Sriotchilism O'Zaic Sep 27 '17 at 22:28 Jelly, 27 bytes 8Ḷµḟ3,4pµSḂ$Ðḟj€”,ż⁾rbx12¤Y


A full program which prints the required output.

Try it online!

How

8Ḷµḟ3,4p⁸SḂ$Ðḟj€”,ż⁾rbx12¤Y - Link: no arguments 8 - literal eight Ḷ - lowered range = [0,1,2,3,4,5,6,7] µ - new monadic chain 3,4 - literal list = [3,4] ḟ - filter discard = [0,1,2,5,6,7] ⁸ - chain's left argument = [0,1,2,3,4,5,6,7] p - Cartesian product = [[0,0],[0,1],...,[2,7],[5,0],...,[7,6],[7,7]] Ðḟ - filter discard if:$                -   last two links as a monad:
S                  -     sum
Ḃ                 -     modulo by 2
”,          - literal comma character
j€            - join €ach pair with a comma = [0,',',0],[0,',',2],...,[2,',',6],[5,',',1],...,[7,',',5],[7,',',7]]
⁾rb      - literal list = ['r','b']
12   - literal twelve
x     - repeat = ['r','r','r','r','r','r','r','r','r','r','r','r','b','b','b','b','b','b','b','b','b','b','b','b']
ż         - zip together = [[[0,',',0],'r'],[[0,',',2],'r'],...,[[2,',',6],'r'],[[5,',',1],'b'],...,[[7,',',5],'b'],[[7,',',7],'b']]
Y - join with newlines = [[0,',',0],'r','\n',[0,',',2],'r','\n',...,'\n',[2,',',6],'r','\n',[5,',',1],'b','\n',...,'\n',[7,',',5],'b','\n',[7,',',7],'b']
- implicit print (smashes the list of lists and characters
-                 together and prints the digits)


Ruby, 63 60 bytes

[*0..11,*20..31].map{|x|puts [x/4,2*x%8+x[2]]*?,+"rb"[x[4]]}


$. format as a sparse array, kind of looks like the goal ": "to text" }:"1 delete the last column ,.12#'rb' append 12 rs followed by 12 bs as the last column  C# (.NET Core), 96 bytes ()=>{for(int i=0;i<24;)System.Console.Write($"{i/4+i/12*2},{i*2%8+i/4%2}{(i++>11?"b":"r")}\n");}