The TransCompilator

Solved LeetCode program · 225 of 1,000

#0289 · Game of Life

Medium Array chunk-05.md

Original English source

Keep a shared board holding 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, and 0. Keep a shared rowsteps holding -1, -1, -1, 0, 0, 1, 1, and 1. Keep a shared colsteps holding -1, 0, 1, -1, 1, -1, 0, and 1. Keep a shared neighbors of 0.

To count from row (a whole number) with column (a whole number). Set neighbors to 0.
For every step from 0 to 7.
The r is row plus item step of rowsteps. The c is column plus item step of colsteps. If r is at least 0 and r is less than 4 and c is at least 0 and c is less than 3 and item (r times 3 plus c) of board is 1, add 1 to neighbors.

The future is a list of 12 zeros.
For every cell from 0 to 11.
The row is cell divided by 3. The column is cell modulo 3. Count from row with column. The live is item cell of board. The nextvalue is 0. If live is 1 and neighbors is at least 2 and neighbors is at most 3, set nextvalue to 1. If live is 1 and neighbors is less than 2, set nextvalue to 0. If live is 1 and neighbors is more than 3, set nextvalue to 0. If live is 0 and neighbors is 3, set nextvalue to 1. Set item cell of future to nextvalue.

For each value in future, show value.

Open in Playground Browse all 1,000 problems

Expected stdout

0
0
0
1
0
1
0
1
1
0
1
0