3 ms·
The number of paths is the sum of 2^(y - x) over each pair (x, y) such that the x-th terminating question is the y-th question overall, plus 2^(number of non-te
by Chinjut 2y ago
The number of paths is the sum of 2^(y - x) over each pair (x, y) such that the x-th terminating question is the y-th question overall, plus 2^(number of non-terminating questions overall).
In other words, for each possible termination point (including making it all the way through), consider how many non-terminating questions come before that termination point, raise 2 to that power, and then sum these all up.
Thus, len(question_paths(totq, term)) is equal to sum([2**(term[i] - i) for i in range(len(term))]) + 2**(totq - len(term)).
- yoshicoder 2y agoI got this formula as well. I viewed it as an expanding binary tree where you end up cutting branches early, similar to a alpha beta pruning search tree