Created
October 27, 2021 15:53
-
-
Save raihanba13/9ca139b3bd0def172ec8609c67101fd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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