r/programmingchallenges • u/babygame • Jun 01 '11
Coloring a grid
Make a program to color in the squares of an (n x m) grid (with some number of colors > 2) such that no two same colors touch.
There is a 'brute force' way, and (at least one) more 'elegant' solution as well.
Edit: I didn't specify-- try one that will output a different pattern each time. It's a nicer problem, I think :)
20
Upvotes
View all comments
4
u/julesjacobs Sep 08 '11
Your challenge is trivially satisfied by a chessboard pattern. Here's a more interesting challenge: from all grids that satisfy the OP's requirements, select one uniformly randomly, that is select one randomly with each valid grid having the same probability.