We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8805265 commit 562f7bdCopy full SHA for 562f7bd
rosalind/nwck-grondilu.pl
@@ -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