Skip to content

Instantly share code, notes, and snippets.

@grondilu
Created July 11, 2013 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grondilu/5978369 to your computer and use it in GitHub Desktop.
Save grondilu/5978369 to your computer and use it in GitHub Desktop.
Rosalind: character based phylogeny in Perl 6
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