UNPKG

combination-and-permutation

Version:

Combination or Permutation computation

40 lines (33 loc) 1.14 kB
# Combination and Permutation computation 组合和排列计算 ## 1. Combination 组合 Every combination has **same probability**. 每一种组合都有**相同的概率**。 execute combination(3) 10000 times, we got: 执行了10000次combination(3),结果如下: '[2,3]' => 1469, '[1,2]' => 1370, '[1,2,3]' => 1447, '[3]' => 1400, '[1,3]' => 1413, '[1]' => 1471, '[2]' => 1430 ## 2. Permutation 排列 Obviously, permutations and combinations are different, and permutations with different numbers have **different probabilities**。 很明显,排列跟组合不同,不同数量数字的排列具有**不同的概率**。 execute permutation(3) 10000 times, we got: 执行了10000次permutation(3),结果如下: '[3]' => 1417, '[2,1,3]' => 264, '[2,3]' => 671, '[3,1,2]' => 267, '[3,1]' => 708, '[1,3]' => 698, '[2]' => 1412, '[2,3,1]' => 230, '[3,2,1]' => 226, '[1,2,3]' => 260, '[3,2]' => 746, '[1,2]' => 750, '[1,3,2]' => 225, '[1]' => 1414, '[2,1]' => 727