I think there is no closed formula, but it's posible to calculate it using recursion (or a loop). From the end, add 1 for terminating questions and multiply by 2 for non terminating ones.<p><pre><code> len(question_paths(10,[1,5])) # 274
2×(1+2×2×2×(1+2×2×2×2×1))
len(question_paths(10,[6,8])) # 448
2×2×2×2×2×2×(1+2×(1+2×1))
len(question_paths(10,[0,1])) # 258
(1+(1+2×2×2×2×2×2×2×2×1))
len(question_paths(10,[8,9])) # 768
2×2×2×2×2×2×2×2×(1+(1+1))</code></pre>