# SPIN - Editorial

CHALLENGE

### EXPLANATION

The easiest way to get accepted is to output a sequence of 100 random moves for N = 2 and -1 for all other cases. Not that it really matters

One of the simplest good approaches is the following. Letâ€™s fix color C into which weâ€™re going to color all the wheels. Letâ€™s say that a wheel is reachable from C if it can be colored into C through a sequence of moves each of which rotates a wheel of color C. Itâ€™s easy to check this for all wheels in O(NM) total time. Letâ€™s rotate some random wheel from those which are not reachable from C several times until all of the wheels are reachable. When this finally happens, letâ€™s rotate some random wheel of color C so that at least one of the wheels is colored into C at the first iteration. It can be seen that weâ€™ll actually color all the wheels into C pretty quickly. This approach is enough to get a score of under 450.

Other solutions should probably use a similar idea. Tiancheng Louâ€™s solution receiving a score of under 303 also makes use of beam search, as it can be inferred from his code.

### SETTERâ€™S SOLUTION

Can be found here.

### TESTERâ€™S SOLUTION

Can be found here.