10
1
Mancala is the name of a family of board games that usually involve a series of cups filled with beads that the players manipulate. This challenge will use a specific rule set for a solitaire variant of the game.
The board consists of a "basket" at one end, followed by an infinite number of cups, numbered starting from 1. Some of the cups will have some number of beads in them. If the n
th cup has exactly n
beads in it, you may "sow" the beads from it. Sowing means to take all n
beads out of the cup, then deposit them one at a time in each cup towards the basket. The last bead will go into the basket. The player wins when all of the beads on the board are in the basket.
Clearly, there are many boards which are not winnable, such as if there is exactly one bead in the second cup. There are no legal plays because all the cups with 0 beads cannot be sown, and the second cup does not have enough beads to be sown. This is obviously no fun, so your task will be to create winnable boards.
Task
Given a positive integer representing a number of beads output a list of non-negative integers representing the number of beads that should be put in each cup to make a winnable board as described above. This list should not contain any trailing zeroes.
For any given number of beads, there is always exactly one winnable board configuration.
Demonstration
This is a demonstration of how to play the winnable board for and input of 4. The winnable board is [0, 1, 3]
. We start with the only available move, sowing the beads from the third cup to get [1, 2, 0]
. Now we actually have a choice, but the only correct one is sowing the first cup, getting: [0, 2, 0]
. Then we sow the second cup yielding [1, 0, 0]
and finally we sow the first cup again to get all empty cups.
Test cases:
1 => [1]
2 => [0, 2]
3 => [1, 2]
4 => [0, 1, 3]
5 => [1, 1, 3]
6 => [0, 0, 2, 4]
7 => [1, 0, 2, 4]
8 => [0, 2, 2, 4]
9 => [1, 2, 2, 4]
10 => [0, 1, 1, 3, 5]
11 => [1, 1, 1, 3, 5]
12 => [0, 0, 0, 2, 4, 6]
13 => [1, 0, 0, 2, 4, 6]
14 => [0, 2, 0, 2, 4, 6]
15 => [1, 2, 0, 2, 4, 6]
16 => [0, 1, 3, 2, 4, 6]
17 => [1, 1, 3, 2, 4, 6]
18 => [0, 0, 2, 1, 3, 5, 7]
19 => [1, 0, 2, 1, 3, 5, 7]
20 => [0, 2, 2, 1, 3, 5, 7]
Big thanks to PeterTaylor for coming up with a program to generate test cases!
3Proof of uniqueness with formula. – xnor – 2016-04-20T21:43:42.260