Close. You actually have to be sure that all 6 cards dealt to the players are unique. For instance, if I get 3 points, if you don't require that all the cards dealth in the game are unique, you would conclude that there is a very small, but positive probability that I will win. In reality, 3 points means that my two cards are a 1 and a 2. Thus there are not 4 1's left, and I am sure not to win.
One way to do that is to select 2 cards for P1. Then select 2 cards for P2, making sure that neither one was dealt to P1. If the sum of P1 is greater than the sum of P2, select 2 cards from the remaining deck for P3. If the sum of P1 is greater than the sum of P3, add one to your counter. I'm sure that there is a faster way to code it, but on my computer this ran in about 2 seconds. There are 52!/(46!*8) ways that the cards can be dealt. 565,271,160 of those result in P1 winning. Thus P(p1 wins) = 0.30850919745967... Don On Jan 23, 7:34 am, Lucifer <sourabhd2...@gmail.com> wrote: > @Don and Sundi.. > > As Don pointed out, all we are looking for is: > sum of a1 > sum of a2 > sum of a1 > sum of a3 > > Assumption: > 1) The 2 cards picked for a particular player are unique. > 2) Cards are numbered : 1,..., 12, 13. > > Hence, the following code should give the answer for the a1's > probability to win: > > for( int i =1; i < 23; ++i) > { > sampleCount+= a[i]*b[i-1]*b[i-1]; > > } > > probability= sampleCount/ 474552; > > sampleCount will be: 145650 > probability = 0.306921 > > On Jan 23, 2:36 pm, Lucifer <sourabhd2...@gmail.com> wrote: > > > > > @Don.. > > > Yup, it seems I misread it ... :) .. Thanks > > > On Jan 23, 9:17 am, Don <dondod...@gmail.com> wrote: > > > > I think that you are misreading the problem. A1 wins if his sum is > > > larger than A2's sum and larger than A3's sum. A1's sum doesn't have > > > to be larger than A2+A3. > > > Don > > > > On Jan 22, 5:18 pm, Lucifer <sourabhd2...@gmail.com> wrote: > > > > > @sundi.. > > > > > Lets put is this way.. > > > > > Probability of (a1 wins + a1 draws + a1 losses) = 1, > > > > > Now, sample count a1 wins = 46298 ( using the above given code) > > > > Hence, the probability (win) = 46298/474552 = .097561 > > > > [ @ Don - as i mentioned in my previous post that i had initially > > > > missed a factor 2, hence the above calculated value shall justify > > > > that] > > > > > Based on explanation given in the previous post, you can use the same > > > > approach and find out the sample count for a1's draw and loss.. > > > > > Add the following code snippet to calculate the same: > > > > > // Draws ( a1 = a2 + a3 ) > > > > > int sampleCount2 = 0; > > > > for(int i =0; i <23; ++i) > > > > { > > > > for(int j = 0; j <i; ++j) > > > > { > > > > if(i - j == j) > > > > sampleCount2 += a[j] * a[j] * a[i]; > > > > else if (i - j > j) > > > > sampleCount2 += 2 * a[j] * a[i-j] * a[i]; > > > > } > > > > > } > > > > > // Losses ( a1 < a2 + a3 ) > > > > > int sampleCount3 = 0; > > > > for(int i =0; i <23; ++i) > > > > { > > > > for(int j = 0; j <23; ++j) > > > > { > > > > if (i - j + 1 ==j) > > > > { > > > > sampleCount3 += a[j] * a[j] * a[i]; > > > > sampleCount3 += 2 * a[j] * (b[22] - b[i-j+1]) * a[i]; > > > > } > > > > else if(i - j + 1 > j) > > > > { > > > > // this is a special case as both i and j are smaller than > > > > // (i - j + 1) > > > > if ( i==0 && j ==0 ) > > > > sampleCount3 = a[j] * a[j] * a[i]; > > > > > sampleCount3 += 2 * a[j] * (b[22] - b[i-j]) * a[i]; > > > > } > > > > else > > > > { > > > > sampleCount3 += a[j] * a[j] * a[i]; > > > > sampleCount3 += 2 * a[j] * (b[22] - b[j]) * a[i]; > > > > } > > > > } > > > > > } > > > > > On executing the given snippet you will get: > > > > sampleCount2 = 10184 (draw) > > > > samepleCount3 = 418070 ( loss) > > > > > Now, for the probability to be 1: > > > > sampleCount + sampleCount2 + sampleCount3 should be 78^3 (474552).. > > > > > Now, > > > > 46298 + 10184 + 418070 = 474552 which is equal to (78^3).. > > > > > On Jan 23, 2:34 am, Sundi <sundi...@gmail.com> wrote: > > > > > > Hi Lucifer, > > > > > Have you checked the sum of probability of (a winning + b > > > > > winning + c winning + draw)==1 ? > > > > > > On Jan 22, 2:38 pm, Lucifer <sourabhd2...@gmail.com> wrote: > > > > > > > @above > > > > > > > editing mistake.. (btw the working code covers it) > > > > > > /* > > > > > > int j =*1*; > > > > > > for(int i = 0; i < 12 ; i+=2) > > > > > > { > > > > > > A[i] = A[i+1] = A[22-i] = A[21-i] = j; > > > > > > ++j;} > > > > > > > */ > > > > > > On Jan 22, 6:53 pm, Lucifer <sourabhd2...@gmail.com> wrote: > > > > > > > > @Don.. > > > > > > > > Well i will explain the approach that i took to arrive at the > > > > > > > probability.. > > > > > > > Well yes u are correct in saying that it doesn't make a lot of > > > > > > > sense > > > > > > > but then the no. of wins by a1 keeping in mind that a1 > a2 + a3 > > > > > > > is > > > > > > > much less than a1 <= a2 + a3.. > > > > > > > Or may be I have gone wrong in calculating the same.. > > > > > > > > Please let me know if u find some issue in the below given > > > > > > > explanation.. > > > > > > > > -------------------------------- > > > > > > > now, the given nos. are 1,2,3,4,.....13.. > > > > > > > > Hence, the possible pair sums are 3,4,5,....,25... > > > > > > > > The total no. of pairs that can be formed are 13 C 2 = 78. > > > > > > > > Now, for each pair within 3-25 (including both extremes) lets > > > > > > > find the > > > > > > > no. of ways we get to the particular sum. > > > > > > > i.e for 3 its 1 ( 1 + 2) > > > > > > > for 7 its 3 (1 + 6, 2 + 5, 3 + 4) > > > > > > > > Lets take an array A[23], to store the count of occurrences for > > > > > > > pair > > > > > > > sums (3 - 25) > > > > > > > A[i] -> will store the no. of ways of getting 'i+3' pair-sum > > > > > > > > A[i] values will be: > > > > > > > i -> > > > > > > > 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 > > > > > > > 17 > > > > > > > 18 19 20 21 22 > > > > > > > > A[i] -> > > > > > > > 1 1 2 2 3 3 4 4 5 5 6 6 6 5 5 4 > > > > > > > 4 > > > > > > > 3 3 2 2 1 1 > > > > > > > > Now, the above can be generated by using the following code: > > > > > > > > Lets say the input is stored in X[R] = {1,2, ..., 13} > > > > > > > Here R is 13.. > > > > > > > > Lets say, the array A is initialized with 0. > > > > > > > > for (int i = 0; i < R-1; ++i) > > > > > > > for ( int j = 1; i < R; ++j) > > > > > > > ++A[ X[i] + X[j] ]; > > > > > > > > Well, as the nos. are continuous , hence we can minimize the > > > > > > > initialization operation as follows > > > > > > > (based on fact that there is a pattern and holds for any set of > > > > > > > continuous nos. from 1 to K) > > > > > > > > // initialze pair counts.. ( 3 ... 25) > > > > > > > int j =0; > > > > > > > for(int i = 0; i < 12 ; i+=2) > > > > > > > { > > > > > > > A[i] = A[i+1] = A[22-i] = A[21-i] = j; > > > > > > > ++j;} > > > > > > > > a[12] = 6; > > > > > > > > [ the above code is specifically written for 1 to 13 (K), but you > > > > > > > can > > > > > > > generalize it based on ur need. > > > > > > > All you need to do is take care of the last initialization > > > > > > > statement > > > > > > > "a[12] = 6;" based on value K (13).] > > > > > > > -------------------------------- > > > > > > > > Now, A[i] basically represent the no. of ways we can get 'i+3' -> > > > > > > > lets > > > > > > > say this is a1's current pick. > > > > > > > Now, for sum of a2 and a3's pick to be smaller than a1's we can > > > > > > > do the > > > > > > > following: > > > > > > > > If A[i] is picked by a1, then let a2 pick A[p] where p < i, then > > > > > > > the > > > > > > > possible picks by a3 would be > > > > > > > from anywhere b/w A[p] to A[i - p - 1]. > > > > > > > Here, there is a catch .. we need to insure that i - p -1 > = p > > > > > > > otherwise the range for a3's pick would be invalid. > > > > > > > Also, the above explanation is based on the assumption that a2 > > > > > > > <=a3. > > > > > > > Hence, to complete figure out all the possibilities of a1, a2 > > > > > > > and a3, > > > > > > > we need to do the following.. > > > > > > > > For a given pick by a1 say A[i], then the no. of possiblites such > > > > > > > that > > > > > > > a1> a2 + a3 would be: > > > > > > > > 1) if a2=a3, A[p] * A[p] * A[i] > > > > > > > 2) if a2!=a3 , 2 * A[p] *( cumulative sum of A[p+1] to A[i - p > > > > > > > -1]) > > > > > > > *A[i] > > > > > > > [ a factor of 2 is multiplied to remove the > > > > > > > assumption a2 < a3 ] > > > > > > > > Now, once we get the total no. of possibities by the above given > > > > > > > equation, the probability would be: > > > > > > > (No. of possiblites) / (78^3) .. > > > > > > > [ 78 -> 13 C 2] > > > > > > > > Code: > > > > > > > int a[23];// to store the count > > > > > > > int b[23];// to store the cumulative count > > > > > > > int k = 1; > > > > > > > > // initialze pair counts.. ( 3 ... 25) > > > > > > > for(int i = 0; i <12; i+=2) > > > > > > > { > > > > > > > a[i] = a[i+1] = a[22-i] = a[21-i] = k; > > > > > > > ++k;} > > > > > > > > a[12] = 6; > > > > > > > > b[0]=a[0]; > > > > > > > > //cumulative sum > > > > > > > for(int i = 1; i <23; i+=1) > > > > > > > { > > > > > > > b[i] = b[i-1] + a[i]; > > > > > > > > } > > > > > > > > // calculate possibilities.. > > > > > > > // i =0 (3 :minimum sum pair)... i=22 (25 : max sum pair) > > > > > > > int sampleCount = 0; > > > > > > > for(int i =0; i <23; ++i) > > > > > > > { > > > > > > > for(int j = 0; j <i; ++j) > > > > > > > { > > > > > > > if(i - j - 1 >= j) > > > > > > > { > > > > > > > sampleCount += a[j] * a[j] * a[i]; > > > > > > > if (i - j - 1 > j) > > > > > > > sampleCount += 2 * a[j] * (b[i-j-1] - b[j]) * a[i]; > > > > > > > } > > > > > > > } > > > > > > > > } > > > > > > > > int R = 78*78*78; > > > > > > > printf("probability = %f ", (float)sampleCount / R); > > > > > > > > -------------------------------------------- > > > > > > > Don, as I mentioned in the start that there is possibility i might > > > > > > > have gone wrong in calculation. The fact being that i missed the > > > > > > > factor 2 when i wrote the code. > > > > > > > But, then the main point here is that whether the approach is > > > > > > > correct > > > > > > > or not. > > > > > > > --------------------------------------------- > > > > > > > > On Jan 20, 3:41 am, Don <dondod...@gmail.com> wrote: > > > > > > > > > You are saying that a1 wins roughly 1 in 20 times? How does > > > > > > > > that make > > > > > > > > any sence? > > > > > > > > Don > > > > > > > > > On Jan 19, 2:35 pm, Lucifer <sourabhd2...@gmail.com> wrote: > > > > > > > > > > @correction: > > ... > > read more »- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.