I am trying to figure out a formula to use for figuring out the number of combinations I can create by rearranging two distinct object types, both of which have distinct numbers of themselves.
I essentially want a Combination with Repetition (i.e. (n+r−1)!/r!(n−1)!) but I can only have a certain number of items per object type. What would the modification need to be to account for this?
To give more context, I am trying to find a pattern for the Climbing Stairs problem, in which a person needs to climb x number of stairs by either taking 1 step or 2 steps at a time. The solution involves finding the unique number of ways that a person can make their trek to the top of the stairs.
To break this problem down, I started figuring out the maximum array length and then working down to the minimum array, which would vary depending upon whether the count of stairs x is odd or even. From there, I can see that the number of unique paths for a given number of stairs grows in a Fibonacci sequence, which I could use to solve the problem fairly easily programmatically, but I have a nagging curiosity about what mathematical formula I would need to apply to generate the unique numbers of intermittent arrays.
To illustrate the point further, let's say I have 6 steps. This means that:
- I can take 13 unique paths to get to the top of the 6th stair (13 being the 6th number in the Fibonacci sequence)
- I can take a maximum of 6 steps of 1 stair at-a-time
- I can take a combination of 5 steps with 1 double step and 4 single steps
- I can take a combination of 4 steps with 2 double steps and 2 single steps
- I can take a minimum of 3 steps of 2 stairs at-a-time
This is the full break down of the unique arrays for 6 steps, traversed by either 1 step or 2:
// Number of steps to traverse = 6
// Total number of unique paths = 13 == (1 + 5 + 6 + 1)
// array length = 6
// number of paths = 1
[1,1,1,1,1,1]
// array length = 5
// number of paths = 5
// items: 1 two, 4 ones
[2,1,1,1,1]
[1,2,1,1,1]
[1,1,2,1,1]
[1,1,1,2,1]
[1,1,1,1,2]
// array length = 4
// number of paths = 6
// items: 2 twos, 2 ones
[2,2,1,1]
[2,1,2,1]
[2,1,1,2]
[1,2,1,2]
[1,1,2,2]
[1,2,2,1]
// length 3
// number of paths = 1
// items: 3 twos
[2,2,2]