I can describe a way of indexing the ape’s coconuts with unique labels.
Hari Seldon was very… generous… in the number of coconuts the ape picks up each step. I’ll change that to 2 per step, to make this tractable. Let’s put the original black numbers on the coconut in a particular way. Each coconut is labeled in binary, with the digits between +/- 80 degrees on one side of the coconut. The least significant binary digit is between 40 and 80 degrees. If there are at least two digits, the most significant digit lies between -80 and -40 degrees. If there are three or more digits, the second-least-significant digit lies between 20 and 40 degrees. The pattern continues, so the twenty-first coconut, binary 10101, is labeled something like
10 101
Let’s look at the red 2. The first step, coconut 1 is removed, and red 2 is on the coconut labeled 1 0. The second step the red 2 is swapped with the red 3, so red 2 is on 1 1.
The next step, red 2 is again on the coconut to be removed, so it is swapped with red 5. Red 2 is now on 1 01.
If you follow this along, red 2 is on that coconut for a few steps, then is next on 10 01 then 10 001, etc. It usually stays put, but when it is swapped it gains another 0 in the middle. All the digits present at any step are always there at any later step, it just gains more and more zeros.
Follow this along, and the black label associated with red 2 is 100… …001
Similarly, for red 4, the sequence is
1 00
1 11
11 01
11 001
110 001
…
110… …001
Red 6 and red 8 eventually look like
1010… …0001 and 1110… …0001
In general, for all even red numbers N, the black labels will eventually be the binary representation of N-1, followed by zeros of descending size, then zeros of ascending size until a final 1 on the far right of the number. And of course, the odd numbers are in the monkey’s cave.
The same can be done if the ape picks up ten coconuts for every one the monkey takes, using decimal numbers. For the original case, you’d need to use base 1000.