This problem asks:

Given: A DNA string s of length at most 100 bp and an array A containing at most 20 numbers between 0 and 1.

Return: An array B having the same length as A in which B[k] represents the common logarithm of the probability that a random string constructed with the GC-content found in A[k] will match s exactly.

Required reading

  1. Logarithms
  2. More logarithms
  3. Probability theory
  4. GC-content

Restate the problem

I’m going to get a short DNA string, s, and an array, A, of up to 20 numbers between zero and one.

I need to return an array, B, the same length as A. Each number in B needs to be the common logarithm of the probability that a random string with the same GC-content as the corresponding value in A, will match s exactly.

What are the chances that a random string with a given GC-content will match s exactly?

Solution steps

First, I broke down the chance that the whole string s gets randomly generated into the product of all the chances that a single base pair will get randomly generated based on a given GC-content.

Then I cycled through each element in A and multiplied together all the single-character probabilities.

I used the math library to calculate the logarithms, rounded to three decimal places and printed the results to the console.