Last active
December 20, 2015 08:19
-
-
Save avdi/6099628 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
def next_state | |
(board, x, y) -> | |
cell = cell_at(board, x, y) | |
live_count = live_neighbors(board, x, y) | |
next_state(cell, live_count) | |
end | |
("o", live_count) when live_count in 2..3 -> "o" | |
("o", _) -> "." | |
(".", live_count) when live_count === 3 -> "o" | |
(".", _) -> "." | |
(_, x, y) when (x < 0 or y < 0) -> "." | |
# This would internally define both next_state/3 and next_state/2 | |
# Since these are distinctions that the user largely doesn't care about |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment