Anonymous user
Birthday problem: Difference between revisions
m
→version 1: changed whitespace and some comments; added wording to the REXX section header.
m (→version 1: changed whitespace and some comments; added wording to the REXX section header.) |
|||
Line 1,540:
=={{header|REXX}}==
===version 1===
The root finding method used is to find the average number of people to share a birthday, and then use the '''floor'''
<br>of that value (less the group size) as a starting point to find a new group size with an expected size that exceeds
<br>50% duplicate birthdays of the required size.
<lang rexx>/*REXX pgm examines the birthday problem via random # simulation (with specifable parms)*/▼
This REXX version doesn't need a precalculated group size to find the percentage required to exceed 50%.
▲<lang rexx>/*REXX pgm examines the birthday problem via random
parse arg dups samp seed . /*get optional arguments from the CL. */
if dups=='' | dups=="," then dups= 10 /*Not specified? Then use the default.*/
if samp=='' | samp=="," then samp= 10000 /* " " " " " " */
if datatype(seed, 'W') then call random ,,seed /*RANDOM seed given for repeatability ?*/
diy = 365
diyM= diy*100
do g=2 to dups; s=
do samp; @.=
do j=0 until @.day==g
day= random(1, diyM)
@.day= @.day + 1
end /*j*/
s=
end /*samp*/
start.g= s/samp % 1 - g
end /*g*/
say right('sample size is ' samp, 40); say /*display this run's sample size. */
say ' required trial % with required'
Line 1,565 ⟶ 1,567:
say ' ──────────── ─────── ──────────────────'
do g=2 to dups /*perform through 2 ──► duplicate size*/
do try=start.g until s/samp>=.5; s=
do samp; @.=
do try; day= random(1, diyM) % 100
@.day= @.day + 1
if @.day==g then do; s=s+1; leave; end /*found enough G (birthday) hits ? */
end /*try;*/
|