Conway's 3D Game of Life

Problem #126

Tags: simulation timed

Who solved this?

Previous:Conway's Hexagonal Game of Life Next:NAND


Now let's include the third dimension! Instead of a field of squares existing on a plane, let's instead imagine a 3-dimensional lattice of cubes.

As before, cubes existing at the edge can "see" cubes existing on the other edge. So the topmost layer are neighbors to the bottommost layer, the leftmost to the rightmost, and the frontmost to the rearmost. Previously we could visualize our 2-dimensional plane wrapping around the surface of a torus, but good luck spatially visualizing the 4-dimensional object required to accurately map our "wrapped" lattice of cubes.
Perhaps we had better come up with the solution quickly, before our heads begin to hurt!

Problem Statement

Input Data
First line is Q, the quantity of testcases.
Q lines then follow, each with four space-separated values W H D N C, where W is the quantity of rows in the lattice, H is the quantity of columns in the lattice, D is the quantity of layers in the lattice, 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 lattice. The string will be generated by taking the initial starting lattice and reading the values from left-to-right in each row, working down from the topmost layer.

Answer
Should be Q space-separated integers, corresponding to the quantity of cells remaining after N turns of the simulation in each testcase.

You have just 3 minutes to solve the problem after you are given your input data; so please reload the page to get new input before calculating and submitting the answer.

Example

input data:
2
5 4 3 5 001011010101011000111010100011001010000111011001101111100000
6 5 5 8 101010011001100010100000011011110011011110100011000110001100001010100110011110110001100010011110100000001110110100000110011000000110111010011111010001

answer:
18 56
You need to login to get test data and submit solution.