Permalink
Browse files

[rosalind] NWCK

  • Loading branch information...
grondilu committed Dec 9, 2012
1 parent 8805265 commit 562f7bdad4b48a82eb94691351f0919e0542f3d3
Showing with 18 additions and 0 deletions.
  1. +18 −0 rosalind/nwck-grondilu.pl
View
@@ -0,0 +1,18 @@
+use v6;
+say gather for lines[] -> $newick, $taxa, $ {
+ my ($a, $b) = $taxa.split: ' ';
+ my @token = $newick.comb: rx/ <.ident>+ | <[(),]> /;
+ Mu while @token.shift ne $a|$b;
+ my ($climbs, $descents) = 0 xx 2;
+ for @token {
+ last if $_ eq $a or $_ eq $b;
+ if /< , ) >/ {
+ if $descents > 0 { $descents-- }
+ else { $climbs++ }
+ }
+ if /< , ( >/ { $descents++ }
+ }
+ take $climbs + $descents;
+}
+
+# vim: ft=perl6

0 comments on commit 562f7bd

Please sign in to comment.