Skip to content

Commit e130ce9

Browse files
author
L. Grondin
committed
[rosalind] LIA
1 parent fc6cc65 commit e130ce9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

rosalind/lia-grondilu.pl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use v6;
2+
3+
my ($k, $N) = $*IN.get.split(" ".Int;
4+
5+
my %p = <AA Aa aa> Z=> <0 1 0>;
6+
for ^$k {
7+
%p =
8+
:AA(2 * [+] %p<AA Aa aa> Z* <1/2 1/4 0>),
9+
:Aa(2 * [+] %p<AA Aa aa> Z* <1/2 1/2 1/2>),
10+
:aa(2 * [+] %p<AA Aa aa> Z* <0 1/4 1/2>),
11+
;
12+
}
13+
die unless 2**$k == [+] %p.values;
14+
my $p = %p<Aa> / 2**$k;
15+
$p *= $p;
16+
17+
sub postfix:<!>($a) { [*] 1..$a }
18+
sub binomialcoefficient($n, $k) {
19+
$n!
20+
/ (($n - $k)! * $k!);
21+
}
22+
my $total = 2**$k;
23+
say [+] map -> $i { (1-$p)**($total - $i)*$p**$i * binomialcoefficient( $total, $i ) }, $N .. $total;
24+
25+
# vim: ft=perl6

0 commit comments

Comments
 (0)