Statistics

Problem Statement for "Pebbles"

Problem Statement

Suppose you have pebbles arranged into several piles. On each round you take one pebble from each pile and make a new pile out of the pebbles you took. As the number of ways to divide the pebbles into piles is finite, it is obvious that arrangements of piles will start to repeat themselves.

Your task is, given an arrangement of pebbles into piles, return the first round when the cycle starts. Consider the original arrangement as round zero.

Comment
This problem is based on the following math problem. You have an arrangement with 45 pebbles, prove that after several rounds it stabilizes (i.e. the final cycle is actually an arrangement that repeats itself at each round). This math problem sounds easy, but in fact it is not that trivial.

Definition

Class:
Pebbles
Method:
cycleStart
Parameters:
int[]
Returns:
int
Method signature:
int cycleStart(int[] initialPiles)
(be sure your method is public)

Notes

  • The arrangement doesn't depend on how you order the piles. Namely, the arrangement {3, 2, 1} is considered the same as {1, 2, 3}.

Constraints

  • initialPiles has between 1 and 20 elements inclusive
  • each element in initialPiles is between 1 and 100 inclusive

Examples

  1. {1,2,3,4,5,6,7,8,9}

    Returns: 0

    If we take one pebble away from each of the piles to form a new pile, we will have a new pile with 9 pebbles. Each of the other piles has one less pebble than originally, in particular, the pile which had 1 pebble disappears. Thus, we end up with piles with the same numbers of pebbles that we started with - {1,2,3,4,5,6,7,8,9}.

  2. {5}

    Returns: 2

    We take one pebble from the only pile and make a new pile with it. Thus, on the next round we have the arrangement {1, 4}. On the next round we have {2, 3}, the next round - {1, 2, 2}, the next round - {1, 1, 3}, and the next round - {2, 3}. The last arrangement of piles is the same as round two, return 2.

  3. {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100}

    Returns: 2762

  4. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}

    Returns: 15

  5. {10,20,30,40,50,60,70,80,90,100,10,20,30,40,50,60,70,80,90,100}

    Returns: 246

  6. {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,99}

    Returns: 2698

  7. {100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,99,99}

    Returns: 2634

  8. {100,100,100,100,100,100,100,100,100,100,100,100,100,100,99,99,99,99,99,99}

    Returns: 2378

  9. {99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99}

    Returns: 1988

  10. {1,1,1,1,1,1,1,1,1,1,100,100,100,100,100,100,100,100,100,100}

    Returns: 910

  11. {100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81}

    Returns: 2200

  12. {100,99,98,97,96,95,94,93,92,91,100,99,98,97,96,95,94,93,92,91}

    Returns: 2381

  13. {6}

    Returns: 3

  14. {55}

    Returns: 45

  15. {1}

    Returns: 0

  16. {2}

    Returns: 0

  17. {1,1}

    Returns: 0

  18. {9,8,7,6,5,4,3,2,1}

    Returns: 0

  19. {99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99}

    Returns: 1988

  20. {100}

    Returns: 86

  21. { 100, 99, 75 }

    Returns: 358

  22. { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }

    Returns: 2762

  23. { 5 }

    Returns: 2

  24. { 45 }

    Returns: 36

  25. { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 1, 1, 1 }

    Returns: 1180

  26. { 1 }

    Returns: 0

  27. { 1, 4 }

    Returns: 1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: