diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-10-25 02:56:04 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-10-25 02:56:04 -0500 |
commit | f95eb52ac418ed3d4f1f2b34ba946e8081c7fa34 (patch) | |
tree | d17c80f1d06c83b434401fcbe907c73776ba232a /EVAL.pl | |
parent | 4550e7c7a184a8786a204ed6962a7e2302eb6baf (diff) | |
download | rosalind-f95eb52ac418ed3d4f1f2b34ba946e8081c7fa34.tar.gz rosalind-f95eb52ac418ed3d4f1f2b34ba946e8081c7fa34.zip |
another solution
Diffstat (limited to 'EVAL.pl')
-rw-r--r-- | EVAL.pl | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -0,0 +1,17 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.016; + +chomp(my ($small_len, $large_len) = split ' ', scalar <>); +chomp(my @probabilities = split ' ', scalar <>); +say join ' ', map { calculate_probability($small_len, $large_len, $_) } + @probabilities; + +sub calculate_probability { + my ($small_len, $large_len, $gc) = @_; + + my $single_char_chance = (($gc / 2) ** 2) * 2 + (((1 - $gc) / 2) ** 2) * 2; + my $substring_chance = $single_char_chance ** $small_len; + return $substring_chance * ($large_len - $small_len + 1); +} |