% mfile life array % This program breeds and kills fish using array operations % % fish(i,j) = 1 if fish present at (i,j), 0 otherwise % % Save current state oldfish=fish(2:d-1,2:d-1); % % Get the count of neighbors neighborcount = fish(1:d-2,2:d-1) + ... fish(1:d-2,1:d-2) + ... fish(1:d-2,3:d) + ... fish(2:d-1,1:d-2) + ... fish(2:d-1,3:d) + ... fish(3:d,2:d-1) + ... fish(3:d,1:d-2) + ... fish(3:d,3:d); % % Breed if exactly three neighbors % Die of loneliness if less than 2 neighbors or % of starvation is more than 3 neighbors % fish(2:d-1,2:d-1) = (~oldfish & (neighborcount == 3)) | ... (oldfish & ((neighborcount == 2) | (neighborcount == 3)));