People seem to be tackling two different problems. Variations on the Birthday Problem as I remember them: (a) what is the probability that two (or more) people share a birthday in a group of N people? (b) what should N be for the probability to be (say) 0.5 ? The somewhat counter-intuitive answers are dealt with in Roger's Wiki Essay, among many treatments, and also Pablo's message, below. The essential point is to consider the probability that there are no matches.
However, Linda's single trial as stated is a random process with a stopping condition: take one person at a time until the new person shares a birthday with those already present. The result is the number of people including the new arrival. I expect you need a Markov Process approach to get the exact expected value for the stopping number. Not proved! Here's a stab at the required simulation, avoiding @ and @: though using [: NB. I use _1 as seed, so need to decrement the count trial =: (_1 + [: # (] (,`]@.e.~ ([: ? 365"_)))^:_)"0 trial 10#_1 NB. eg conduct 10 trials 27 19 29 2 24 42 30 9 34 33 mean =: +/%# NB. ok for vectors or columns of matrix ([:(;~mean) mean) TRIALS =: trial 500 10 $ _1 +-------+-------------------------------------------------------------------+ |23.5882|22.696 23.676 23.894 24.044 23.874 23.56 24.258 23.416 22.81 23.654| +-------+-------------------------------------------------------------------+ These means are indeed close to N in problems (a) & (b) where the probability is ~0.50, namely 21 for 0.475695 and 22 for 0.507297, but not the same. I used 365 rather than Pablo's 365.25 . The simulation could be done for 365.25, using the integer 1461 (say). The stopping condition would be a bit more complicated. The deviation of trials is quite large: SS =: [: *: (-"1 mean) NB. squared deviations from mean stdev=: [: %: [: mean SS NB. Observed Standard deviation NB. not necessarily recommended for real, large sets of data (mean,:stdev) TRIALS 22.696 23.676 23.894 24.044 23.874 23.56 24.258 23.416 22.81 23.654 11.9378 12.6587 12.6917 12.5288 12.281 11.9741 12.1957 11.442 12.0969 12.8718 NB. standard deviation of the means: (mean, stdev) mean TRIALS 23.5882 0.477041 Mike On 18/01/2012 1:15 PM, Pablo Landherr wrote: > Another solution. > > bdayprob > [: -. [: */\@:-. [: %&365.25 i. > bdayprob 24 > 0 0.00273785 0.00819856 0.0163448 0.0271172 0.0404352 0.0561981 0.074286 > 0.0945617 0.116872 0.141051 0.166919 0.19429 0.222967 0.25275 0.283438 > 0.314827 0.346718 0.378912 0.411221 0.443461 0.475459 0.507053 0.538094 > > > > On Wed, Jan 18, 2012 at 7:03 AM, Roger Hui<rogerhui.can...@gmail.com>wrote: > >> Does http://www.jsoftware.com/jwiki/Essays/Birthday%20Problem answer any >> of >> your questions? >> >> >> >> On Tue, Jan 17, 2012 at 9:40 PM, Linda Alvord<lindaalv...@verizon.net >>> wrote: >>> Capture the last row of c >>> >>> ]l=:{:c >>> 106 249 7 326 308 274 81 347 276 113 108 20... >>> >>> And use grade up to arrange the numbers in sequence >>> >>> (/:l){l >>> 0 1 3 3 4 4 5 5 6 6 7 7 7 7 8 8 8 13 13... >>> >>> This should be i.365 >>> >>> I have an idea on how to get what you want but I'll wait to see what you >> do >>> next. >>> I have to use a deal without a fixed seed for the deal. >>> >>> I happened to remember 24 and haven't gone looking for the number and >>> haven't the foggiest notion of how I proved it! >>> >>> Linda >>> >>> -----Original Message----- >>> From: Linda Alvord [mailto:lindaalv...@verizon.net] >>> Sent: Tuesday, January 17, 2012 11:25 PM >>> To: 'Programming forum' >>> Subject: RE: [Jprogramming] Challenge 4 Bountiful Birthdays >>> >>> I think we need sortleaf. >>> >>> Linda >>> >>> -----Original Message----- >>> From: programming-boun...@jsoftware.com >>> [mailto:programming-boun...@jsoftware.com] On Behalf Of Brian Schott >>> Sent: Tuesday, January 17, 2012 10:14 PM >>> To: Programming forum >>> Subject: Re: [Jprogramming] Challenge 4 Bountiful Birthdays >>> >>> $c=.500 365?.@$365 >>> $D=. i.&0"1(=&#~.)\"1 c >>> mean D+1 NB. 25.086 >>> pretty 5 SL sortleaf 1+D >>> >>> $c=. 10 500 365?.@$365 >>> $D=. i.&0"1(=&#~.)\"1 c >>> mean, D+1. NB. 24.6856 >>> pretty"2] 5 SL"0 1 sortleaf"1] 1+D >>> >>> I am suspicious of these results because my memory is that the mean is >>> closer to 18.5 people. Then again, other measures of the center look >> closer >>> to 19, just looking at the stemplots. >>> >>> --- >>> (B=) >>> >>> On Jan 15, 2012, at 5:40 AM, "Linda Alvord"<lindaalv...@verizon.net> >>> wrote: >>> >>>> For this challenge, as usual, do not use @ but you may use whatever >>> style >>>> and strategy you like to accomplish the task. >>>> >>>> >>>> >>>> The problem is to simulate the classic birthday problem. >>>> >>>> >>>> >>>> A single trial works this way. People enter a room one by one and >>> declare >>>> their birth date. Suppose the 29th person is the first person to >> match a >>>> birthday of someone in the room. The result of the first trial is 29. >>>> >>>> >>>> >>>> Repeat for 500 trials. >>>> >>>> >>>> >>>> If you use Kip's frequency distribution of the results you have lots of >>>> information. >>>> >>>> >>>> >>>> fd=:[: /:~ ~. ,. [: +/"1 ~. =/ ] >>>> >>>> >>>> >>>> But the mean gives a more concise summary of the data. So, the final >>> part >>>> of the problem is to obtain a list of 10 means of 500 trials and >> the >>>> mean of the means. >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm >> > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm