Skip to content

Commit

Permalink
[rosalind] NWCK
Browse files Browse the repository at this point in the history
  • Loading branch information
grondilu committed Dec 9, 2012
1 parent 8805265 commit 562f7bd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions rosalind/nwck-grondilu.pl
@@ -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.