"In a country in which people only want boys, every family continues to have children until they have a boy. If they have a girl, they have another child. If they have a boy, they stop. What is the proportion of boys to girls in the country?"

Please post your solution + answer in the comments. GO!

-----

**Solution**-----

Thank you to all that emailed me and posted in the comments! The first responder with the correct answer was Gary H., however, he volunteered to disqualify himself because he had seen the question before (what a noble man!).

The

**winner**is

**Paul R.**A case of Snuggies is on it's way to you as your prize.

Honorable mention goes out to Dan D and Adam C. No, no honorable mention goes to Bad Dinosaur, he didn't even play.

**Here it is:**we assume that the probabilities of having a boy vs girl is 50%. Next, assume there are N families, so there will be N boys at the end (because the families keep going until they have a boy. N families. N boys). From the girl side, we can see the following:

round 1: N/2 have a boy and stop, N/2 have a girl, so N/2 girls so far

round 2: N/2 families left, 50% have a girl, so N/4 (0.5*N/2 = N/4)

round 3: N/4 families left, 50% have a girl, so N/8 (0.5*N/4 = N/8)

You get the idea. There will be an "infinite" sum equal to:

**N/2 + N/4 + N/8 ... N / infinity = N**

Note: this follows from Series basics (read more here).

So number of boys equals N, and number of girls equals N, the ratio is N:N or

**1:1**

The Monte Carlo simulation supports these findings (thanks to Paul R. for the lovely ruby code):

*Example output:*

Family problem, 1000000 trials:

997496 girls, 1000000 boys

1.997496 children per family

**0.997496 girls per boy**

`#!/usr/bin/env ruby`

# usage: ./family.rb [trials]

# Family problem, 1000000 trials:

#

# 997496 girls, 1000000 boys

# 1.997496 children per family

# 0.997496 girls per boy

#

# Ran in 15.508096s

# A spoonful of sugar helps the medicine go down

self[(length*Kernel.rand).floor]

end

end

@children = {:boy => 0, :girl => 0 }

complete! if complete

end

@children[:boy]

end

@children[:girl]

end

@children[[:boy, :girl].rand] += 1

end

have_child! until complete?

end

boys == 1

end

end

iterations = if ARGV.length > 0

ARGV[0].to_i

else

1000

end

puts "Family problem, trials:"

started = Time.new

children = {:boys => 0, :girls => 0 }

iterations.times do

f = Family.new

children[:boys] += f.boys

children[:girls] += f.girls

end

family_size = (children[:boys] + children[:girls]).to_f / iterations

ratio = children[:girls].to_f / children[:boys]

elapsed = Time.new - started

puts

puts " girls, boys"

puts " children per family"

puts " girls per boy"

puts

puts "Ran in s"

## 2 comments:

Friday Funnies are a lot more fun than Friday Mathies

Monte Carlo says 1:1 :)

http://gist.github.com/234913

## Post a Comment

Post a comment ...