匹配随机基序
作者:L. Grondin
http://rosalind.info/problems/rstr/
示例输入
90000 0.6 ATAGCCGA
示例输出
0.689
源代码: rstr-grondilu.pl
use v6; my @default-input = ("90000 0.6", "ATAGCCGA"); sub MAIN($input-file = Nil) { my @data = $input-file ?? $input-file.IO.lines !! @default-input; my ($N, $gc-content) = @data.shift.split: " "; my $dna = @data.shift; my $result = 1 - exp ($N * log(1-prob :$dna, :$gc-content)); say $result.fmt("%.3f"); } sub prob(:$dna, :$gc-content) { 1/2**$dna.chars * [*] map { $_ eq 'G'|'C' ?? $gc-content !! (1 - $gc-content) }, $dna.comb }