From f95eb52ac418ed3d4f1f2b34ba946e8081c7fa34 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 25 Oct 2012 02:56:04 -0500 Subject: another solution --- EVAL.pl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 EVAL.pl (limited to 'EVAL.pl') 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); +} -- cgit v1.2.3-54-g00ecf