This puzzle felt like one that Alteryx would be well suited to solving.
Representing the Board’s State
The board looks like:
Each location can either have a coin or not have a coin. This means a binary representation is straight forward. Keeping the numbering order the same I choose to have 1 be the first bit through to 10 being the 10th bit. So a board like:
Would be encoded to the number of 662:
Additionally, we can now create all the possible states of the board by running through every number from 1 to 1022. We can ignore the completely empty board (state 0) and completely full board (start 1023). Our goal is to get to a state where only one bit is set.
I chose to reverse the binary representation so character 1 of the string represents coin 1.
Next, I want to consider the set of possible moves. The board is very symmetrical so if we look at moving 1 it’s like looking at 7 and 10 as well. Likewise, 2 is like looking at 3, 4, 6, 8 and 9. And finally, we have 5 to look at.
Coin 1 can only jump to either 4 or 6 and only if 2 or 3 are occupied respectively. All other moves are either not in a straight line or exceed the bounds of the board.
Coin 2 can only jump to either 7 or 9 and only if 4 or53 are occupied respectively.
Finally, coin 5 cannot itself jump anywhere without exceeding the bounds of the board.
We can now build an entire set of all legitimate moves:
|Start||Moves (Start – Jump – End)|
What I chose to do was compute all the states that each state could move to. The first part of this was to break each state into 10 rows for every state with a 1 or 0 to show if a coin is present in each cell.
After this a sequence of joins allows you to work out the legitimate moves. First, join the cells with a coin to the start of a move. Then join the jump cell with an occupied cell. And then finally join the target cell with an empty cell. Having done this we end up with a table of State, Start, Jump, Target of all possible starting states and moves. The diagram below shows the state of the board for a random state and the possible moves:
Finally, using a formula tool to compute the new state of the board:
Now we need to work out the sequence of plays. I chose to run the sequence backwards. Start with the end state and reverse moves until you find an initial state. As I was being lazy I repeated blocks rather than an iterative macro but this seemed a simple solution given the scale of the problem.
To compute final states, I used a
REGEX_CountMatches expression to count the 1s. A final state will be an integral non-negative power of 2 and so will have a single 1 in the binary representation. We can then join the state transition to produce the possible last moves. For tracking the sequence of moves, I create two additional columns
MoveSequence. Moves will count the number of separate moves and MoveSequence will track the moves made.
We then need to make 7 more back steps. Each of these steps is identical. They take the current possible set of plays until this point and the state transitions and produces the next set of plays. If the
Target of the new move is equal to the
Start of the current move then we don’t increment the
Moves count otherwise we add 1. The expression I used was:
Having repeated this 6 more times, we end up with the 84 possible plays which win the game. The last step is to choose the lowest Moves and then we are done.
As always it is a lot of fun to challenge the bounds of what is possible within Alteryx. This was a nice puzzle and had some interesting challenges to build it quickly.
I’m not posting my sequence here but if you run the workflow it will give you the answer. The workflow is available on DropBox