21
3
The game of Chinese checkers is played on a board with spaces in the shape of a six-pointed star:
We can create an ASCII-art representation of this board, using .
for empty spots and the letters GYORPB
for the six colored starting locations:
G
G G
G G G
G G G G
B B B B . . . . . Y Y Y Y
B B B . . . . . . Y Y Y
B B . . . . . . . Y Y
B . . . . . . . . Y
. . . . . . . . .
P . . . . . . . . O
P P . . . . . . . O O
P P P . . . . . . O O O
P P P P . . . . . O O O O
R R R R
R R R
R R
R
To make it more interesting, we can also change the size. We'll measure the size of a board by the side length of its triangular starting locations: the board above is size 4.
Since it's really a pain to type all that by hand, let's write a program (or function) to do it!
Details
Your code should take a positive integer representing the size of the board, via STDIN, ARGV, or function argument. Output the checkerboard pattern to STDOUT (you may alternately return it as a string if your submission is a function).
Output must either
- have no trailing spaces at all, or
- have exactly enough trailing spaces to fill out the pattern to a perfect rectangle of width 6 * N + 1.
Output may optionally have a trailing newline. No other extra (leading, trailing) whitespace is permitted.
Examples
Size 1:
G
B . . Y
. . .
P . . O
R
Size 2:
G
G G
B B . . . Y Y
B . . . . Y
. . . . .
P . . . . O
P P . . . O O
R R
R
Size 4:
G
G G
G G G
G G G G
B B B B . . . . . Y Y Y Y
B B B . . . . . . Y Y Y
B B . . . . . . . Y Y
B . . . . . . . . Y
. . . . . . . . .
P . . . . . . . . O
P P . . . . . . . O O
P P P . . . . . . O O O
P P P P . . . . . O O O O
R R R R
R R R
R R
R
Scoring
This is code-golf: the shortest code in bytes wins.
Can the output have empty lines of spaces before and after? – xnor – 2015-05-30T06:04:55.633
I'm going to say no. – DLosc – 2015-05-30T06:29:21.763
You mentioned trailing spaces, but what about leading spaces? Does the image need to be flush left, or can it have an equal amount of leading spaces on each line? – Sp3000 – 2015-05-30T06:35:21.023
Flush left, as shown in the sample output. – DLosc – 2015-05-30T06:39:03.537
Can there be spaces beyond the right edge but still forming a rectangle? – xnor – 2015-05-30T06:42:39.937
Where were you guys when this was in the sandbox? ;) No. Question edited to clarify whitespace policy. – DLosc – 2015-05-30T07:19:58.707