Skip to content

Commit 562f7bd

Browse files
author
L. Grondin
committed
[rosalind] NWCK
1 parent 8805265 commit 562f7bd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

rosalind/nwck-grondilu.pl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use v6;
2+
say gather for lines[] -> $newick, $taxa, $ {
3+
my ($a, $b) = $taxa.split: ' ';
4+
my @token = $newick.comb: rx/ <.ident>+ | <[(),]> /;
5+
Mu while @token.shift ne $a|$b;
6+
my ($climbs, $descents) = 0 xx 2;
7+
for @token {
8+
last if $_ eq $a or $_ eq $b;
9+
if /< , ) >/ {
10+
if $descents > 0 { $descents-- }
11+
else { $climbs++ }
12+
}
13+
if /< , ( >/ { $descents++ }
14+
}
15+
take $climbs + $descents;
16+
}
17+
18+
# vim: ft=perl6

0 commit comments

Comments
 (0)