views:

167

answers:

2

I am trying to write an algorithm to calculate outcomes. But I need help with combinatorics.

Suppose I have to choose 2 numbers from 1 to 10. From the fundamental rule of counting, in the absence of any restriction, the number of possible outcomes is 10 * 10 = 100. (10 possible outcomes in choosing the first number x 10 possible outcomes in choosing the second).

What is the number of possible outcomes given that the first number has to be greater than the second number?

+6  A: 

If you choose:

  • 1: 2 to 10 = 9 possibilities
  • 2: 3 to 10 = 8 possibilities
  • ...
  • 9: 10 = 1 possibility

So

9 + 8 + ... + 2 + 1 = 45

This is called an arithmetic progression the sum is equal to:

f(n) = n * (n+1) / 2 = 9 * 10 / 2 = 45
cletus
For example if the first number I choose is 3 , shouldn't the number of possible options left for the second number be 2? (i.e the numbers 1 and 2). From what you have written, it would be 7.
blackgeneral
@blackgeneral: I've taken the approach of choosing a number and then all numbers higher than it. You could do it the other way: choose a number and then all numbers below it (which is what you do with 3 yields 1 and 2 instead of 4 through 10). The result will be the same.
cletus
+10  A: 

45.

Imagine your grid of 10x10 pairs. There's a diagonal line from 1,1 to 10,10 where A=B, so those aren't A>B. The line divides the other cases into two halves.. one with A>B and one with B < A. Each of these partitions are equal size. There's 90 values left (10 taken by the diagonal line) so there are 45 pairs where A > B.

SPWorley
The grid is a useful analogy for 2 variables and I certainly think about Backgammon and similar things in those terms but it quickly falls down when you get to 3 or more. My approach is a more robust and general way of thinking about combinatorial problems.
cletus