Skip to content

Instantly share code, notes, and snippets.

@fgalassi
Last active August 27, 2019 21:01
Show Gist options
  • Save fgalassi/6f37650c2496d7dd1edc to your computer and use it in GitHub Desktop.
Save fgalassi/6f37650c2496d7dd1edc to your computer and use it in GitHub Desktop.
% 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