Skip to content

Instantly share code, notes, and snippets.

@raihanba13
Created October 27, 2021 15:53
Show Gist options
  • Save raihanba13/9ca139b3bd0def172ec8609c67101fd0 to your computer and use it in GitHub Desktop.
Save raihanba13/9ca139b3bd0def172ec8609c67101fd0 to your computer and use it in GitHub Desktop.
n = 15
A = randi([0 1], n,n)
while 1
spy(A)
% here is the logic of dead or alive
% we will check full row first, then we will move to next column
for i=2:n-1
%fprintf('%d\n', i)
for j=2:n-1
% we take a 3X3 matrix
row_start = i;
column_start = j;
%{
fprintf('\n%d %d', i, j);
fprintf('\n%d', temp_sum);
fprintf('\n%d', A(i,j));
%}
temp_matrix = A(row_start-1:i+1, column_start-1:j+1);
temp_sum = sum(sum(temp_matrix));
if A(i,j) == 1 && temp_sum < 2
A(i,j) = 0;
elseif A(i,j) == 1 && temp_sum > 3
A(i,j) = 0;
elseif A(i,j) == 0 && temp_sum == 3
A(i,j) = 1;
end
% fprintf('\n%d', A(i,j));
% display(temp_matrix);
% pause(2);
end
end
pause(2)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment