-
-
Save grondilu/5978369 to your computer and use it in GitHub Desktop.
Rosalind: character based phylogeny in Perl 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
my @sample = « | |
'cat dog elephant mouse rabbit rat' | |
011101 | |
001101 | |
001100 | |
»; | |
my $species = set my @species = @sample.shift.words; #get.words; | |
my @split = map { | |
item set map *.key, grep *.value, hash @species Z=> .comb | |
}, @sample; #lines; | |
loop { | |
for terminal-split() { | |
my $ancestor = "({join ',', .list.sort})"; | |
note $species = set ($species (-) $_), $ancestor; | |
say "({join ",", $species.list});" and exit if $species.elems == 3; | |
for @split -> $split is rw { | |
if $_ (<=) $split { | |
$split = $split (-) $_; | |
$split = set $split, $ancestor; | |
} | |
} | |
} | |
} | |
sub terminal-split { | |
gather for @split { | |
take .item if .elems == 2; | |
take item $species (-) $_ if .elems == $species.elems - 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment