ITコンサルの日常

ITコンサル会社に勤務する普通のITエンジニアの日常です。

17個を任意個組み合わせたらいくつになる?

最大17メッセージが任意の組み合わせで出力される、というような処理に対して、誰かがテストケース数を数えたところ、8,100ケースになるという。
まあ、どうせ自動化も出来ないし、そんなにやらないんでしょ?とか思いつつ、ほんとかどうか計算してみた。
多分計算式は、\sum_{n=1}^{17}\tiny 17 \normal C_nな感じのはず。(コンビネーションがうまく書けん。。)
で、こいつを計算するプログラム。

Function combination(a, b)
                bunsi = 1
                bunbo = 1

                current = a
                For i=1 to b
                                bunsi = bunsi * current
                                bunbo = bunbo * i
                                current = current - 1
                Next

                combination = bunsi / bunbo
End Function

Dim result
Dim combinationResult
result = 0
For j=1 to 17
        combinationResult = combination(17, j)
        WScript.Echo "combination(17," & j & ") = " & combinationResult
        result = result + combinationResult
Next

WScript.Echo "result = " & result

結果。

combination(17,1) = 17
combination(17,2) = 136
combination(17,3) = 680
combination(17,4) = 2380
combination(17,5) = 6188
combination(17,6) = 12376
combination(17,7) = 19448
combination(17,8) = 24310
combination(17,9) = 24310
combination(17,10) = 19448
combination(17,11) = 12376
combination(17,12) = 6188
combination(17,13) = 2380
combination(17,14) = 680
combination(17,15) = 136
combination(17,16) = 17
combination(17,17) = 1
result = 131071

というわけで、131,071ケースになった。うーん、どうやって8,100って出てきたんだろう。。