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.
Next: Body Count!
Up: Procedures
Previous: Solution
Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 14:10:26 GMT 1996