user
An **eertree** is a data structure designed for efficient processing of certain palindrome tasks, for instance counting the number of sub-palindromes in an input string.

The data structure has commonalities to both *tries* and *suffix trees*.
  See links below.

Task

Construct an eertree for the string "eertree", then output all sub-palindromes by traversing the tree.

See also

* Wikipedia entry:   trie.
* Wikipedia entry:   suffix tree
* Cornell University Library, Computer Science, Data Structures and Algorithms ───► EERTREE: An Efficient Data Structure for Processing Palindromes in Strings.
* EERTREE: An efficient data structure for processing palindromes in strings[1]
assistant
(formerly Perl 6)

**Translation of**: Ring

```
my $str = "eertree";
my @pal = ();
my ($strrev,$strpal);

for (1 .. $str.chars) -> $n {
   for (1 .. $str.chars) -> $m {
      $strrev = "";
      $strpal = $str.substr($n-1, $m);
      if ($strpal ne "") {
         for ($strpal.chars ... 1) -> $p {
            $strrev ~= $strpal.substr($p-1,1);
         }
         ($strpal eq $strrev) and @pal.push($strpal);
      }
   }
}

say @pal.unique;

```

Output:

```
(e ee eertree ertre r rtr t)

```