Punnett Squares
Description:
In biology, a genotype is the genetic make up of an individual which determines a specific trait. There are three possible ways to describe a genotype:
- Homozygous dominant. Represented by two upper case letters, e.g. BB.
- Heterozygous. Represented by an upper and lower case letter, e.g. Bb.
- Homozygous recessive. Represented by two lower case letters, e.g. bb.
Given the genotypes of each parent, a Punnett square can show the probablilty of the child's genotype. While this is a useful tool, it can be tedious to draw many times and calculate the probability of each genotype.
Your task is to write a function punnettSquare(father, mother)
, where father
and mother
are genotypes, for example punnettSquare("Bb", "BB")
. It will return an object containing (string array for C#):
- The Punnett square, including spaces and new lines for readability.
- The probabilty for each genotype listed above (dominant, heterozygous, and recessive). This is written as a number representing a percent eg. 50 means 50%.
Rules for the Punnett Square
- The square should always have the father genotype across the top of the table, and the mother genotype should be down the left side of the table.
- The square should include spaces and new lines to ensure readability. The format is "--B--b\nB-BB-bB\nb-Bb-bb", where - represents a space.
- The uppercase letter will always come before the lowercase letter in the square eg Bb instead of bB.
Example:
punnettSquare("Bb", "Bb")
should return
{ punnett:
" B b
B BB Bb
b Bb bb",
dominantProb: 25,
heterozygousProb: 50,
recessiveProb: 25 }
Example for C#:
PunnettSquare("Bb", "BB")
should return
string[] {" B b\nB BB Bb\nB BB Bb", "50", "50", "0"};
If both parents do not have exactly 2 letters, return false. For C# it should return null. Any letters may be used for the genotypes.
Similar Kata:
Stats:
Created | Nov 22, 2015 |
Published | Nov 28, 2015 |
Warriors Trained | 171 |
Total Skips | 69 |
Total Code Submissions | 138 |
Total Times Completed | 22 |
JavaScript Completions | 17 |
C# Completions | 6 |
Total Stars | 7 |
% of votes with a positive feedback rating | 88% of 13 |
Total "Very Satisfied" Votes | 10 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 13 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |