Created
October 15, 2016 16:33
-
-
Save not-much-io/67b229f7f78890362ce42f9498109194 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
@spec new_grid(pos_int, pos_int) :: grid | |
def new_grid(height, width), do: new_grid(height, width, []) | |
@spec new_grid(pos_int, pos_int, [cell_state]) :: grid | |
defp new_grid(h, w, acc) | |
defp new_grid(0, _w, acc), do: acc | |
defp new_grid(h, w, acc), do: new_grid(h - 1, w, [new_grid_line(w) | acc]) | |
@spec new_grid_line(pos_int, [cell_state]) :: [cell_state] | |
defp new_grid_line(width, acc \\ []) | |
defp new_grid_line(0, acc), do: acc | |
defp new_grid_line(width, acc) do | |
rand_state = Enum.random([:alive, :dead]) | |
new_grid_line(width - 1, [rand_state | acc]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment