Lights Out is a logic game wherein all lights need to be turned off to complete each board. See the first problem in the series for an introduction.
This problem contains boards that each require ten moves to solve. For example, if
board = [0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 1]
an answer is:
moves = [1 2 3 4 5 16 17 18 19 20]
Prev.: 5x5, 8 moves — Next: 5x5, 13 moves
There seems to be a problem with Lights Out 5. Test cases 4 and 11 can be solved in fewer than 10 moves. Case 4 is solved by [1 3 5 21 23 25], which is easily verified by hand. Case 11 takes 9 moves -- [1 3 7 12 15 16 22 24 25].
@goc
1 William is right.
2 Next problem of this series could be "Lights Out - 5x5, from 3 to 10 moves", I think it is more difficult than this one.
@goc3 Sorry for misspell your name, but I can not delete the comment because of bug of cody.
@William: thanks for catching that. Actually, test case 4 was intentional, as it can also be solved in 10 moves. But, to prevent future confusion, I have replaced it. And, test case 11 was indeed an error—it has been fixed.
@li haitao: the test suite has been updated. Also, problem #7 in the series (not out yet, but will be soon) is similar to what you suggest. Thanks for the comments.
@goc3
A piece of advice, measure the running time(using tic, toc, for example) in the test suit to see which solution is fast.
@li haitao: I got 3.838179s (total time for test suite) for William's solution and 0.986936s (1/4 the time) for your sped-up version. Impressive.
i am surprised about the fact that some test admit a shorter solution than 10 moves :S
Find the longest sequence of 1's in a binary sequence.
2444 Solvers
Return the 3n+1 sequence for n
5205 Solvers
196 Solvers
Determine the number of odd integers in a vector
321 Solvers
102 Solvers