Last active
August 27, 2019 21:01
-
-
Save fgalassi/6f37650c2496d7dd1edc to your computer and use it in GitHub Desktop.
This file contains 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
% The beauty of the right programming paradigm. | |
% Conway's Game of life in 4 lines of Octave code. | |
function new = life(board) | |
neighbours = conv2(board, [1 1 1; 1 0 1; 1 1 1], 'same') | |
new = neighbours == 3 | (neighbours == 2 & board) | |
end | |
% Create a 100x100 board and run the game in a GUI | |
board = rand(100) > 0.6 | |
while (true) | |
spy(board); drawnow; pause(0.3) | |
board = life(board) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment