Expected Offspring Phenotypes

Foundational Computational Biology Probability Expected Value Mendelian Genetics Linearity
Significance:

Expected value is linear regardless of whether the underlying events are independent,
which is what makes this calculation so much simpler than it first appears. Genetic counsellors use
exactly this reasoning to estimate how many children in a cohort will express a trait, and the same
linearity argument underpins the expected-count calculations in every population genetics model.

Statement

You are given six integers giving the number of couples in a population with each of
these genotype pairings, in order:

  1. AA x AA
  2. AA x Aa
  3. AA x aa
  4. Aa x Aa
  5. Aa x aa
  6. aa x aa

Every couple produces exactly two offspring.

Compute the expected number of offspring displaying the dominant phenotype, and print it to five
decimal places
.

The probability that a single offspring shows the dominant phenotype is 1.0 for the first three
pairings, 0.75 for the fourth, 0.5 for the fifth, and 0.0 for the sixth.

Input — read from standard input
Variable Type Description
counts
line 1
str Six space-separated integers, the number of couples of each genotype pairing
each count between 0 and 20000

These variables are already read for you in the starter code on the right.

Output

str expected number of dominant-phenotype offspring, to five decimal places

Sample Cases
Sample 1
Input
1 0 0 1 0 1
Expected Output
3.50000
One couple of each of three pairings; only the first two contribute.
Sample 2
Input
18 15 6 27 24 30
Expected Output
142.50000
A larger population showing the weighted-sum behaviour.

Submit also runs your code against 5 hidden test cases. Hidden inputs are never shown — if one fails you'll get its number and a description of the mismatch, not the data.

Constraints
  • Exactly six integers on one line, separated by single spaces
  • 0 <= each count <= 20000
  • Every couple produces exactly two offspring
  • Output exactly five decimal places
Further Reading
  • Expected value is linear, so you can sum each pairing's contribution independently.
  • The contribution of a pairing is count * 2 * probability.
  • No combinatorics are needed at all — this is a weighted sum, nothing more.

My Notes
Log in to save personal notes.
Console output will appear here when you click Run Code or Submit...
Expected: counts (str)