From: Siraaj Khandkar Date: Wed, 8 Aug 2012 23:19:56 +0000 (-0400) Subject: No need to recalculate X(W) and Y(H) again. X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=681949204b5348589f8935601c761631a75f341b;p=cellular-automata.git No need to recalculate X(W) and Y(H) again. --- diff --git a/003/src/life.erl b/003/src/life.erl index 2e7114c..806d2cb 100644 --- a/003/src/life.erl +++ b/003/src/life.erl @@ -15,17 +15,17 @@ bang(Args) -> [X, Y] = [atom_to_integer(A) || A <- Args], Board = init_board(X, Y), - life_loop(Board). + life_loop(X, Y, Board). %% ============================================================================ %% Internal %% ============================================================================ -life_loop(Board) -> +life_loop(X, Y, Board) -> ok = do_print_board(Board), timer:sleep(?INTERVAL), - life_loop(next_generation(Board)). + life_loop(X, Y, next_generation(X, Y, Board)). do_print_board(Board) -> @@ -57,10 +57,7 @@ state_to_char(0) -> ?CHAR_DEAD; state_to_char(1) -> ?CHAR_ALIVE. -next_generation(Board) -> - H = array:size(Board), - W = array:size(array:get(0, Board)), - +next_generation(W, H, Board) -> array:map( fun(Y, Row) -> array:map(