Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
minor style rewrite
  • Loading branch information
grondilu committed May 10, 2013
1 parent 8da517c commit 22ef363
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions rosalind/suff-grondilu.pl
@@ -1,34 +1,29 @@
use v6;

my $dna = get;
sub suffixes(Str $str) { map *.flip, [\~] $str.flip.comb }
sub suffix-tree(@a) {
if (@a == 0) { [] }
elsif (@a == 1) { return hash @a[0] => [] }
else {
return hash gather for @a.classify(*.substr(0, 1)) {
my $subtree = suffix-tree([ grep *.chars, map *.substr(1), .value[] ]);
if $subtree.elems == 1 {
my $pair = $subtree.pick;
take .key ~ $pair.key => $pair.value;
} else {
take .key => $subtree;
}
}
@a == 0 ?? [] !!
@a == 1 ?? hash @a[0] => [] !!
hash gather for @a.classify(*.substr(0, 1)) {
my $subtree = suffix-tree([ grep *.chars, map *.substr(1), .value[] ]);
if $subtree.elems == 1 {
my $pair = $subtree.pick;
take .key ~ $pair.key => $pair.value;
} else {
take .key => $subtree;
}
}
}

sub show-edges($tree) {
return if $tree.elems == 0;
for $tree[] {
say .key;
show-edges .value;
say .key;
show-edges .value;
}
}

my $tree = suffix-tree(suffixes($dna));

show-edges $tree;
show-edges suffix-tree suffixes get;


# vim: ft=perl6

0 comments on commit 22ef363

Please sign in to comment.