News for hackers. Stuff that matters.
Re:Do men or women have more brothers? by mudbungie on Monday May 23, 2016 @03:59PM (#11756444)
I chose to answer the question empirically. http://pastebin.com/1g1bAEPt Turns out it's equal.
Re:Do men or women have more brothers? by micheljansen on Monday May 23, 2016 @04:13PM (#11756553)
While that's a nice way to approach a mathematical problem, it does not take into account the social aspects of the problem. For example, it used to be (and perhaps still is?) quite common for families to aspire to have a boy and therefore have another child when they have a girl, but not when they have a boy.

Interestingly, these sort of things are much easier to model empirically the way you did (all you would need is a small tweak to the "haveAKid" condition in the while loop around line 35), whereas the math gets pretty complicated fast.

Re:Do men or women have more brothers? by dhimes on Monday May 23, 2016 @04:16PM (#11756585)
Well, it was posted in probability and not is some social science board. So I thought it was safe to assume a purely mathematical question. Not that I can answer it...
Re:Do men or women have more brothers? by mudbungie on Monday May 23, 2016 @05:12PM (#11757042)
Yeah, I wrote that after staring at it for a few minutes, and giving up any pretense that I could model it with confidence.
Re:Do men or women have more brothers? by oh_sigh on Monday May 23, 2016 @04:36PM (#11756745)
Social and biological aspects. Assume there may be some genetic factor which makes it impossible(or even just less equal-odds) for a pair to produce a female, or male. If that's the case, men will on average have more brothers than women do.
Re:Do men or women have more brothers? by sp332 on Monday May 23, 2016 @04:24PM (#11756644)
I think you forgot to put quotes around "Girl" on line 46. Edit: Actually I'm not sure what the problem is but I'm getting 0 girls and a divide-by-0 error.

Edit2: I don't remember why I was getting all girls, but the other issue was integer division. If boybrothers/boys truncates to 0, then (girlbrothers/girls)/(boybrothers/boys) will divide by 0.

Re:Do men or women have more brothers? by mudbungie on Monday May 23, 2016 @05:04PM (#11756969)
Actually, line 46 is referencing the class Girl, so you wouldn't want quotes. Technically, you're supposed to use try/except duck-typing in Python, but I often find that clearer code comes out of assertions where you literally check the type of an object instead of handling errors. This was no exception. (Sorry, bad pun)

You might try throwing in a random seed. I just trusted that my system would iterate enough that it wouldn't matter, but if you're getting all boys (I'm not sure that's the case, but you said that you're getting 0 girls...), it could be that for whatever reason, the system might not be advancing the seed. Try inserting the following two lines immediately after import random:

from datetime import datetime

random.seed(datetime.now())

Re:Do men or women have more brothers? by kqr on Monday May 23, 2016 @05:30PM (#11757186)
Run it in Python 3.
Re:Do men or women have more brothers? by sp332 on Monday May 23, 2016 @05:32PM (#11757209)
Yeah in hindsight that was pretty obvious. I guess the real bug was leaving off the #! line :)
Re:Do men or women have more brothers? by kqr on Monday May 23, 2016 @05:29PM (#11757179)
I'm surprised you managed to make it that complicated! http://pastebin.com/fck8qkMc
Re:Do men or women have more brothers? by mudbungie on Monday May 23, 2016 @05:44PM (#11757295)
I like your solution! Good use of iter().

You actually bring up an interesting question of design philosophies. I thought that the script that I posted was extremely explicit, and therefore clear. Yours is far more terse, and implicit, which means that there's less to understand, but there is some onus on the reader to decode what is happening.

I'm not sure which is better, as a policy. Obviously, solving problems with fewer lines is desirable, but it's also good to make solutions that are intrinsically obvious.

Re:Do men or women have more brothers? by kqr on Tuesday May 24, 2016 @12:51AM (#11759051)
It is as they say: every problem can be solved with an additional level of indirection... except the problem of too many levels of indirection.