~statianzo/sevenlangs

5c4cec6c39b63404febd4084150bb059e72ae102 — Jason Staten 1 year, 10 months ago 6fcdf67
erlang: cracking the coding interview 8.1
1 files changed, 14 insertions(+), 0 deletions(-)

A erlang/steps.erl
A erlang/steps.erl => erlang/steps.erl +14 -0
@@ 0,0 1,14 @@
-module(steps).
-export([permutations/1, combinations/1]).

% Cracking the Coding Interview 8.1
% Go up N steps 1, 2, or 3 at a time

% Count of permutations
permutations(0) -> 0;
permutations(1) -> 1;
permutations(2) -> 2;
permutations(Steps) -> permutations(Steps - 1) + permutations(Steps - 2) + permutations(Steps - 3).

% Brute force list of all combinations O(N^3)
combinations(N) -> [{X, Y, Z} || X <- lists:seq(0, N), Y <- lists:seq(0, N), Z <- lists:seq(0, N), (X + Y * 2 + Z * 3 == N)].
\ No newline at end of file