C Probability to see each card at least once if m>=n cards C are drawn with replacement from a deck of n cards. C C Author: Hugo Pfoertner http://www.pfoertner.org C C Version History: C Jan 10 2004 Initial version C double precision p integer choose external choose C Title line write (*,*) ' Number of cards drawn' write (*,*) ' | Size of deck (drawn cards are replaced)' write (*,*) ' | | Successful cases' write (*,*) ' | | | Probability' write (*,*) ' | | | |' C Loop over number of drawn cards do 10 m = 2, 20 C Loop over size of card deck do 20 n = m, 1, -1 p = 0.0D0 do 30 i = 0, n-1 p = p + dble((-1)**i)*dble(choose(n,i))*dble(n-i)**m 30 continue write (*,1001) m,n,p,100.0*p/dble(n)**m 1001 format ( 2I3, f23.0, f9.4 ) 20 continue 10 continue end C*************** integer function choose ( n, m ) C C(n,m) integer c(135) data c /1,1, 1,2,1, 1,3,3,1, 1,4,6,4,1, 1,5,10,10,5,1, & 1,6,15,20,15,6,1, 1,7,21,35,35,21,7,1, & 1,8,28,56,70,56,28,8,1, & 1,9,36,84,126,126,84,36,9,1, & 1,10,45,120,210,252,210,120,45,10,1, & 1,11,55,165,330,462,462,330,165,55,11,1, & 1,12,66,220,495,792,924,792,495,220,66,12,1, & 1,13,78,286,715,1287,1716,1716,1287,715,286,78,13,1, & 1,14,91,364,1001,2002,3003,3432,3003,2002,1001,364,91,14,1, & 1,15,105,455,1365,3003,5005,6435, & 6435,5005,3003,1365,455,105,15,1/ if ( m .eq. 0 .or. m .eq. n ) then choose = 1 return endif C Find index in table k = (n*(n+1))/2 + m C Compute if outside table if ( k .gt. 135 ) then d = 1.0D0 do 10 k = 1, m d = d * dble(n-k+1) / dble(k) 10 continue C Check range if ( d .gt. 2.147483647D9 ) then stop ' Choose outside range' else choose = nint ( d ) endif else choose = c(k) endif return C End of function choose end C********************************************** Results: Number of cards drawn m | Size of deck n (drawn cards are replaced) | | Successful cases s (believe first 13 decimal digits) | | | Probability=s/n^m | | | | 1 1 1. 100.0000 2 2 2. 50.0000 2 1 1. 100.0000 3 3 6. 22.2222 3 2 6. 75.0000 3 1 1. 100.0000 4 4 24. 9.3750 4 3 36. 44.4444 4 2 14. 87.5000 4 1 1. 100.0000 5 5 120. 3.8400 5 4 240. 23.4375 5 3 150. 61.7284 5 2 30. 93.7500 5 1 1. 100.0000 6 6 720. 1.5432 6 5 1800. 11.5200 6 4 1560. 38.0859 6 3 540. 74.0741 6 2 62. 96.8750 6 1 1. 100.0000 7 7 5040. 0.6120 7 6 15120. 5.4012 7 5 16800. 21.5040 7 4 8400. 51.2695 7 3 1806. 82.5789 7 2 126. 98.4375 7 1 1. 100.0000 8 8 40320. 0.2403 8 7 141120. 2.4480 8 6 191520. 11.4026 8 5 126000. 32.2560 8 4 40824. 62.2925 8 3 5796. 88.3402 8 2 254. 99.2188 8 1 1. 100.0000 9 9 362880. 0.0937 9 8 1451520. 1.0815 9 7 2328480. 5.7702 9 6 1905120. 18.9043 9 5 834120. 42.7069 9 4 186480. 71.1365 9 3 18150. 92.2116 9 2 510. 99.6094 9 1 1. 100.0000 10 10 3628800. 0.0363 10 9 16329600. 0.4683 10 8 30240000. 2.8163 10 7 29635200. 10.4913 10 6 16435440. 27.1812 10 5 5103000. 52.2547 10 4 818520. 78.0602 10 3 55980. 94.8026 10 2 1022. 99.8047 10 1 1. 100.0000 11 11 39916800. 0.0140 11 10 199584000. 0.1996 11 9 419126400. 1.3356 11 8 479001600. 5.5763 11 7 322494480. 16.3096 11 6 129230640. 35.6206 11 5 29607600. 60.6364 11 4 3498000. 83.3988 11 3 171006. 96.5334 11 2 2046. 99.9023 11 1 1. 100.0000 12 12 479001600. 0.0054 12 11 2634508800. 0.0839 12 10 6187104000. 0.6187 12 9 8083152000. 2.8620 12 8 6411968640. 9.3306 12 7 3162075840. 22.8452 12 6 953029440. 43.7816 12 5 165528000. 67.8003 12 4 14676024. 87.4759 12 3 519156. 97.6884 12 2 4094. 99.9512 12 1 1. 100.0000 13 13 6227020800. 0.0021 13 12 37362124800. 0.0349 13 11 97037740800. 0.2811 13 10 142702560000. 1.4270 13 9 130456085760. 5.1323 13 8 76592355840. 13.9321 13 7 28805736960. 29.7307 13 6 6711344640. 51.3858 13 5 901020120. 73.8116 13 4 60780720. 90.5703 13 3 1569750. 98.4587 13 2 8190. 99.9756 13 1 1. 100.0000 14 14 87178291196. 0.0008 14 13 566658892802. 0.0144 14 12 1612798387200. 0.1256 14 11 2637143308800. 0.6944 14 10 2731586457600. 2.7316 14 9 1863435974400. 8.1455 14 8 843184742400. 19.1718 14 7 248619571200. 36.6575 14 6 45674188560. 58.2845 14 5 4809004200. 78.7907 14 4 249401880. 92.9094 14 3 4733820. 98.9724 14 2 16382. 99.9878 14 1 1. 100.0000 15 15 1307674368191. 0.0003 15 14 9153720575884. 0.0059 15 13 28332944640030. 0.0554 15 12 50999300352000. 0.3310 15 11 59056027430401. 1.4138 15 10 45950224320000. 4.5950 15 9 24359586451200. 11.8313 15 8 8734434508800. 24.8248 15 7 2060056318320. 43.3919 15 6 302899156560. 64.4213 15 5 25292030400. 82.8769 15 4 1016542800. 94.6729 15 3 14250606. 99.3149 15 2 32766. 99.9939 15 1 1. 100.0000 16 16 20922789838832. 0.0001 16 15 156920924169009. 0.0024 16 14 524813313023700. 0.0241 16 13 1031319184895650. 0.1550 16 12 1320663933388840. 0.7143 16 11 1155068769254392. 2.5138 16 10 703098107712002. 7.0310 16 9 297846188640000. 16.0736 16 8 86355926616960. 30.6798 16 7 16540688324160. 49.7720 16 6 1969147121760. 69.8004 16 5 131542866000. 86.2079 16 4 4123173624. 96.0001 16 3 42850116. 99.5433 16 2 65534. 99.9969 16 1 1. 100.0000 17 17 355687431958501. 0.0000 17 16 2845499424257040. 0.0010 17 15 10226013557926280. 0.0104 17 14 21785854970862620. 0.0714 17 13 30575780537700680. 0.3535 17 12 29708792431718730. 1.3391 17 11 20439835646630210. 4.0439 17 10 10009442963520030. 10.0094 17 9 3457819037312639. 20.7338 17 8 823172919528960. 36.5562 17 7 129568848121440. 55.6973 17 6 12604139926560. 74.4632 17 5 678330198120. 88.9101 17 4 16664094960. 96.9978 17 3 128746950. 99.6955 17 2 131070. 99.9985 17 1 1. 100.0000 18 18 6402373607936134. 0.0000 18 17 54420176545698630. 0.0004 18 16 209144207718603200. 0.0044 18 15 480178027929169200. 0.0325 18 14 733062897120271600. 0.1717 18 13 783699448602466200. 0.6969 18 12 601783536940180000. 2.2604 18 11 334942064711655400. 6.0242 18 10 134672620008326200. 13.4673 18 9 38528927611574410. 25.6698 18 8 7621934141203200. 42.3102 18 7 995210916336000. 61.1154 18 6 79694820748080. 78.4707 18 5 3474971465400. 91.0943 18 4 67171367640. 97.7472 18 3 386634060. 99.7970 18 2 262142. 99.9992 18 1 1. 100.0000 19 19 121645100935268000. 0.0000 19 18 1094805901879330000. 0.0002 19 17 4480594532668239000. 0.0019 19 16 11029155770316090000. 0.0146 19 15 18198613875781000000. 0.0821 19 14 21234672840113020000. 0.3553 19 13 18011278812054430000. 1.2320 19 12 11240707219822070000. 3.5184 19 11 5165761531919779000. 8.4464 19 10 1732015476199009000. 17.3202 19 9 415357755774998400. 30.7478 19 8 68937160460313590. 47.8348 19 7 7524340159588561. 66.0094 19 6 499018753280880. 81.8923 19 5 17710714165200. 92.8551 19 4 270232006800. 98.3098 19 3 1160688606. 99.8647 19 2 524286. 99.9996 19 1 1. 100.0000 20 20 2432901438756178000. 0.0000 20 19 23112569254158100000. 0.0001 20 18 100357207787891000000. 0.0008 20 17 263665755140947800000. 0.0065 20 16 467644314337956300000. 0.0387 20 15 591499300737992200000. 0.1779 20 14 549443323130422000000. 0.6567 20 13 380275818414388000000. 2.0009 20 12 196877625020903500000. 5.1354 20 11 75875547089306630000. 11.2784 20 10 21473732319740060000. 21.4737 20 9 4358654246117808000. 35.8511 20 8 611692004959217400. 53.0558 20 7 56163512390086080. 70.3872 20 6 3100376804676480. 84.7988 20 5 89904730860000. 94.2719 20 4 1085570781624. 98.7321 20 3 3483638676. 99.9098 20 2 1048574. 99.9998 20 1 1. 100.0000