MATCH = 0.1
NO_MATCH = 0.9
percentages = [
NO_MATCH**4,
NO_MATCH**3 * MATCH * 4,
NO_MATCH**2 * MATCH**2 * 6, # 12, 13, 14, 23, 24, 34
NO_MATCH * MATCH**3 * 4,
MATCH**4
]
sum = 0.0
percentages.each_with_index do |pct, matches|
puts "%d matches %.2f%% of the time averages %.2f matched (%d matchings)" % [matches, pct, matches * pct, pct * 10000 * 10000]
sum += pct * matches
end
puts sum
Output
0 matches 0.66% of the time averages 0.00 matched (65610000 matchings)
1 matches 0.29% of the time averages 0.29 matched (29160000 matchings)
2 matches 0.05% of the time averages 0.10 matched (4860000 matchings)
3 matches 0.00% of the time averages 0.01 matched (360000 matchings)
4 matches 0.00% of the time averages 0.00 matched (10000 matchings)
0.4