We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ac897af commit 8da517cCopy full SHA for 8da517c
rosalind/suff-grondilu.pl
@@ -0,0 +1,34 @@
1
+use v6;
2
+
3
+my $dna = get;
4
+sub suffixes(Str $str) { map *.flip, [\~] $str.flip.comb }
5
+sub suffix-tree(@a) {
6
+ if (@a == 0) { [] }
7
+ elsif (@a == 1) { return hash @a[0] => [] }
8
+ else {
9
+ return hash gather for @a.classify(*.substr(0, 1)) {
10
+ my $subtree = suffix-tree([ grep *.chars, map *.substr(1), .value[] ]);
11
+ if $subtree.elems == 1 {
12
+ my $pair = $subtree.pick;
13
+ take .key ~ $pair.key => $pair.value;
14
+ } else {
15
+ take .key => $subtree;
16
+ }
17
18
19
+}
20
21
+sub show-edges($tree) {
22
+ return if $tree.elems == 0;
23
+ for $tree[] {
24
+ say .key;
25
+ show-edges .value;
26
27
28
29
+my $tree = suffix-tree(suffixes($dna));
30
31
+show-edges $tree;
32
33
34
+# vim: ft=perl6
0 commit comments