function A = gendata2(n,whichstart) % GENDATA2 : Create sample data for Homework 2 % % A = gendata2(n,whichstart) % % This returns an n-by-n array of 0s and 1s % as a starting position for the Game of Life, % for testing CS240A problem 2. % % "whichstart" is an integer that specifies which % which of several starting positions to use. % This Matlab prototype just has three possibilities: % whichstart = 0: all 0s % whichstart = 1: an interesting cell % whichstart = 2: a glider % The MPI and UPC harnesses will have more possibilities % % John R. Gilbert 26 Jan 2006 A = zeros(n,n); if whichstart == 0 return elseif whichstart == 1 cell = [1 1 1 0 1 ; 1 0 0 0 0 ; 0 0 0 1 1 ; 0 1 1 0 1 ; 1 0 1 0 1]; i = round(n/3); j = round(n/5); A(i:i+4,j:j+4) = cell; return elseif whichstart == 2 glider = [1 1 1 ; 1 0 0 ; 0 1 0 ]; i = round(n/3); j = round(n/5); A(i:i+2,j:j+2) = glider; return else error('whichstart must be 0, 1, or 2 for the Matlab data generator'); end;