@AeryB
Probably my language skills are pretty bad, but I’ll try to make everything clear.
Well, first thing, it is not that I am supporting the analytical approach and against what your algorithm is trying to do.
My Python script is not an algorithm or anything fancy. It just uses brute force to list all the combinations for 4 people’s birthdays in our universe where a year consists of only 5 days.
However, as I said in my previous post, what is your reasoning behind not increasing the counter (matches
in your code) likewise when your algo satisfies more than one boolean propositions. Why you’d increase it by only 1 in such cases?
Let me talk through what this code does to answer your question. In the screenshot below, a denotes the birthday of person A in classroom 1, b for person B in classroom 1; c for C in classroom 2; d for D in 2. Line 5 - 8 consists of 4 nested loops, which generates all the 625 combinations for our setting (5 days in a year, n=5). What does it mean? It means that the probability that person A’s birthday is day 0, B day 0, C day 0 and D day 0 is 1/625; the probability that person A’ birthday is day 0, B day 0, C day 0 and D day 1 is also 1/625; the probability that person A’ birthday is day 0, B day 0, C day 0 and D day 2 is also 1/625; and so on.
Now we come to line 9. This is the first iteration of the code and a = b = c = d = 0. This denotes one of the 625 combinations. Does it satisfy the condition that the birthday of a person from classroom 1 is the same as another one from classroom 2? Yes, so we assign 1 to the match variable to express that one of all the combinations meets the condition. You asked why I’d increase match by only 1 when a=b=c=d=0? Well, this is just one combination. If it meets the condition, match is 1, otherwise is 0. So very naturally match can only be 1 or 0 for one combination. Maybe I made you confused by naming this variable match? Maybe I should have named it is_condition_satisfied
?
This is what I am using against your algorithm. But, for the analytical case, I, from my current pov, have nothing to use against it . That’s why I can’t deny it. If you have any valid proof/logic, I must reconsider.
OK. I’ll show why the analytic solution is incorrect with another example. It seems that my initial setting of 5 days a year is not simple enough to show why the solution is incorrect. Let’s make it very, very simple so that we can do the calculation by hand.
Let’s say in our even stranger universe a year just consists of 2 days. First, how many combinations do we have? 16. So there will be 16 rows below. Each row denotes one possibility out of 16. For example, “0,0,0,0,yes” means that the probability that the birthday of all the 4 persons is day 0 in our strange universe is 1/16 and it satisfies the condition that
the birthday of a person from classroom 1 is the same as another one from classroom 2.
There are 14 yes out of 16 rows, so the probability will be 14/16. What does the analytical solution produce? It would be 1 - (1- 1/2) ^ (2^2) = 15/16. 15/16 != 14/16, which shows that the solution is incorrect.
A birthday,B birthday,C birthday,D birthday,is_condition_satisfied
0,0,0,0,yes
0,0,0,1,yes
0,0,1,0,yes
0,0,1,1,no
0,1,0,0,yes
0,1,0,1,yes
0,1,1,0,yes
0,1,1,1,yes
1,0,0,0,yes
1,0,0,1,yes
1,0,1,0,yes
1,0,1,1,yes
1,1,0,0,no
1,1,0,1,yes
1,1,1,0,yes
1,1,1,1,yes