Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Lubos Motl
- Dear Steve, of course that the answer to this latest problem will be 43% or so, the program is attached below. But it's because what you're doing is borderline cheating. You want to create the impression that there are 100 years and potentially 400 births in those four families. However, the typical run will only produce 5-10 children. So in every single run, the number of children will fail to be large.
- This latest problem has nothing to do with a population. It is a group of 5-10 people that goes extinct within 2 years or so.
- Yesterday, 03:40:11 – Flag – Like – Reply
- Lubos Motl
- Here is the program, I needed 5 minutes to write it and a few seconds to run it. Input:
- sumOfFractions = 0; runs = 1000; years = 100;
- For[run = 1, run <= runs, run++,
- stillproducing = {1, 1, 1, 1};
- girlsboys = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
- (* 0 is boy and 1 is girl *)
- For[year = 1, year <= years, year++,
- For[family = 1, family <= 4, family++,
- randomsex = RandomInteger[];
- girlsboys[[family, randomsex + 1]] =
- girlsboys[[family, randomsex + 1]] + stillproducing[[family]]
- ;
- stillproducing[[family]] = stillproducing[[family]]*randomsex;
- ];
- ]; (* Print[MatrixForm[girlsboys]]; *)
- fraction = Total[girlsboys[[All, 2]]]/Total[Flatten[girlsboys]];
- sumOfFractions = sumOfFractions + fraction;
- ];
- overallGirlPercentage = sumOfFractions/runs
- N[overallGirlPercentage]
- Output:
- 12803786239/29099070000
- 0.44000672
- This has nothing to do with the original problem because there's no "population" here.
- Yesterday, 03:41:28 – Flag – Like – Reply
- Lubos Motl
- If you correctly calculated the weighted average over the runs, with weights given by the total number of children in the run, you get 50%:
- sumOfFractions = 0; runs = 1000; years = 100;
- totalweights = 0;
- For[run = 1, run <= runs, run++,
- stillproducing = {1, 1, 1, 1};
- girlsboys = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
- (* 0 is boy and 1 is girl *)
- For[year = 1, year <= years, year++,
- For[family = 1, family <= 4, family++,
- randomsex = RandomInteger[];
- girlsboys[[family, randomsex + 1]] =
- girlsboys[[family, randomsex + 1]] + stillproducing[[family]]
- ;
- stillproducing[[family]] = stillproducing[[family]]*randomsex;
- ];
- ]; (* Print[MatrixForm[girlsboys]]; *)
- weight = Total[Flatten[girlsboys]];
- fraction = Total[girlsboys[[All, 2]]]/weight*weight;
- sumOfFractions = sumOfFractions + fraction;
- totalweights = totalweights + Total[Flatten[girlsboys]];
- ];
- overallGirlPercentage = sumOfFractions/totalweights
- N[overallGirlPercentage]
- Output:
- 519/1019 = 0.5093
- With a higher number of runs, you get closer to 50%
- Yesterday, 03:46:30 – Flag – Like – Reply
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement