Eertree: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Phix}}: added syntax colouring, made p2js compatible)
m (syntax highlighting fixup automation)
Line 22:
{{trans|D}}
 
<langsyntaxhighlight lang="11l">T Node
Int length
Int suffix
Line 86:
 
V tree = eertree(‘eertree’)
print(subPalindromes(tree))</langsyntaxhighlight>
 
{{out}}
Line 95:
=={{header|C sharp|C#}}==
{{trans|Java}}
<langsyntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
 
Line 190:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>[ee, e, r, t, rtr, ertre, eertree]</pre>
Line 196:
=={{header|C++}}==
{{trans|D}}
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <functional>
#include <map>
Line 316:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>[ee, e, r, t, rtr, ertre, eertree]</pre>
Line 322:
=={{header|D}}==
{{trans|Go}}
<langsyntaxhighlight Dlang="d">import std.array;
import std.stdio;
 
Line 393:
}
return s.data;
}</langsyntaxhighlight>
{{out}}
<pre>["ee", "e", "r", "t", "rtr", "ertre", "eertree"]</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 471:
}
return
}</langsyntaxhighlight>
{{out}}
<pre>
Line 479:
=={{header|Java}}==
{{trans|D}}
<langsyntaxhighlight Javalang="java">import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Line 569:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>[ee, r, t, rtr, ertre, eertree, e]</pre>
Line 575:
=={{header|Julia}}==
{{trans|Python}}
<langsyntaxhighlight lang="julia">mutable struct Node
edges::Dict{Char, Node}
link::Union{Node, Missing}
Line 653:
 
eertree("eertree")
</langsyntaxhighlight> {{output}} <pre>
Results of processing string "eertree":
Number of sub-palindromes: 7
Line 661:
=={{header|Kotlin}}==
{{trans|Python}}
<langsyntaxhighlight lang="scala">// version 1.1.4
 
class Node {
Line 779:
val result = eertree.getSubPalindromes()
println("Sub-palindromes: $result")
}</langsyntaxhighlight>
 
{{out}}
Line 789:
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
If Version<9.5 Then exit
If Version=9.5 And Revision<2 Then Exit
Line 866:
 
Print Palindromes$(eertree("eertree"))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 874:
=={{header|Nim}}==
{{trans|Kotlin}}
<langsyntaxhighlight Nimlang="nim">import algorithm, strformat, strutils, tables
 
type
Line 987:
echo fmt"Number of sub-palindromes: {eertree.nodes.len}"
let result = eertree.getSubPalindromes()
echo fmt"Sub-palindromes: {result.join("", "")}"</langsyntaxhighlight>
 
{{out}}
Line 996:
=={{header|Objeck}}==
{{trans|Java}}
<langsyntaxhighlight lang="objeck">use Collection.Generic;
 
class Eertree {
Line 1,127:
return @edges;
}
}</langsyntaxhighlight>
 
{{output}}
Line 1,136:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">$str = "eertree";
 
for $n (1 .. length($str)) {
Line 1,151:
}
 
print join ' ', grep {not $seen{$_}++} @pal, "\n";</langsyntaxhighlight>
{{out}}
<pre>e ee eertree ertre r rtr t</pre>
Line 1,157:
=={{header|Phix}}==
If you use this in anger it may be wise to replace {string chars, sequence next} with a dictionary, which can obviously be either a new dictionary for each node, or perhaps better a single/per tree dictionary keyed on {n,ch}.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">enum</span> <span style="color: #000000;">LEN</span><span style="color: #0000FF;">,</span><span style="color: #000000;">SUFF</span><span style="color: #0000FF;">,</span><span style="color: #000000;">CHARS</span><span style="color: #0000FF;">,</span><span style="color: #000000;">NEXT</span>
Line 1,237:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
{{out}}
The tree matches Fig 1 in the pdf linked above.
Line 1,257:
=={{header|Python}}==
 
<langsyntaxhighlight lang="python">#!/bin/python
from __future__ import print_function
 
Line 1,361:
eertree.get_sub_palindromes(eertree.rto, [eertree.rto], [], result) #Odd length words
eertree.get_sub_palindromes(eertree.rte, [eertree.rte], [], result) #Even length words
print ("Sub-palindromes:", result)</langsyntaxhighlight>
 
{{out}}
Line 1,371:
{{trans|Python}}
 
<langsyntaxhighlight lang="racket">#lang racket
(struct node (edges ; edges (or forward links)
link ; suffix link (backward links)
Line 1,456:
(for ((c "eertree")) (eertree-add! et (char->integer c)))
(map (compose list->string (curry map integer->char)) (eertree-get-palindromes et)))
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,464:
(formerly Perl 6)
{{trans|Ring}}
<syntaxhighlight lang="raku" perl6line>my $str = "eertree";
my @pal = ();
my ($strrev,$strpal);
Line 1,482:
 
say @pal.unique;
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,490:
=={{header|REXX}}==
This REXX program is modeled after the &nbsp; '''Ring''' &nbsp; example.
<langsyntaxhighlight lang="rexx">/*REXX program creates a list of (unique) sub─palindromes that exist in an input string.*/
parse arg x . /*obtain optional input string from CL.*/
if x=='' | x=="," then x= 'eertree' /*Not specified? Then use the default.*/
Line 1,508:
say '──────── The number of sub─palindromes found: ' words($)
say '──────── The list of sub─palindromes found: ' strip($)
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
Line 1,517:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Eertree
 
Line 1,543:
next
see sortpal + nl
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,557:
=={{header|Ruby}}==
{{trans|D}}
<langsyntaxhighlight lang="ruby">class Node
def initialize(length, edges = {}, suffix = 0)
@length = length
Line 1,635:
 
tree = eertree("eertree")
print subPalindromes(tree), "\n"</langsyntaxhighlight>
{{out}}
<pre>["ee", "e", "r", "t", "rtr", "ertre", "eertree"]</pre>
Line 1,641:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<langsyntaxhighlight lang="vbnet">Module Module1
 
Class Node
Line 1,737:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre>[ee, e, r, t, rtr, ertre, eertree]</pre>
Line 1,743:
=={{header|Wren}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="ecmascript">class Node {
construct new() {
_edges = {} // edges (or forward links)
Line 1,861:
System.print("Number of sub-palindromes: %(eertree.nodes.count)")
var result = eertree.getSubPalindromes()
System.print("Sub-palindromes: %(result)")</langsyntaxhighlight>
 
{{out}}
Line 1,872:
=={{header|zkl}}==
{{trans|Python}}
<langsyntaxhighlight lang="zkl">class Node{
fcn init(length){
var edges=Dictionary(), # edges (or forward links). (char:Node)
Line 1,947:
}
}
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">st:="eertree";
println("Processing string \"", st,"\"");
eertree:=Eertree(st);
println("Number of sub-palindromes: ", eertree.nodes.len());
println("Sub-palindromes: ", eertree.get_sub_palindromes());</langsyntaxhighlight>
{{out}}
<pre>
10,333

edits