Post Reply 
Little explorations with HP calculators (no Prime)
12-27-2018, 04:59 PM
Post: #319
RE: Little explorations with HP calculators (no Prime)
After running a bunch of iterations of the previously-posted routines, I became curious about the distribution of counts of matches (where a "match" is defined by a proper mix of 50/20 colored balls).

Knowing that it would be too slow to attempt this on a 50g, I opted to attempt this with python running on my laptop (I'm still in a learning mode with python -- please be kind).

I came up with the following to generate one million random lists of 100 blue/40 white balls, then summed the individual counts to see how they were distributed:
Code:
import random

def random_list():
    result = [1]*100 + [0]*40
    random.shuffle(result)
    return result

def match_count(thelist):
    matches = 0
    for i in range(71):
        sublist = thelist[i:i+70]
        if sum(sublist) == 50:
            matches += 1
    return matches

def main():
    result = {}
    for i in range(1,72):
        result[i] = 0
    for __ in range(1000000):
        thelist = random_list()
        matches = match_count(thelist)
        result[matches] += 1
    for i in range(1,72):
        print('%d\t%d' % (i,result[i]))

if __name__ == '__main__':
    main()

The final result of the above is a tab-delimited list of counts and quantities, and the following is a sample of one run:
Code:
1    60726
2    60743
3    60133
4    59444
5    58566
6    57093
7    55206
8    53189
9    51518
10    48693
11    45882
12    43496
13    40126
14    37631
15    34314
16    31327
17    28141
18    25558
19    22785
20    19674
21    17479
22    15290
23    13129
24    11113
25    9502
26    7924
27    6637
28    5407
29    4362
30    3518
31    2719
32    2233
33    1763
34    1291
35    950
36    690
37    509
38    399
39    282
40    177
41    123
42    100
43    54
44    40
45    24
46    25
47    5
48    3
49    4
50    1
51    2
52    0
53    0
54    0
55    0
56    0
57    0
58    0
59    0
60    0
61    0
62    0
63    0
64    0
65    0
66    0
67    0
68    0
69    0
70    0
71    0

Placing that data into an Excel spreadsheet and plotting the result gives a very familiar shape:

[Image: attachment.php?aid=6706]

I suspect the probability of randomly generating a list that has 71 "matches" is quite small. Smile


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Little explorations with HP calculators (no Prime) - DavidM - 12-27-2018 04:59 PM



User(s) browsing this thread: 14 Guest(s)