You are viewing a single comment's thread. Return to all comments →
Another Erlang solution:
main() -> { ok, [N]} = io:fread("", "~d"), pascal(0, N, []). pascal(C, N, A) -> case N-C of 0 -> ok; _ -> A1 = generate(C, A), print_line(A1), pascal(C+1, N, A1) end. generate(0, _A) -> [1]; generate(1, _A) -> [1, 1]; generate(_N, A) -> {_, A1} = lists:foldl(fun(E, {P, AN}) -> {E, AN ++ [P + E]} end, {0, []}, A), A1 ++ [1]. print_line(A) -> lists:foreach(fun(E) -> io:format("~p ", [E]) end, A), io:format("~n", []).
Pascal's Triangle
You are viewing a single comment's thread. Return to all comments →
Another Erlang solution: