An interesting dialog.

 

From: Linda Alvord [mailto:lindaalv...@verizon.net] 
Sent: Friday, January 20, 2012 12:33 AM
To: 'mike_liz....@tiscali.co.uk'
Subject: RE: [Jprogramming] FW: Challenge 4 Bountiful Birthdays

 

Since you said it is OK to quote you, I'm sending this to the forum.

 

   b1=: 13 : '+/(=/~?#~y)*</~i.y'

   b1

[: +/ ([: =/~ [: ? #~) * [: </~ i.

   

   b1md=:[: -. [: ~: [: i.~ [: ? #~

   b1md

[: -. [: ~: [: i.~ [: ? #~

   

We might as well build this thing "from the ground up" so to speak. My
earlier post today indicates I'm willing to believe that the mean of means
should be very near 23. 

 

So I'm about to tackle what you are saying about trials.

 

I knew I could do this challenge somehow or other, but as I went along, I
didn't like the only ways I seem to be able to make work.

 

More later.

 

Linda

 

From: Mike Day [mailto:mike_liz....@tiscali.co.uk] 
Sent: Thursday, January 19, 2012 11:16 AM
To: Linda Alvord
Subject: Re: [Jprogramming] FW: Challenge 4 Bountiful Birthdays

 

Linda 

Of course you're right!  Don't know what came over me.  
I suppose I didn't quite understand what b1 was doing,  
but that's a pretty lame excuse.

Now I understand b1 a bit better here are some more 
constructive thoughts: 

  a) Your b1 does need to sample from 366 in order to be 
sure of a repeat.  It's possible (but highly unlikely!!!) 
to get i.365,  when this would happen in "day": 
   1+0{b#b*i.365 [ b =: 365#0
|index error
|   1+0    {b#b*i.365[b=:365#0

  b) it's a bit neater to define b1 by 
   b1a =: ([:([: -. [:~:i.~) [: ?#~) 
   
   b1a 10
0 0 0 1 0 0 0 1 0 0

  c) but you can get what you're trying to achieve in one 
pass through "day" (eg 366 day 1) by 

   triala =: (1 + 1 i.~ b1a)"0 
   triala 365 NB. 365 as no worry about all birthdays different
11
   If you did want all indices of b (in day),  I'd 
use I. as in 
      I. 0 0 0 1 0 0 0 1 0 0
3 7
   I believe Hui has optimised (i.&1), so triala could 
be a bit more efficient than the one I've defined above.

  d) you can repeat triala merely by 
   triala 10#365
41 39 38 31 18 40 17 12 30 15

  e) finally to do 10 lots of 500 trials, 
   mean triala 500 10 $ 365
25.18 24.022 24.696 25.148 24.648 25.562 24.082 24.778 25.048 24.246

   f) triala as defined here is more efficient than the "trial" 
I posted in the forum: 
   ts'mean triala 500 10 $ 366'
0.109998 73088
   ts'mean trial 500 10 $ 366'
0.217957 73472

So it's presumably better to sample 366 at a time rather 
than do the conditional sampling that my previous effort, 
"trial", was doing.   

All the best,  and sorry for that Howler! 

Mike

On 19/01/2012 4:44 AM, Linda Alvord wrote: 

You need at least 2 people,  often 20 or so,  but very occasionally (!) 
as many as 1000 or 10000 or more!



The end of your sentence above is not true because the 366th birthdate must
match one of the previous ones (unless it is leap year and then I guess you
must go to 367).

 

If you copy and past Day it may break and you must join the two parts for it
to work.

 

 

From: Mike Day [mailto:mike_liz....@tiscali.co.uk] 
Sent: Wednesday, January 18, 2012 11:04 AM
To: Linda Alvord
Subject: Re: [Jprogramming] FW: Challenge 4 Bountiful Birthdays

 

Linda 

Not broadcast,  but do quote me if you wish. 

In application, b1 seems to be sampling with replacement 
from 0 to 364,  365 times.   Why 365 times?  

You specified: 

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.

You need at least 2 people,  often 20 or so,  but very occasionally (!) 
as many as 1000 or 10000 or more!

Perhaps I misunderstand b1;  am I the "Day" whose control 
structure is a culprit?!

Mike Day
NB my forum message timed at 3:17pm (GMT) might also be relevant

On 18/01/2012 2:19 PM, Linda Alvord wrote: 

c=:0
 
b1=: 13 :'+/(=/~?#~y)*</~i.y'
 
b1
 
b1 365
 
day=: 4 :'while. 0<y do.c=:c,1+0{b#b*i.$b=.b1 x ++/0*y=.0{|.i.y end.'
 
365 day 500
 
]sla=: 13 :'1}.x day y'
 
365 sla 500
 
mean=: +/ % #
 
mean 365 sla 500
 
c=:0
 
365 sla 500
 
mean 365 sla 500
 
m=:c=:0
 
momla=: 4 : 'while. 0<y do. m=:m,mean 365 sla 500 ++/0*y=.0{|.i.y end.'
 
NB. I couldn't make momla work. The control structure in day may be the
culpritI
 
(215 $'(mean 365 sla 500+c=:0),'),',:(mean 365 sla 500)'
 
]means=:":(215 $'(mean 365 sla 500+c=:0),'),',:(mean 365 sla 500)'
 
".means
 
mean ".means
 
 
 
I hadn't gotten to Brian's "do it all at once", but that was my next plan.
 
 
 
Linda
 
 
 
From: Linda Alvord [mailto:lindaalv...@verizon.net] 
Sent: Sunday, January 15, 2012 5:41 AM
To: 'Programming forum'
Subject: RE: Challenge 4 Bountiful Birthdays
 
 
 
I have been reluctant to include the interesting fd created by Henry Rich
and Ric Sherlock because I was unable to write the explicit version that
produces their tacit version. I finally got it , so we now have another fd.
 
 
 
   fdrs=:[: /:~ ({. , #)/.~ 
 
   fdrs
 
[: /:~ ({. , #)/.~
 
 
 
 
 
   a=:3 2 3 3 1 3 4 1 1 2
 
   fd=: 13 :'/:~(~.y),.#/.~y'
 
   fd
 
[: /:~ ~. ,. #/.~
 
   fd a
 
1 3
2 2
3 4
4 1
 
 
 
From: Linda Alvord [mailto:lindaalv...@verizon.net] 
Sent: Monday, January 09, 2012 10:45 AM
To: 'Linda Alvord'
Subject: Challenge 4 Bountiful Birthdays
 
 
 
Chalenge 4 Bountiful Birthdays       PLEASE DO NOT RESPOND UNTIL 1/16/2012
12 am EST
 
 
 
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.
 
 
 
'til next week.
 
 
 
Linda
 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
 

 

 

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to