Statistics

Problem Statement for "GameOfLifeDivTwo"

Problem Statement

Cat Taro and Rabbit Hanako invented a new variation of "Game Of Life".

N cells are arranged around a circle. The cells are numbered from 0 to N-1. For each i between 0 and N-2, inclusive, the i-th cell and the (i+1)-th cell are adjacent to each other. The (N-1)-th cell and the 0-th cell are adjacent to each other. Each cell has exactly two adjacent cells. Each cell has a state: "live" or "die".

Taro and Hanako can decide the states of the cells at time 0. For time t > 0, the states are determined as follows:
  • Consider three cells: the i-th cell and the two cells that are adjacent to the i-th cell.
  • If at least two of the three cells are "live" at time t-1, the state of the i-th cell at time t will be "live".
  • If at least two of the three cells are "die" at time t-1, the state of the i-th cell at time t will be "die".
You are given a String init. The number of cells in the game (N) is equal to the number of characters in init. The i-th character of init represents the state they assign to the i-th cell at time 0. '1' means "live" and '0' means "die". Return a string that describes the states at time T using the same encoding.

Definition

Class:
GameOfLifeDivTwo
Method:
theSimulation
Parameters:
String, int
Returns:
String
Method signature:
String theSimulation(String init, int T)
(be sure your method is public)

Constraints

  • init will contain between 3 and 50 characters, inclusive.
  • Each character in init will be '0' (zero) or '1' (one).
  • T will be between 0 and 1,000, inclusive.

Examples

  1. "01010"

    2

    Returns: "00000"

    At time 0, Taro and Hanako set the state to "01010". At time 1, the state becomes "00100". At time 2, the state becomes "00000".

  2. "010101"

    5

    Returns: "101010"

    The state alternates between "010101" and "101010" repeatedly.

  3. "111010"

    58

    Returns: "111111"

  4. "111111111"

    511

    Returns: "111111111"

    The state never changes.

  5. "110010000010111110010100001001"

    1000

    Returns: "110000000001111110000000000001"

  6. "11111111111111111111111111111111111111111111111111"

    1000

    Returns: "11111111111111111111111111111111111111111111111111"

  7. "00001111111111111111111111111111111110000000000000"

    1000

    Returns: "00001111111111111111111111111111111110000000000000"

  8. "11111111111111111111111111110000000001111111111111"

    1000

    Returns: "11111111111111111111111111110000000001111111111111"

  9. "11111111111111110000000000011100000000000001111111"

    1000

    Returns: "11111111111111110000000000011100000000000001111111"

  10. "00000000000001111111110000000000000000011111000000"

    1000

    Returns: "00000000000001111111110000000000000000011111000000"

  11. "11111111101110000000000000000001111111110000000001"

    1000

    Returns: "11111111111110000000000000000001111111110000000001"

  12. "11111111111111111111111111111111111100111100111011"

    1000

    Returns: "11111111111111111111111111111111111100111100111111"

  13. "11110111111111111100011110011111110000000011111111"

    1000

    Returns: "11111111111111111100011110011111110000000011111111"

  14. "00000000000000100000000111110001100000000000000110"

    1000

    Returns: "00000000000000000000000111110001100000000000000110"

  15. "00000011111000000000011100000011001111111100111100"

    1000

    Returns: "00000011111000000000011100000011001111111100111100"

  16. "01011100101001010001010110101010100101010110101010"

    1000

    Returns: "00111100000000000000011111111000000000111111110000"

  17. "01101010010110101010101011101011101010010101010101"

    1000

    Returns: "11111000001111111111111111111111111000000000011111"

  18. "10101010101010100001101011010101010101101011010101"

    1000

    Returns: "11111111000000000001111111111111111111111111111111"

  19. "01011011010101010110010101010101001010101010100101"

    1000

    Returns: "11111111111111111110000000000000000000000000000000"

  20. "01011010010101010101010101010101010110101101011010"

    1000

    Returns: "00111100000000000000001111111111111111111111111100"

  21. "01011010101010101010101011010101011010101010101001"

    1000

    Returns: "01111111111111111111111111111111111111111000000000"

  22. "01010010101101010101010101010101010101010110101010"

    1000

    Returns: "00000000111111111111111111111111111111111111110000"

  23. "10101010101010101010101010101010101100101010101010"

    1000

    Returns: "00000000000111111111111111111111111100000000000000"

  24. "01010101010101011010101010101010101010101010101010"

    1000

    Returns: "00000000111111111111111111111111100000000000000000"

  25. "01010101010101010101010101010101010101010101010101"

    1000

    Returns: "01010101010101010101010101010101010101010101010101"

  26. "1111101"

    7

    Returns: "1111111"

  27. "010101010101101010"

    6

    Returns: "000000111111111000"

  28. "111100111000"

    3

    Returns: "111100111000"

  29. "00011010"

    9

    Returns: "00011100"

  30. "01010011010011010101010101010101010"

    3

    Returns: "00000011100011111010101010101010000"

  31. "1010110110010110"

    8

    Returns: "1111111110001111"

  32. "0000001011010110101111101101001010111"

    2

    Returns: "0000000111111111111111111110000011111"

  33. "0010100010011"

    3

    Returns: "0000000000011"

  34. "11111111111111111000100111111110010101111111"

    2

    Returns: "11111111111111111000000111111110000111111111"

  35. "0011"

    9

    Returns: "0011"

  36. "001011010101010101010101010110100101010"

    5

    Returns: "000111111110101010101011111111000000000"

  37. "01101010101010101010101010101010101010"

    4

    Returns: "01111110101010101010101010101010100000"

  38. "0010000101011001000100100000100"

    5

    Returns: "0000000001111000000000000000000"

  39. "0001100001110"

    0

    Returns: "0001100001110"

  40. "101010101001011010101010101001010"

    2

    Returns: "101010100000111110101010100000010"

  41. "001101111101110010000001110110100"

    8

    Returns: "001111111111110000000001111111000"

  42. "101010101010101010101011010101010101010101010101"

    1

    Returns: "110101010101010101010111101010101010101010101011"

  43. "11101101"

    5

    Returns: "11111111"

  44. "000110101001010101001010110"

    8

    Returns: "000111100000000000000011110"

  45. "11110001011011100000101100000111111"

    9

    Returns: "11110000111111100000011100000111111"

  46. "10101010101010101010101010101010101010101010101010"

    0

    Returns: "10101010101010101010101010101010101010101010101010"

  47. "11111111111111111111111111111111111111111111111111"

    0

    Returns: "11111111111111111111111111111111111111111111111111"

  48. "0101010101010101010101010101010101010101010101010"

    1

    Returns: "0010101010101010101010101010101010101010101010100"

  49. "0101010101010101010101010101010101010101010101010"

    22

    Returns: "0000000000000000000000010100000000000000000000000"

  50. "0101010101010101010101010101010101010101010101010"

    23

    Returns: "0000000000000000000000001000000000000000000000000"

  51. "1010101010101010101010101010101010101010101010101"

    24

    Returns: "1111111111111111111111111111111111111111111111111"

  52. "1010101010101010101010101010101010101010101010101"

    25

    Returns: "1111111111111111111111111111111111111111111111111"

  53. "0101010101010101010101010101010101010101010101010"

    26

    Returns: "0000000000000000000000000000000000000000000000000"

  54. "111"

    1000

    Returns: "111"

  55. "111"

    0

    Returns: "111"

  56. "110"

    1000

    Returns: "111"

  57. "010"

    0

    Returns: "010"

  58. "00101110011"

    0

    Returns: "00101110011"

  59. "101000100001000001111000111000110010101001"

    1000

    Returns: "110000000000000001111000111000110000000001"

  60. "011100101010101010101111"

    9

    Returns: "111100000000011111111111"

  61. "1111"

    0

    Returns: "1111"

  62. "101"

    1

    Returns: "111"

  63. "01010111011111111000000101011010101010010101"

    1000

    Returns: "11111111111111111000000001111111100000000000"

  64. "111111111"

    100

    Returns: "111111111"

  65. "10101"

    1

    Returns: "11011"

  66. "10101010101010101010101010101010101010101010101010"

    1000

    Returns: "10101010101010101010101010101010101010101010101010"

  67. "1010"

    1

    Returns: "0101"

  68. "10010"

    1

    Returns: "00001"

  69. "0101"

    1

    Returns: "1010"

  70. "11010"

    1

    Returns: "11101"

  71. "011"

    1

    Returns: "111"

  72. "0101"

    100

    Returns: "0101"

  73. "10100"

    1

    Returns: "01000"

  74. "1110110101010101010"

    346

    Returns: "1111111111111111111"

  75. "0101010101"

    0

    Returns: "0101010101"

  76. "11111"

    0

    Returns: "11111"


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: