Showing posts with label combinations. Show all posts
Showing posts with label combinations. Show all posts

Thursday, 5 February 2026

Why Is 313131 An Interesting Number?


Recently a friend of mine who was staying at a hotel revealed that the six digit security code for the room was 313131. This looked like an easy code to crack and I was reminded of a post that I'd made recently titled Passcodes and Repeated Digits in November of 2025. Figure 1 shows the probabilities for the number of distinct digits chosen:


Figure 1

So the code 313131 is indeed easy to crack, requiring only a maximum of 62 attempts or 31 attempts on average. However, what was of most interest to me regarding 313131 was its prime factorisation:$$ 313131=3 \times 7 \times 13 \times 31 \times 37$$If we rearrange the order of multiplication we get the following:$$ 313131=7 \times 3 \times 13 \times 31 \times 37$$Concatenating these digits we get the number \(73133137\) which is palindromic.

Naturally, I wondered how many other numbers share this property and so I set Gemini to investigate this with the following prompt:

Write a program in Python, tailored for insertion into SageMathCell or a Jupyter notebook, that identifies all composite numbers from 4 up to a user chosen upper limit with the property that the prime factors, when arranged in a suitable order and then concatenated, produce a palindromic number. The default upper limit can be set to 40000. An example of such a number would be 313131 = 3 x 7 x 13 x 31 x 37 that can written as 7 x 3 x 13 x 31 x 37 to produce the palindromic number 73133137 when concatenated. The output of the program should be a table showing number and factorisation followed by a comma separated list of the qualifying numbers.

Naturally this a processor intensive process and my Jupyter notebook struggled mightily to generate the list of suitable numbers. After some time, I decided to restrict the range to between 28000 and 29000 and after further modifications by Gemini, I was able to achieve the following list of numbers:

28072, 28125, 28194, 28224, 28242, 28273, 28308, 28322, 28332, 28416, 28431, 28448, 28585, 28589, 28593, 28601, 28602, 28609, 28620, 28672, 28685, 28692, 28750, 28800, 28812, 28847, 28951

Figure 2 shows the details:


Figure 2

I've incorporated this algorithm into my daily search program that has become somewhat impressive if I do say so myself. See Figure 3 for the results of 28067, my diurnal age today.


Figure 3

The output is generated by the same program but I've just restricted the range to my daily number, rather lazy but it does the job. Remember the prime factorisation takes multiplicity into account. For completeness I'll include the Python code:

import sys

def get_prime_factors(n):
    """Returns a list of prime factors of n."""
    factors = []
    d = 2
    temp = n
    while d * d <= temp:
        while temp % d == 0:
            factors.append(d)
            temp //= d
        d += 1
    if temp > 1:
        factors.append(temp)
    return factors

def is_palindrome(s):
    """Checks if a string is a palindrome."""
    return s == s[::-1]

def distinct_permutations(iterable):
    """
    Yields unique permutations of items in iterable.
    This handles repeated elements efficiently (e.g., [2, 2, 3])
    without generating all n! redundant combinations.
    """
    # Sort the list to start with the lexicographically first permutation
    s = sorted(iterable)
    yield tuple(s)
    
    n = len(s)
    while True:
        # 1. Find the largest index i such that s[i] < s[i+1]
        i = n - 2
        while i >= 0 and s[i] >= s[i+1]:
            i -= 1
        
        if i == -1:
            return # All permutations generated
        
        # 2. Find the largest index j such that s[i] < s[j]
        j = n - 1
        while s[j] <= s[i]:
            j -= 1
        
        # 3. Swap s[i] and s[j]
        s[i], s[j] = s[j], s[i]
        
        # 4. Reverse the sequence from s[i+1] up to the end
        s[i+1:] = s[i+1:][::-1]
        
        yield tuple(s)

def find_palindromic_composites(start_n, end_n):
    results = []
    actual_start = max(4, start_n)

    for n in range(actual_start, end_n + 1):
        factors = get_prime_factors(n)
        
        # Skip primes
        if len(factors) < 2:
            continue
            
        found_property = False
        winning_perm = None
        winning_concat = None
        
        # Use the optimized generator instead of itertools.permutations
        for p in distinct_permutations(factors):
            concat_str = "".join(map(str, p))
            
            if is_palindrome(concat_str):
                found_property = True
                winning_perm = p
                winning_concat = concat_str
                break 
        
        if found_property:
            fact_str = " x ".join(map(str, winning_perm))
            results.append((n, fact_str, winning_concat))

    return results

# --- Configuration ---
LOWER_BOUND = 28000
UPPER_BOUND = 29000

# --- Main Execution ---
print(f"Searching for composite numbers between {LOWER_BOUND} and {UPPER_BOUND}...")
print("-" * 80)
print(f"{'Number':<8} | {'Valid Factor Ordering':<35} | {'Resulting Palindrome'}")
print("-" * 80)

qualifying_numbers = find_palindromic_composites(LOWER_BOUND, UPPER_BOUND)

if not qualifying_numbers:
    print(f"No qualifying numbers found in the range {LOWER_BOUND} to {UPPER_BOUND}.")
else:
    for num, factor_str, pal_str in qualifying_numbers:
        print(f"{num:<8} | {factor_str:<35} | {pal_str}")

    print("-" * 80)
    print("\nComma separated list of qualifying numbers:")
    print(", ".join(str(r[0]) for r in qualifying_numbers))

Monday, 23 June 2025

Lottery Numbers

 


Figure 1

Figure 1 shows the Lotto results for Saturday night 21st June 2025. What's unusual about the numbers is that seven out of the eight numbers are even. I was wondering as to the probability of this happening. To begin with there are 45 numbers to choose from: 22 are even and 23 are odd. See Figure 2.


Figure 2

Looking at the draw we see that the first number drawn was a 6 and this is an even number. The probability of drawing an even number is 22/45. The next three numbers were all even as well and the probabilities are therefore 21/44, 20/43 and 19/42. Then comes the only odd number, 1, and the probability of drawing an odd number is 23/41. The final three numbers are all even with probabilities of 18/40, 17/39 and 16/38. So the probability of this configuration:$$ \text{even, even, even, even. odd, even, even, even}$$is given by:$$\frac{22}{45} \times \frac{21}{44} \times \frac{20}{43} \times \frac{19}{42} \times \frac{23}{41} \times \frac{18}{40} \times \frac{17}{39} \times \frac{16}{38} \approx 0.0023$$However, we're not concerned with that particular order of even and odd numbers. We only want to determine the probability of seven even numbers and one odd number. The odd number could be in the first to eighth position. Each of these eight configurations has the same probability, around 0.0023, so we need to multiply by eight. This gives 0.01820 to five decimal places or a probability of around 1.82% and so$$\text{probability of one odd and seven even numbers } \approx 1.82 \text{%} $$Another way to approach the probability is via combinations. Let's see if we get the same result using this approach. There are \(^{22} \text{C}_{7}\) ways of choosing seven even numbers from the 22 available and \( ^23 \text{C}_1\) ways of choosing an odd number. With no restrictions, there are \( ^45 \text{C}_8 \) ways of choosing eight numbers from the 45 available. Thus:$$ \begin{align} \text{probability } &= \frac{^{22} \text{C}_{7} \times ^{23} \text{C}_1}{^{45} \text{C}_8}\\  \\[-1.5 ex] &=\frac{170544 \times 23}{215553195} \\[-0.5 ex]  \\ &\approx 0.01820 \\[-1.5 ex]  \\ &\approx 1.82\text{%} \end{align} $$So there is agreement. The probability that all the numbers are even would be given by:$$ \begin{align} \text{probability all even } &= \frac{ ^{22} \text{C}_8}{ ^{45} \text{C}_8}\\ \\[-1.5 ex] &\approx 0.00148 \\[-1.5 ex] \\ &\approx 0.148 \text{%} \end{align}$$This is considerably more unlikely than getting seven out of eight!

Sunday, 24 December 2023

Sphenic Generating Number Set

The number associated with my diurnal age today, 27293, has a very interesting property that qualifies it for membership in OEIS A181622 (permalink):


 A181622



Sequence starting with 1 such that the sum of any two distinct terms has three distinct prime factors.



The sequence begins 1, 29, 41, 281, 401, 1089, 1585, 2289, 4629, 27293 and thus the sum of any two of these numbers produces a sphenic number. There are 45 combinations producing the following sums:

1 + 29 = 30 = 2 * 3 * 5
1 + 41 = 42 = 2 * 3 * 7
1 + 281 = 282 = 2 * 3 * 47
1 + 401 = 402 = 2 * 3 * 67
1 + 1089 = 1090 = 2 * 5 * 109
1 + 1585 = 1586 = 2 * 13 * 61
1 + 2289 = 2290 = 2 * 5 * 229
1 + 4629 = 4630 = 2 * 5 * 463
1 + 27293 = 27294 = 2 * 3 * 4549
29 + 41 = 70 = 2 * 5 * 7
29 + 281 = 310 = 2 * 5 * 31
29 + 401 = 430 = 2 * 5 * 43
29 + 1089 = 1118 = 2 * 13 * 43
29 + 1585 = 1614 = 2 * 3 * 269
29 + 2289 = 2318 = 2 * 19 * 61
29 + 4629 = 4658 = 2 * 17 * 137
29 + 27293 = 27322 = 2 * 19 * 719
41 + 281 = 322 = 2 * 7 * 23
41 + 401 = 442 = 2 * 13 * 17
41 + 1089 = 1130 = 2 * 5 * 113
41 + 1585 = 1626 = 2 * 3 * 271
41 + 2289 = 2330 = 2 * 5 * 233
41 + 4629 = 4670 = 2 * 5 * 467
41 + 27293 = 27334 = 2 * 79 * 173
281 + 401 = 682 = 2 * 11 * 31
281 + 1089 = 1370 = 2 * 5 * 137
281 + 1585 = 1866 = 2 * 3 * 311
281 + 2289 = 2570 = 2 * 5 * 257
281 + 4629 = 4910 = 2 * 5 * 491
281 + 27293 = 27574 = 2 * 17 * 811
401 + 1089 = 1490 = 2 * 5 * 149
401 + 1585 = 1986 = 2 * 3 * 331
401 + 2289 = 2690 = 2 * 5 * 269
401 + 4629 = 5030 = 2 * 5 * 503
401 + 27293 = 27694 = 2 * 61 * 227
1089 + 1585 = 2674 = 2 * 7 * 191
1089 + 2289 = 3378 = 2 * 3 * 563
1089 + 4629 = 5718 = 2 * 3 * 953
1089 + 27293 = 28382 = 2 * 23 * 617
1585 + 2289 = 3874 = 2 * 13 * 149
1585 + 4629 = 6214 = 2 * 13 * 239
1585 + 27293 = 28878 = 2 * 3 * 4813
2289 + 4629 = 6918 = 2 * 3 * 1153
2289 + 27293 = 29582 = 2 * 7 * 2113
4629 + 27293 = 31922 = 2 * 11 * 1451

Only one of the numbers (2289) in this set is sphenic itself and, after the initial 1, the next four numbers are prime:

1 = 1
29 = 29
41 = 41
281 = 281
401 = 401
1089 = 3^2 * 11^2
1585 = 5 * 317
2289 = 3 * 7 * 109
4629 = 3 * 1543
27293 = 7^2 * 557

Beyond 27293, the next numbers in the sequence are 74873, 965813, 2536781, 4479197, 36730306, 150318056 and 4527046433. 

It's natural to think about the biprime analog of this sequence and up to 100,000 at least, the members are rather sparse. They are 1, 5, 9, 86 and 212 (permalink). The details are as follows (permalink):

1 = 1
5 = 5
9 = 3^2
86 = 2 * 43
212 = 2^2 * 53

There are 10 combinations of these numbers taken two at a time

1 + 5 = 6 = 2 * 3
1 + 9 = 10 = 2 * 5
1 + 86 = 87 = 3 * 29
1 + 212 = 213 = 3 * 71
5 + 9 = 14 = 2 * 7
5 + 86 = 91 = 7 * 13
5 + 212 = 217 = 7 * 31
9 + 86 = 95 = 5 * 19
9 + 212 = 221 = 13 * 17
86 + 212 = 298 = 2 * 149

Extending to numbers with four distinct prime factors, we get the following initial sequence: 1, 209, 1121, 2989, 11381, 34889, 47701 (permalink). The details are as follows (permalink):

1 = 1
209 = 11 * 19
1121 = 19 * 59
2989 = 7^2 * 61
11381 = 19 * 599
34889 = 139 * 251
47701 = 47701

There are 21 combinations of these numbers taken two at a time

1 + 209 = 210 = 2 * 3 * 5 * 7
1 + 1121 = 1122 = 2 * 3 * 11 * 17
1 + 2989 = 2990 = 2 * 5 * 13 * 23
1 + 11381 = 11382 = 2 * 3 * 7 * 271
1 + 34889 = 34890 = 2 * 3 * 5 * 1163
1 + 47701 = 47702 = 2 * 17 * 23 * 61
209 + 1121 = 1330 = 2 * 5 * 7 * 19
209 + 2989 = 3198 = 2 * 3 * 13 * 41
209 + 11381 = 11590 = 2 * 5 * 19 * 61
209 + 34889 = 35098 = 2 * 7 * 23 * 109
209 + 47701 = 47910 = 2 * 3 * 5 * 1597
1121 + 2989 = 4110 = 2 * 3 * 5 * 137
1121 + 11381 = 12502 = 2 * 7 * 19 * 47
1121 + 34889 = 36010 = 2 * 5 * 13 * 277
1121 + 47701 = 48822 = 2 * 3 * 79 * 103
2989 + 11381 = 14370 = 2 * 3 * 5 * 479
2989 + 34889 = 37878 = 2 * 3 * 59 * 107
2989 + 47701 = 50690 = 2 * 5 * 37 * 137
11381 + 34889 = 46270 = 2 * 5 * 7 * 661
11381 + 47701 = 59082 = 2 * 3 * 43 * 229
34889 + 47701 = 82590 = 2 * 3 * 5 * 2753

Of course, it's not mandatory to start with 1. Suppose in the case of sphenic numbers, we start with 3. The second number must be 27 so that 3 and 27 add to 30, the first sphenic number. When we started with 1, we needed 29 as the second number. After that, we get the following sequence of numbers in the range up to 40,000: 3, 27, 39, 75, 399, 571, 1027, 1387, 3283. The details are as follows:

3 = 3
27 = 3^3
39 = 3 * 13
75 = 3 * 5^2
399 = 3 * 7 * 19
571 = 571
1027 = 13 * 79
1387 = 19 * 73
3283 = 7^2 * 67

There are 36 combinations of these numbers taken two at a time

3 + 27 = 30 = 2 * 3 * 5
3 + 39 = 42 = 2 * 3 * 7
3 + 75 = 78 = 2 * 3 * 13
3 + 399 = 402 = 2 * 3 * 67
3 + 571 = 574 = 2 * 7 * 41
3 + 1027 = 1030 = 2 * 5 * 103
3 + 1387 = 1390 = 2 * 5 * 139
3 + 3283 = 3286 = 2 * 31 * 53
27 + 39 = 66 = 2 * 3 * 11
27 + 75 = 102 = 2 * 3 * 17
27 + 399 = 426 = 2 * 3 * 71
27 + 571 = 598 = 2 * 13 * 23
27 + 1027 = 1054 = 2 * 17 * 31
27 + 1387 = 1414 = 2 * 7 * 101
27 + 3283 = 3310 = 2 * 5 * 331
39 + 75 = 114 = 2 * 3 * 19
39 + 399 = 438 = 2 * 3 * 73
39 + 571 = 610 = 2 * 5 * 61
39 + 1027 = 1066 = 2 * 13 * 41
39 + 1387 = 1426 = 2 * 23 * 31
39 + 3283 = 3322 = 2 * 11 * 151
75 + 399 = 474 = 2 * 3 * 79
75 + 571 = 646 = 2 * 17 * 19
75 + 1027 = 1102 = 2 * 19 * 29
75 + 1387 = 1462 = 2 * 17 * 43
75 + 3283 = 3358 = 2 * 23 * 73
399 + 571 = 970 = 2 * 5 * 97
399 + 1027 = 1426 = 2 * 23 * 31
399 + 1387 = 1786 = 2 * 19 * 47
399 + 3283 = 3682 = 2 * 7 * 263
571 + 1027 = 1598 = 2 * 17 * 47
571 + 1387 = 1958 = 2 * 11 * 89
571 + 3283 = 3854 = 2 * 41 * 47
1027 + 1387 = 2414 = 2 * 17 * 71
1027 + 3283 = 4310 = 2 * 5 * 431
1387 + 3283 = 4670 = 2 * 5 * 467

Obviously, there are many more possibilities to explore here.

Tuesday, 23 November 2021

Numbers As Sums Of Palindromes

I've written about palindromes before in a variety of posts (just type palindromes into the search box for this site) but thus far I've not mentioned the representation of numbers as a sum of palindromes. Figure 1 shows a screenshot of a tweet from Cliff Pickover's Twitter feed:


Figure 1

I came across this tweet not long ago and immediately wrote a program (permalink) in SageMathCell to determine what these palindromic sums were for any given number. Below is the calculation box.


It turns out that for 26532, my diurnal age today, there are 193 different way to represent it as a sum of three palindromes. Here are examples of just a few of them:
  • 11 + 969 +25552
  • 414 + 7337 + 18781
  • 979 + 1111 + 24442
  • 5885 + 6006 + 14641
Most numbers, about 92%, can in fact be represented as a sum of two palindromes in one or more ways. However, 26532 is amongst the 8% minority that cannot. The numbers on either side of it however, can be represented as a sum of two palindromes. The program above can be easily modified to find these palindromes, just replace C = Combinations(P, 3) with C = Combinations(P, 2). Here are the results:
  • 26531 = 979 + 25552
  • 26533 = 171 + 26362 = 1991 + 24542
Between 26500 and 27000, the numbers that cannot be represented as a sum of two palindromes are:
26502, 26512, 26522, 26532, 26542, 26572, 26582, 26592, 26602, 26612, 26622, 26632, 26642, 26672, 26682, 26692, 26702, 26712, 26722, 26732, 26742, 26772, 26782, 26792, 26802, 26812, 26822, 26832, 26842, 26872, 26882, 26892, 26902, 26912, 26922, 26932, 26942, 26952, 26972, 26982, 26992
There are 41 such numbers representing 8.20% of the total of 500 numbers. It can be noted that all the numbers in this range are even and all end in 2. This pattern seems to repeat for other ranges. 

That's about it, a simple yet interesting property that divides numbers into two categories: those that can be represented as a sum of two palindromes and those that cannot. 

Friday, 7 May 2021

The Egg Drop Numbers

It's always a delight to suddenly come across a new category of numbers that I haven't heard of before. Today I turned 26332 days old and discovered that this number is a member of OEIS A116082: 


 A116082

a(n) = C(n,7) + C(n,6) + C(n,5) + C(n,4) + C(n,3) + C(n,2) + C(n,1).


The sequence members, up to 26332, are as follows:

0, 1, 3, 7, 15, 31, 63, 127, 254, 501, 967, 1815, 3301, 5811, 9907, 16383, 26332

What caught my attention however, was a reference in the OEIS comments to The Egg Drop Numbers. This led to an interesting investigation, beginning with the so-called Two Egg Problem that is clearly stated on this site:

Egg Dropping Puzzle (2-egg, 100-floor version)
“Figure out the highest floor of a 100-floor building an egg can be dropped without breaking,  given two eggs”. The Egg Dropping Puzzle is a mathematical puzzle that has been around the internet for some time now, which is known to be adopted in interviews of major companies like Google, Microsoft, Accenture and even Hewlett Packard. You are to determine the minimum number of attempts required in the worst case scenario to find the critical floor.

 Assumptions in the Egg Dropping Puzzle:
  • The two eggs are identical.
  • If an egg does not break by dropping from a certain floor, it will not break dropping from any floor below that.
  • If an egg breaks by dropping on a certain floor, it will break dropping from any floor above that.
  • An egg may break by dropping on the 1st floor.
  • An egg may not break by dropping even on the 100th floor.
I won't repeat the explanation of how to solve this problem here, because that's provided on the site, but I will display the formula that is established viz.:
With \(x\) eggs and \(m\) trials, the maximum number of floors of a building we can test is given by: $$\binom {m}{1} +\binom {m}{2} + \dots + \binom {m}{x}$$

The site provides a spreadsheet that lists a wide range of results for different values of \(x\) and \(m\). Figure 1 shows an excerpt from the spreadsheet with some annotations added.


Figure 1

The members of OEIS A116082 appear as the entries in far right column under 7 eggs. Thus it is seen that:$$26332=\binom {16}{1} +\binom {16}{2} + \binom {16}{3}+\binom {16}{4} + \binom {16}{5} + \binom {16}{6} + \binom {16}{7}$$Thus, armed with 7 eggs, we can, with at most 16 trials, find the critical floor in a building with as many as 26332 floors. This is rather remarkable I think. 

Without the egg dropping association, OEIS A116082 would be rather bland but now I've become aware of a whole new category of numbers, The Egg Drop Numbers. On June 6th, 2025 (the anniversary of D-Day by the way), I will enjoy the next egg drop number, 27823, which is the maximum number of floors for which someone, armed with 9 eggs, will be able to determine the critical floor with at most 15 trials.

One last point to make is that, in the unlikely event that the number of eggs \(x\) exceeds the number of trials \(m\), then the formula becomes:$$\binom {m}{1} +\binom {m}{2} + \dots + \binom {m}{\min(x, m)}$$

Monday, 10 June 2019

Lotto Loser

Figure 1
Figure 1 shows my Australian Gold Lotto results for Saturday night, the 1st June 2019. Once again, a prize of any sort eluded me but I was naturally struck by the fact that across my four games, I had all the winning numbers: 6, 9, 20, 25, 27 and 31 with 9 being chosen twice and each of the other numbers once.

Immediately, I wondered what was the probability of such an occurrence. Specifically, what were my chances of choosing all six winning numbers across four games but not have more than three winning numbers in any one game (prizes are awarded for four or more winning numbers). I'm going to ignore supplementary numbers in this analysis and only consider the red winning numbers.

I've pondered Lotto probabilities before in an earlier post titled Losing at Lotto (17th March 2018) in which I investigated the probability of not getting any numbers (red or blue) in four games. That turned out to be about 0.0066 or 0.66%. I made other posts about Lotto including Lotto Simulations (20th October 2018), The Mersenne Twister (20th January 2019 )and Oz Lotto (31st May 2017).

Anyway, back to problem under consideration. In no game can I have more than three winning numbers or else I'd win a prize. So a constant for each game is that I need to choose 3 losing numbers out of the 39 available. There are 39 x 38 x 37 ways of doing this. What I've done in Figure 2 is to show the range of minimum possible configurations (where there is no repetition of winning numbers across the four games). From those configurations I've worked out the remaining possibilities, given the constraints that there cannot be more than three winning numbers in any game and there cannot be a repeated number in any game.

Figure 2

We'll tackle each in turn:

Configuration 1, top left, multiplying rows: 

6 x 5 x 4 x 39 x 38 x 37
3 x 2 x 1 x 39 x 38 x 37
45 x 44 x 43 x 39 x 38 x 37
45 x 44 x 43 x 39 x 38 x 37   

Configuration 2, top middle, multiplying rows: 

6 x 5 x 43 x 39 x 38 x 37 
4 x 3 x 43 x 39 x 38 x 37
2 x 1 x 43 x 39 x 38 x 37
45 x 44 x 43 x 39 x 38 x 37   

Configuration 3, top right, multiplying rows: 

6 x 5 x 4 x 39 x 38 x 37
3 x 2 x 43 x 39 x 38 x 37
1 x 44 x 43 x 39 x 38 x 37 
45 x 44 x 43 x 39 x 38 x 37 

Configuration 4, bottom left, multiplying rows:

6 x 5 x 43 x 39 x 38 x 37
4 x 3 x 43 x 39 x 38 x 37
2 x 44 x 43 x 39 x 38 x 37
1 x 44 x 43 x 39 x 38 x 37

Configuration 5, bottom middle, multiplying rows:

6 x 5 x 4 x 39 x 38 x 37
3 x 44 x 43 x 39 x 38 x 37
2 x 44 x 43 x 39 x 38 x 37
1 x 44 x 43 x 39 x 38 x 37   

Each product on each line is divided by \(^{45}p_5\) or 45 x 44 x 43 x 42 x 41 x 40 = 5,864,443,200 and all lines are multiplied together within a configuration. The probabilities for all configurations are then added because they are mutually exclusive. The results are shown in Figure 2 (a spreadsheet snapshot).

Figure 3
The chances work out to be slightly less than two in ten million (1.89), whereas the probability of getting all six numbers in one game is slightly more than one in ten million (1.23). To me, this result seems far too low. 

Another approach involves the use of combinations, which I tried initially but dismissed because the probability seemed far too high. However, I'll revisit that approach here and see what I come up with a second time around. The essential points in this approach are:

  • there are four games
  • there are 45C6 ways of choosing the six numbers in each game
  • up to three winning numbers (6C3) can be chosen in each game
  • conversely, there must be three losing numbers (38C3) in each game
  • all six winning numbers must be chosen across the four games

The configurations shown in Figure 3 can be reused but this time with combinations. See Figure 4 below.

Figure 4

Each of the line above needs to be divided by 45C6 to determine the probabilities which turn out to be:
  • 0.00638281628563513 for configuration 1 
  • 0.321868017603801 for configuration 2 
  • 0.0548922200564621 for configuration 3 
  • 0.472073092485574 for configuration 4 
  • 0.161017178832289 for configuration 5
  • 1.01623332526376 overall
Clearly something is terribly wrong as probability cannot exceed 1. Below is the SageMath code I used for the calculation:
C11=binomial(6,3) #6C3 x 39C3 C12=binomial(3,3) #3C3 x 39C3 C13=binomial(45,3) #45C3 x 39C3
C14=binomial(45,3) #45C3 x 39C3
C21=binomial(6,2)*binomial(43,1) #6C2 x 43C1 x 39C3
C22=binomial(4,2)*binomial(43,1) #4C2 x 43C1 x 39C3
C23=binomial(2,1)*binomial(43,1) #2C1 x 43C1 x 39C3 C24=binomial(45,3) #45C3 x 39C3 C31=binomial(6,3) #6C3 x 39C3
C32=binomial(3,2)*binomial(43,1) #3C2 x 43C1 x 39C3
C33=binomial(1,1)*binomial(44,2) #1C1 x 44C2 x 39C3
C34=binomial(45,3) #45C3 x 39C3 C41=binomial(6,2)*binomial(43,1) #6C2 x 43C1 x 39C3
C42=binomial(4,2)*binomial(43,1) #4C2 x 43C1 x 39C3 C43=binomial(2,1)*binomial(44,2) #2C1 x 44C2 x 39C3
C44=binomial(1,1)*binomial(44,2) #1C1 x 44C2 x 39C3
C51=binomial(6,3) #6C3 x 39C3 C52=binomial(3,1)*binomial(44,2) #3C1 x 44C2 x 39C3
C53=binomial(2,1)*binomial(44,2) #2C1 x 44C2 x 39C3 C54=binomial(1,1)*binomial(44,2) #1C1 x 44C2 x 39C3
C1=n(C11*C12*C13*C14*(binomial(39,3)/binomial(45,6))^4)
C2=n(C21*C22*C23*C24*(binomial(39,3)/binomial(45,6))^4)
C3=n(C31*C32*C33*C34*(binomial(39,3)/binomial(45,6))^4)
C4=n(C41*C42*C43*C44*(binomial(39,3)/binomial(45,6))^4)
C5=n(C51*C52*C53*C54)*((binomial(39,3)/binomial(45,6))^4)
print C1, C2, C3, C4, C5
p=C1+C2+C3+C4+C5
print p
I'll need to return to this and try to resolve the problem. My first result is vanishingly small and my second is impossibly high!

Saturday, 17 March 2018

Losing at Lotto

Figure 1
Each week, I play four games in the Saturday Night Gold Lotto and, though I seldom win a prize, I always manage to choose at least one winning number. For each game in this particular lottery, you must choose six numbers out of a total of 45 (numbered from 1 to 45) and, during the draw, six main numbers are chosen as well as two supplementary numbers (so there are eight "winning" numbers). If you select all six main numbers, you share in the first division prize of $4,000,000. The amount is divided among the total numbers of winners which on average is between four and five. Combinations of main numbers and supplementary numbers win lesser prizes. Tonight, I was surprised to see that I'd managed to select none of the eight winning numbers. I've attached a screenshot of my results (see Figure 1). This got me wondering what was the probability of doing this? It had to be fairly low because I couldn't recall it ever happening to me before.

To tackle the problem, let's consider a single game in which there are 37 "losing" numbers along with the eight "winning" numbers. How many ways can these 37 numbers be chosen if I am selecting six numbers at a time, disregarding the order in which they are chosen. There are \( ^{37}C_6 \)= 2516 ways to do this out of a total of \(^{45}C_6\) = 8815 possibilities. So the probability of choosing six losing numbers in a single game is 2516/8815 which is almost 0.29 or 29%. Thus for every 100 games I play, around 29 will result in my missing all of the winning numbers. However, it is highly unlikely that I'll "succeed" in doing this four times in a row because each game is independent of the other and so the probabilities are multiplied. Thus the fraction 2516/8815 is raised to the fourth power and this gives a probability of about 0.0066 or 0.66%. In other words, if I play 10,000 sets of four games each, I'll only miss all of the winning numbers about 66 times. Tonight was one of those times.

Below is shown the WolframAlpha calculation:


For an earlier post on the probability of winning at Oz Lotto, follow this link.

UPDATE: on Saturday March 6th 2021 I also managed to select no numbers out of four games. Thus it is almost three years since this last happened. Figure 2 shows a screenshot of the results.

Figure 2

Sunday, 11 February 2018

The Mathematics of Chess Pairings

There was a recent article is ChessBase regarding a problem that had arisen last year involving the world's highest ranked woman player, Hou Hifan. The article began:
The Gibraltar Masters wrapped up Thursday, with Levon Aronian in first place. This year Round Ten passed without incident, in contrast to 2017 when, on February 2nd, the story of the day was a rare scandal involving women's World Champion Hou Yifan deliberately losing a game in protest of the high number of women she was paired against. She was further confounded when a similarly unlikely string of pairings happened in October at the Isle of Man Open. Johannes Meijer looks at the odds in detail. Hou did not return to Gibralter in 2018, but instead competed in the Tata Steel Chess Masters.
Imagine, you are at a tournament with 255 players of which 43 are female. You are to play ten rounds. How many female opponents would you expect to face? Three? Five? I am pretty sure you wouldn't say seven. Yet, this was exactly the number of female players Hou Yifan faced at the Gibraltar Open 2017 when, a year ago today, she threw her last game in protest of these seemingly odd pairings.
The article goes on to ask the question: How probable is such a pairing? Could it have happened by chance at all? Well, the approach to solving this problem involves the hypergeometric distribution, a discrete probability distribution commonly covered in high school probability and statistics courses. Wikipedia describes it thus:


Thus to find how likely, or unlikely, Hou's pairings were we only have to replace "green marbles" with women and "red marbles" with men. So k=7, K=43, N=255, n-10, n-k=3 and N-K=212. Substituting into the formula we get:$$P(X=7)=\frac{^KC_k \text{ . } ^{N-K}C_{n-k}}{^NC_n}=\frac{^{43}C_7 \text{ . } ^{212}C_{3}}{^{255}C_{10}}\approx 0.000188 $$Thus it seen that the likelihood is very small that this could happen and yet the pairings were allegedly arranged using a computer draw. The quoted article carries out similar calculations but follow a somewhat different approach.

To be strictly accurate, since possible pairings with Hou Hifan are under consideration, we should make K=42 and thus N=254. This gives a slightly lower probability of 0.000164 and so even more unlikely. It means that out of 10,000 random pairings of a woman with ten competitors, the result of being paired with another woman in seven out of the ten rounds would be expected to occur less than twice. On the other hand, the probability of not being paired with any women is nearly 16% and is given by:$$P(X=0)=\frac{^KC_k \text{ . } ^{N-K}C_{n-k}}{^NC_n}=\frac{^{42}C_0 \text{ . } ^{212}C_{10}}{^{254}C_{10}}\approx 0.158251 $$