Statistics

Problem Statement for "Dragons"

Problem Statement

There is a small cube planet somewhere. On each side of the cube there lives a four-armed dragon. It is time for dinner now. Each dragon sits in front of his bowl with food.

During each round, the following happens: Each dragon is trying to steal food from his neighbors (living on four neighboring sides of the cube). He spreads his four arms there (each arm goes to each separate neighbor). As other dragons do the same, four hands meet in each bowl of food. Four hands fight for a while and each takes one quarter of the food in this bowl to its own bowl. Hence, each round the food distribution changes.

Given the initial amount of food in each bowl and the number of rounds, return the amount of food the dragons' boss Snaug will have after these rounds.

In more detail:

The initial amount of food will be given in the following order: front, back, up, down, left, right. The dragons' boss Snaug lives on the "up" side of the cube. If the answer is an integer, return this integer. If the answer is a fraction, return the answer in the format X/Y, where X and Y are integers without common factors. Extra leading zeroes shouldn't be present in your answer.

Example.

Suppose that the initial distribution of food is the following: 0, 0, 4, 0, 0, 0. That is Snaug has 4 and everybody else has 0 amount of food in their bowls. After the first round the distribution of food will be the following: 1, 1, 0, 0, 1, 1, that is every neighbor of Snaug steals from him one quarter of his food. After the second round the distribution of food will be the following: 1/2, 1/2, 1, 1, 1/2, 1/2.

Definition

Class:
Dragons
Method:
snaug
Parameters:
int[], int
Returns:
String
Method signature:
String snaug(int[] initialFood, int rounds)
(be sure your method is public)

Constraints

  • initialFood has exactly 6 elements
  • each element of initialFood is between 0 and 1,000 inclusive
  • rounds is between 0 and 45 inclusive

Examples

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

    2

    Returns: "1"

    See the explanation above

  2. {0, 0, 4, 0, 0, 0}

    3

    Returns: "1/2"

  3. {1000, 1000, 1000, 1000, 1000, 1000}

    45

    Returns: "1000"

    When everybody has the same amount of food, they continue to have the same amount of food after each round

  4. {0, 0, 4, 0, 0, 0}

    45

    Returns: "5864062014805/8796093022208"

  5. {1, 0, 0, 0, 0, 0}

    45

    Returns: "11728124029611/70368744177664"

  6. {1, 2, 3, 4, 5, 6}

    45

    Returns: "7/2"

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

    45

    Returns: "61572651155457/17592186044416"

  8. {1000, 0, 0, 0, 0, 0}

    45

    Returns: "1466015503701375/8796093022208"

  9. {999,0,0,0,0,0}

    45

    Returns: "11716395905581389/70368744177664"

  10. {0,0,999,0,0,0}

    45

    Returns: "5858197952790195/35184372088832"

  11. {0,0,0,0,0,0}

    10

    Returns: "0"

  12. {999,998,997,996,995,994}

    45

    Returns: "1993/2"

  13. {2,2,3,3,4,4}

    45

    Returns: "3"

  14. {3,3,2,2,4,4}

    45

    Returns: "105553116266497/35184372088832"

  15. {1,10,100,2,20,200}

    45

    Returns: "3905465301860361/70368744177664"

  16. {0,1,0,0,0,0}

    45

    Returns: "11728124029611/70368744177664"

  17. {0,0,1,0,0,0}

    45

    Returns: "5864062014805/35184372088832"

  18. {0,0,0,1,0,0}

    45

    Returns: "5864062014805/35184372088832"

  19. {0,0,0,0,1,0}

    45

    Returns: "11728124029611/70368744177664"

  20. {0,0,0,0,0,1}

    45

    Returns: "11728124029611/70368744177664"

  21. {128, 256, 384, 512, 640, 768}

    45

    Returns: "448"

  22. {1,0,0,0,0,0}

    1

    Returns: "1/4"

  23. {0,1,0,0,0,0}

    1

    Returns: "1/4"

  24. {0,0,1,0,0,0}

    1

    Returns: "0"

  25. {0,0,0,0,1,0}

    1

    Returns: "1/4"

  26. {0,0,0,0,0,1}

    1

    Returns: "1/4"

  27. {22,33,44,11,4,4}

    0

    Returns: "44"

  28. { 5, 6, 1, 2, 3, 4 }

    45

    Returns: "61572651155457/17592186044416"

  29. { 3, 5, 7, 11, 13, 17 }

    45

    Returns: "328387472829099/35184372088832"

  30. { 3, 4, 5, 6, 1, 2 }

    45

    Returns: "61572651155455/17592186044416"

  31. { 200, 1000, 999, 977, 13, 337 }

    45

    Returns: "20676682664203205/35184372088832"

  32. { 0, 0, 1, 0, 0, 0 }

    45

    Returns: "5864062014805/35184372088832"

  33. { 200, 1000, 999, 977, 337, 13 }

    45

    Returns: "20676682664203205/35184372088832"

  34. { 6, 5, 1, 3, 2, 4 }

    45

    Returns: "246290604621827/70368744177664"

  35. { 46, 21, 13, 17, 14, 33 }

    45

    Returns: "844424930131977/35184372088832"

  36. { 200, 999, 1000, 13, 937, 133 }

    45

    Returns: "38491703065182289/70368744177664"

  37. { 7, 11, 13, 17, 19, 27 }

    45

    Returns: "275610914695851/17592186044416"

  38. { 0, 1000, 1000, 1000, 1000, 1000 }

    45

    Returns: "7330077518506625/8796093022208"

  39. { 999, 1000, 200, 133, 13, 923 }

    45

    Returns: "38327509328768415/70368744177664"

  40. { 1, 3, 5, 7, 9, 11 }

    45

    Returns: "6"

  41. { 1, 2, 3, 4, 5, 6 }

    45

    Returns: "7/2"


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: