Problem Statement
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".
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
"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".
"010101"
5
Returns: "101010"
The state alternates between "010101" and "101010" repeatedly.
"111010"
58
Returns: "111111"
"111111111"
511
Returns: "111111111"
The state never changes.
"110010000010111110010100001001"
1000
Returns: "110000000001111110000000000001"
"11111111111111111111111111111111111111111111111111"
1000
Returns: "11111111111111111111111111111111111111111111111111"
"00001111111111111111111111111111111110000000000000"
1000
Returns: "00001111111111111111111111111111111110000000000000"
"11111111111111111111111111110000000001111111111111"
1000
Returns: "11111111111111111111111111110000000001111111111111"
"11111111111111110000000000011100000000000001111111"
1000
Returns: "11111111111111110000000000011100000000000001111111"
"00000000000001111111110000000000000000011111000000"
1000
Returns: "00000000000001111111110000000000000000011111000000"
"11111111101110000000000000000001111111110000000001"
1000
Returns: "11111111111110000000000000000001111111110000000001"
"11111111111111111111111111111111111100111100111011"
1000
Returns: "11111111111111111111111111111111111100111100111111"
"11110111111111111100011110011111110000000011111111"
1000
Returns: "11111111111111111100011110011111110000000011111111"
"00000000000000100000000111110001100000000000000110"
1000
Returns: "00000000000000000000000111110001100000000000000110"
"00000011111000000000011100000011001111111100111100"
1000
Returns: "00000011111000000000011100000011001111111100111100"
"01011100101001010001010110101010100101010110101010"
1000
Returns: "00111100000000000000011111111000000000111111110000"
"01101010010110101010101011101011101010010101010101"
1000
Returns: "11111000001111111111111111111111111000000000011111"
"10101010101010100001101011010101010101101011010101"
1000
Returns: "11111111000000000001111111111111111111111111111111"
"01011011010101010110010101010101001010101010100101"
1000
Returns: "11111111111111111110000000000000000000000000000000"
"01011010010101010101010101010101010110101101011010"
1000
Returns: "00111100000000000000001111111111111111111111111100"
"01011010101010101010101011010101011010101010101001"
1000
Returns: "01111111111111111111111111111111111111111000000000"
"01010010101101010101010101010101010101010110101010"
1000
Returns: "00000000111111111111111111111111111111111111110000"
"10101010101010101010101010101010101100101010101010"
1000
Returns: "00000000000111111111111111111111111100000000000000"
"01010101010101011010101010101010101010101010101010"
1000
Returns: "00000000111111111111111111111111100000000000000000"
"01010101010101010101010101010101010101010101010101"
1000
Returns: "01010101010101010101010101010101010101010101010101"
"1111101"
7
Returns: "1111111"
"010101010101101010"
6
Returns: "000000111111111000"
"111100111000"
3
Returns: "111100111000"
"00011010"
9
Returns: "00011100"
"01010011010011010101010101010101010"
3
Returns: "00000011100011111010101010101010000"
"1010110110010110"
8
Returns: "1111111110001111"
"0000001011010110101111101101001010111"
2
Returns: "0000000111111111111111111110000011111"
"0010100010011"
3
Returns: "0000000000011"
"11111111111111111000100111111110010101111111"
2
Returns: "11111111111111111000000111111110000111111111"
"0011"
9
Returns: "0011"
"001011010101010101010101010110100101010"
5
Returns: "000111111110101010101011111111000000000"
"01101010101010101010101010101010101010"
4
Returns: "01111110101010101010101010101010100000"
"0010000101011001000100100000100"
5
Returns: "0000000001111000000000000000000"
"0001100001110"
0
Returns: "0001100001110"
"101010101001011010101010101001010"
2
Returns: "101010100000111110101010100000010"
"001101111101110010000001110110100"
8
Returns: "001111111111110000000001111111000"
"101010101010101010101011010101010101010101010101"
1
Returns: "110101010101010101010111101010101010101010101011"
"11101101"
5
Returns: "11111111"
"000110101001010101001010110"
8
Returns: "000111100000000000000011110"
"11110001011011100000101100000111111"
9
Returns: "11110000111111100000011100000111111"
"10101010101010101010101010101010101010101010101010"
0
Returns: "10101010101010101010101010101010101010101010101010"
"11111111111111111111111111111111111111111111111111"
0
Returns: "11111111111111111111111111111111111111111111111111"
"0101010101010101010101010101010101010101010101010"
1
Returns: "0010101010101010101010101010101010101010101010100"
"0101010101010101010101010101010101010101010101010"
22
Returns: "0000000000000000000000010100000000000000000000000"
"0101010101010101010101010101010101010101010101010"
23
Returns: "0000000000000000000000001000000000000000000000000"
"1010101010101010101010101010101010101010101010101"
24
Returns: "1111111111111111111111111111111111111111111111111"
"1010101010101010101010101010101010101010101010101"
25
Returns: "1111111111111111111111111111111111111111111111111"
"0101010101010101010101010101010101010101010101010"
26
Returns: "0000000000000000000000000000000000000000000000000"
"111"
1000
Returns: "111"
"111"
0
Returns: "111"
"110"
1000
Returns: "111"
"010"
0
Returns: "010"
"00101110011"
0
Returns: "00101110011"
"101000100001000001111000111000110010101001"
1000
Returns: "110000000000000001111000111000110000000001"
"011100101010101010101111"
9
Returns: "111100000000011111111111"
"1111"
0
Returns: "1111"
"101"
1
Returns: "111"
"01010111011111111000000101011010101010010101"
1000
Returns: "11111111111111111000000001111111100000000000"
"111111111"
100
Returns: "111111111"
"10101"
1
Returns: "11011"
"10101010101010101010101010101010101010101010101010"
1000
Returns: "10101010101010101010101010101010101010101010101010"
"1010"
1
Returns: "0101"
"10010"
1
Returns: "00001"
"0101"
1
Returns: "1010"
"11010"
1
Returns: "11101"
"011"
1
Returns: "111"
"0101"
100
Returns: "0101"
"10100"
1
Returns: "01000"
"1110110101010101010"
346
Returns: "1111111111111111111"
"0101010101"
0
Returns: "0101010101"
"11111"
0
Returns: "11111"