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
Show parent comment
0
u/julesjacobs Sep 08 '11
Yup, that's an optimization of brute force rejection sampling, but might still be extremely slow. Can you compute the expected running time?