summaryrefslogtreecommitdiffstats
path: root/EVAL.pl
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-10-25 02:56:04 -0500
committerJesse Luehrs <doy@tozt.net>2012-10-25 02:56:04 -0500
commitf95eb52ac418ed3d4f1f2b34ba946e8081c7fa34 (patch)
treed17c80f1d06c83b434401fcbe907c73776ba232a /EVAL.pl
parent4550e7c7a184a8786a204ed6962a7e2302eb6baf (diff)
downloadrosalind-f95eb52ac418ed3d4f1f2b34ba946e8081c7fa34.tar.gz
rosalind-f95eb52ac418ed3d4f1f2b34ba946e8081c7fa34.zip
another solution
Diffstat (limited to 'EVAL.pl')
-rw-r--r--EVAL.pl17
1 files changed, 17 insertions, 0 deletions
diff --git a/EVAL.pl b/EVAL.pl
new file mode 100644
index 0000000..de43118
--- /dev/null
+++ b/EVAL.pl
@@ -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);
+}