Birthday problem: Difference between revisions

→‎{{header|REXX}}: re-worked entire program. -- ~~~~
(→‎{{header|REXX}}: re-worked entire program. -- ~~~~)
Line 198:
if samp=='' | samp==',' then samp=100000 /*" " " " " */
if seed\==',' & seed \=='' then call random ,,seed /*repeatability? */
!.diy =0365 /*or: diy=365.25*/ /*the number of Days In a Year. /*used for tracking pop averages.*/
diydiyM=365diy*100 /*or: diy=365.25*/ /*the number of Days In a Year /*this expands the RANDOM range. */
/* [] get Feba 29th'srough B-dayestimate for Mar 1.%*/
do kg=2 to grps; s=0 /*perform through 2──►group size.*/
do samp; @.=0 /*perform some number of trials. */
@.=0 do j=1 /*initializedo birthdayuntil occurrencesg dup birthdays found.*/
do j day=random(1,diyM) % 100 /*do until Kexpand duprandom birthdaysnumber found.generation*/
@.day=random(@.day+1,diy*100) % 100 /*expandrecord the of randoma numberparticular generationBday*/
if @.day=@.day+1=g then leave /*when G hits have occurred /*record the of a particular Bday···*/
if @.day==k then leave end /*when K hits have occurred ...j*/
s=s+j end /*jadd number of people to sum. */
s=s+j end /*add number of people to sum. samp*/
 
end /*samp*/
! start.kg=s /samp%1-g /*savedefine where the total number oftry-outs peoplestart*/
end /*kg*/
 
pad=' ' /*padding for easier eyeballing. */
say ' sample size is ' samp /*show sample size of this run. */
say
say___=' ' pad 'required' pad 'group' pad '% with required' /*padding for easier eyeballing. */
say pad___ ' common required' pad___ ' sizegroup' pad___ 'common% with birthdaysrequired'
say pad___ '──────── common ' pad___ '───── size' pad___ '────────────────common birthdays'
say ___ '────────' ___ '─────' ___ '────────────────'
/* [↓] where the try-outs happen.*/
do g=2 to grps /*perform through 2──►group size.*/
do try=start.g; s=0 /*perform try-outs until avg>50%.*/
do samp; @.=0 /*perform some number of trials. */
do j=1 for try /*do until K dup birthdays found.*/
day=random(1,diyM) % 100 /*expand random number generation*/
@.day=@.day+1 /*record the of a particular Bday*/
if @.day\==g then iterate /*when G hits have occurred ···*/
pad=' ' s=s+1 /*paddinganother forcommon easierbirthday eyeballingfound. */
leave /* ... and stop looking for more.*/
end /*j*/
end end /*samp*/
 
do g=2 toif s/samp>.5 grps then leave /*if the average is > 50%, /*show all the groups simulatedstop. */
d=!.g/samp end /*average common birthday size. try*/
 
say pad___ center(g,8) pad___ right(d%1try,5) pad___ center((50+(d-d%1)s/dsamp*100)'%',16)
end /*g*/
/*stick a fork in it, we're done.*/</lang>
'''output'''
Line 230 ⟶ 243:
sample size is 100000
 
required group % with required
common size common birthdays
 
──────── ───── ────────────────
2 2423 50.027478675100%
3 88 5051.008330914700%
4 187 50.001682530400%
5 311313 50.002049814100%
</pre>