Sha256: 8aae36edccc2b17214fd6ede8f87f3fe2c2658eb59c91ab9bd1a1dcef8d94d2d
Contents?: true
Size: 752 Bytes
Versions: 40
Compression:
Stored size: 752 Bytes
Contents
-module(example). -export([gen_pascals_triangle/1, test_version/0]). gen_pascals_triangle(N) when N < 0 -> -1; gen_pascals_triangle(0) -> []; gen_pascals_triangle(N) -> gen_pascals_triangle_helper(1, N, []). gen_pascals_triangle_helper(Count, N, CurrentResult) -> case Count > N of true -> CurrentResult; false -> gen_pascals_triangle_helper( Count + 1, N, CurrentResult ++ gen_next(CurrentResult)) end. gen_next([]) -> [[1]]; gen_next(CurrentResult) -> LastRowDropLast = lists:droplast(lists:last(CurrentResult)), ReverseLastRowDropLast = lists:reverse(LastRowDropLast), ZipList = lists:zipwith( fun(X, Y) -> X + Y end, LastRowDropLast, ReverseLastRowDropLast), [[1] ++ ZipList ++ [1]]. test_version() -> 1.
Version data entries
40 entries across 40 versions & 1 rubygems