Comment Write code! (Score 3, Informative) 472
For work experience, sign up on freelancing sites like odesk. Take jobs just to do them. Nobody knows how old you are, there. Even if all you can do is sysadmin -- well, admin some cloud services!
It's nearly the end of the year. I noticed I average about a post a year now on this once so fantastic news site that I barely check up on these days. I haven't seen the oodles of good posts that whooshed by, nor have I seen the inventive new types of trolls that lurked here since when I was in University. That's a perplexing 10 years ago by now.
OK, now with 3.13M families:
# echo 'select child1_gender,count(*) from families where child2_gender = "M" and child2_day=2 group by child1_gender;' | mysql test
child1_gender count(*)
F 111608
M 112037
50.095% male. If I remove the Tuesday constraint?
# echo 'select child1_gender,count(*) from families where child2_gender = "M" group by child1_gender;' | mysql test
child1_gender count(*)
F 783068
M 784087
50.03% male.
But you know, perhaps I'm being not literal enough. It's always possible to misencode a problem, and there's a lot of insistence that you have to handle the overlapping case of boy/boy. So, lets try a different mechanism. Lets literally do what the problem asks:
"I have two children, one of whom is a boy born on a Tuesday. What's the probability that my other child is a boy?"
For each family, if either of the children is male, return whether they are both male.
# echo 'select child1_gender=child2_gender from families where (child1_gender="M" and child1_day=2) or (child2_gender="M" and child2_day="2") ' | mysql test | sort | uniq -c | sort -n
1 child1_gender=child2_gender
207934 1
223445 0
...heh! That's kind of neat! I think I shall play with this some more.
Alright. It's 4:21AM, I'm in a random hotel room with a $400 voucher from Delta, and somewhere, someone on the Internet is wrong.
This sounds like a job for SQL.
First, lets start with a table:
# echo "describe families" | mysql test
Field Type Null Key Default Extra
child1_gender char(1) YES NULL
child1_day int(11) YES NULL
child2_gender char(1) YES NULL
child2_day int(11) YES NULL
Now, lets put a million records in it.
# echo "select count(*) from families" | mysql test
count(*)
1025537
# echo "select * from families limit 10" | mysql test
child1_gender child1_day child2_gender child2_day
F 1 M 0
F 4 M 3
M 1 F 1
F 5 M 1
M 0 M 3
F 0 F 3
M 0 M 2
M 4 F 1
M 6 M 3
F 3 F 1
(We're going to define 2 as Tuesday.) Now, lets look at the problem statement:
"I have two children, one of whom is a boy born on a Tuesday. What's the probability that my other child is a boy?"
We're going to translate that to, as in parent post.
Select the gender of all second children where the first child was born on a Tuesday and the first child was male.
Select the gender of all first children where the second child was born on a Tuesday and the second child was male.
Or, in actual SQL:
select child2_gender,count(*) from families where child1_gender = "M" and child1_day=2 group by child2_gender;
select child1_gender,count(*) from families where child2_gender = "M" and child2_day=2 group by child1_gender;
The results?
# echo 'select child2_gender,count(*) from families where child1_gender = "M" and child1_day=2 group by child2_gender;' | mysql test
child2_gender count(*)
F 36593
M 36617
# echo 'select child1_gender,count(*) from families where child2_gender = "M" and child2_day=2 group by child1_gender;' | mysql test
child1_gender count(*)
F 36811
M 37031
So, in the first set, we see 49.58% male for the other child. In the second set, we see 50.14% male for the other child.
And in myself, I find a renewed respect for numerical simulation. Happy Tuesday!
Thus spake the master programmer: "After three days without programming, life becomes meaningless." -- Geoffrey James, "The Tao of Programming"