Conway's Game of Life is quite popular, so let's add our own variation on the idea. Instead of a grid of squares, let's instead use a hexagonal grid. We'll orient the grid so that the hexagons are stacked in vertical columns. The same rules as before still apply, being:
6 "neighbor" squares.
2 neighbors, it will die on the next turn. 2 or 3 neighbors, it will remain on the next turn. 3 neighbors, it will die on the next turn.3 nieghbors, then a cell will appear in that hexagon on the next turn.Also as before, the spaces on the topmost and bottommost rows are considered adjacent, and the spaces on the leftmost and rightmost columns are also considered adjacent. There will always be an even quantity of columns to ensure there will be no issue.
Below we have a 6x5 grid of hexagons, simulated for 2 turns. Note that the upper-leftmost
hexagon is "above" the hexagon in the next column. This will always be the case for all textcases
Turn 0:
_____ _____ _____
/ \ / \ / \
/ \_____/ \_____/ x \_____
\ / \ / \ / \
\_____/ \_____/ x \_____/ \
/ \ / \ / \ /
/ \_____/ \_____/ \_____/
\ / \ / \ / \
\_____/ \_____/ \_____/ \
/ \ / \ / \ /
/ x \_____/ x \_____/ x \_____/
\ / \ / \ / \
\_____/ \_____/ x \_____/ \
/ \ / \ / \ /
/ \_____/ x \_____/ \_____/
\ / \ / \ / \
\_____/ \_____/ x \_____/ \
/ \ / \ / \ /
/ \_____/ x \_____/ x \_____/
\ / \ / \ / \
\_____/ \_____/ x \_____/ \
\ / \ / \ /
\_____/ \_____/ \_____/
Turn 1:
_____ _____ _____
/ \ / \ / \
/ \_____/ x \_____/ x \_____
\ / \ / \ / \
\_____/ \_____/ x \_____/ \
/ \ / \ / \ /
/ \_____/ \_____/ x \_____/
\ / \ / \ / \
\_____/ \_____/ \_____/ \
/ \ / \ / \ /
/ \_____/ x \_____/ \_____/
\ / \ / \ / \
\_____/ x \_____/ \_____/ x \
/ \ / \ / \ /
/ \_____/ \_____/ \_____/
\ / \ / \ / \
\_____/ \_____/ \_____/ \
/ \ / \ / \ /
/ \_____/ x \_____/ \_____/
\ / \ / \ / \
\_____/ \_____/ \_____/ x \
\ / \ / \ /
\_____/ \_____/ \_____/
Turn 2:
_____ _____ _____
/ \ / \ / \
/ \_____/ x \_____/ x \_____
\ / \ / \ / \
\_____/ \_____/ x \_____/ x \
/ \ / \ / \ /
/ \_____/ x \_____/ x \_____/
\ / \ / \ / \
\_____/ \_____/ x \_____/ \
/ \ / \ / \ /
/ \_____/ \_____/ \_____/
\ / \ / \ / \
\_____/ \_____/ \_____/ \
/ \ / \ / \ /
/ \_____/ x \_____/ \_____/
\ / \ / \ / \
\_____/ \_____/ \_____/ \
/ \ / \ / \ /
/ \_____/ \_____/ \_____/
\ / \ / \ / \
\_____/ \_____/ \_____/ \
\ / \ / \ /
\_____/ \_____/ \_____/
Input Data
First line is Q, the quantity of testcases.
Q lines then follow, each with four space-separated values W H N C, where
W is the quantity of columns,
H is the quantity of spaces in any given column,
N is the quantity of turns the simulation should be run for, and
C is a binary string of digits representing the initial state of the grid. The string will be generated by taking the initial starting grid and reading the values from left-to-right in each row.
Answer
Should be Q space-separated integers, corresponding to the quantity of cells remaining after N turns of the simulation in each testcase.
Example
input data:
2
6 5 2 000110000000101110001101001110
18 17 16 001011011100110000100010010101011010011101100000110111000000101000010011011001001100101110111101011000011001101001011101010010111010100010101100000110000110011101111110011000011110000000111100010100100010010000011110111111111100001101101111100100100001100101100100111001000010000100110001000101110010000001
answer:
8 17