Since you have not done this type of problem before, start by doing the problem. By that I mean, play the game. Get some black and white chips or poker chips or cards. Line them up and play the game. Or work out examples on paper like you did in your post. Create enoguh examples that you understand the algorithm and you can either solve the puzzle or declare it unsolvable.
Once you can solve the probme by hand, try to converty the algorithm you discovered into code in the language of your choice.
This puzzle may be famous, but I have not heard of it. It looks like a simpler version of the 15 puzzle (which is very famous). You might learn something by researching the 15 puzzle since this seems like a one-dimensional variation.