-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)].