Created
June 9, 2017 06:09
-
-
Save lvidarte/b75c30e051e6ea6dccc58efddea76e6b 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
#!/usr/bin/python3 | |
""" | |
Author: Leo Vidarte <http://nerdlabs.com.ar> | |
This is free software, | |
you can redistribute it and/or modify it | |
under the terms of the GPL version 3 | |
as published by the Free Software Foundation. | |
""" | |
""" | |
Las transiciones dependen del número de células vecinas vivas: | |
* Una célula muerta con exactamente 3 células vecinas vivas "nace" | |
(al turno siguiente estará viva). | |
* Una célula viva con 2 ó 3 células vecinas vivas sigue viva. | |
* En otro caso muere o permanece muerta (por "soledad" o "superpoblación"). | |
""" | |
DEAD = 0 | |
ALIVE = 1 | |
def print_board(board): | |
for row in board: | |
print(' '.join(['.' if col == DEAD else '#' for col in row])) | |
def get_board_size(board): | |
width = len(board[0]) # explícito mejor que implícito | |
height = len(board) | |
return (width, height) | |
if __name__ == '__main__': | |
# Glider | |
board = [ | |
[0, 0, 0, 0, 0, 0, 0, 0], | |
[0, 0, 0, 1, 0, 0, 0, 0], | |
[0, 0, 0, 0, 1, 0, 0, 0], | |
[0, 0, 1, 1, 1, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0], | |
[0, 0, 0, 0, 0, 0, 0, 0], | |
] | |
print_board(board) | |
width, height = get_board_size(board) | |
print("\nwidth {}, height {}".format(width, height)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment