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

Version Path
trackler-2.2.1.180 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.179 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.178 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.177 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.176 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.175 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.174 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.173 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.172 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.171 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.170 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.169 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.167 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.166 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.165 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.164 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.163 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.162 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.161 tracks/erlang/exercises/pascals-triangle/src/example.erl
trackler-2.2.1.160 tracks/erlang/exercises/pascals-triangle/src/example.erl