Next: Body Count!
Up: Procedures
Previous: Solution
CSHIFT was used to count the number of neighbouring live cells. You
can optimise the code to do the count with only four CSHIFT operations
instead of eight. This requires the use of a temporary array the same
size as board. For each array element,
- create the temporary by adding the current value of board to
the value of the left and right partners (two CSHIFT s)
- find the upper and lower partners for this temporary array (two
more CSHIFT s) and add these to the temporary array
- each element now contains the number of neighbours, plus the
original value of the cell. Subtract the original state to obtain the
number of neighbours with four CSHIFT s.
Go back to Notes
Next: Body Count!
Up: Procedures
Previous: Solution
©University of Liverpool, 1997
Thu May 29 10:11:26 BST 1997Not for commercial use.