Eertree: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|Phix}}: added syntax colouring, made p2js compatible) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 22:
{{trans|D}}
<
Int length
Int suffix
Line 86:
V tree = eertree(‘eertree’)
print(subPalindromes(tree))</
{{out}}
Line 95:
=={{header|C sharp|C#}}==
{{trans|Java}}
<
using System.Collections.Generic;
Line 190:
}
}
}</
{{out}}
<pre>[ee, e, r, t, rtr, ertre, eertree]</pre>
Line 196:
=={{header|C++}}==
{{trans|D}}
<
#include <functional>
#include <map>
Line 316:
return 0;
}</
{{out}}
<pre>[ee, e, r, t, rtr, ertre, eertree]</pre>
Line 322:
=={{header|D}}==
{{trans|Go}}
<
import std.stdio;
Line 393:
}
return s.data;
}</
{{out}}
<pre>["ee", "e", "r", "t", "rtr", "ertre", "eertree"]</pre>
=={{header|Go}}==
<
import "fmt"
Line 471:
}
return
}</
{{out}}
<pre>
Line 479:
=={{header|Java}}==
{{trans|D}}
<
import java.util.HashMap;
import java.util.List;
Line 569:
}
}
}</
{{out}}
<pre>[ee, r, t, rtr, ertre, eertree, e]</pre>
Line 575:
=={{header|Julia}}==
{{trans|Python}}
<
edges::Dict{Char, Node}
link::Union{Node, Missing}
Line 653:
eertree("eertree")
</
Results of processing string "eertree":
Number of sub-palindromes: 7
Line 661:
=={{header|Kotlin}}==
{{trans|Python}}
<
class Node {
Line 779:
val result = eertree.getSubPalindromes()
println("Sub-palindromes: $result")
}</
{{out}}
Line 789:
=={{header|M2000 Interpreter}}==
<syntaxhighlight 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>
{{out}}
<pre>
Line 874:
=={{header|Nim}}==
{{trans|Kotlin}}
<
type
Line 987:
echo fmt"Number of sub-palindromes: {eertree.nodes.len}"
let result = eertree.getSubPalindromes()
echo fmt"Sub-palindromes: {result.join("", "")}"</
{{out}}
Line 996:
=={{header|Objeck}}==
{{trans|Java}}
<
class Eertree {
Line 1,127:
return @edges;
}
}</
{{output}}
Line 1,136:
=={{header|Perl}}==
{{trans|Raku}}
<
for $n (1 .. length($str)) {
Line 1,151:
}
print join ' ', grep {not $seen{$_}++} @pal, "\n";</
{{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}.
<!--<
<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>
<!--</
{{out}}
The tree matches Fig 1 in the pdf linked above.
Line 1,257:
=={{header|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)</
{{out}}
Line 1,371:
{{trans|Python}}
<
(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>
{{out}}
Line 1,464:
(formerly Perl 6)
{{trans|Ring}}
<syntaxhighlight lang="raku"
my @pal = ();
my ($strrev,$strpal);
Line 1,482:
say @pal.unique;
</syntaxhighlight>
{{out}}
<pre>
Line 1,490:
=={{header|REXX}}==
This REXX program is modeled after the '''Ring''' example.
<
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. */</
{{out|output|text= when using the default input:}}
<pre>
Line 1,517:
=={{header|Ring}}==
<
# Project : Eertree
Line 1,543:
next
see sortpal + nl
</syntaxhighlight>
Output:
<pre>
Line 1,557:
=={{header|Ruby}}==
{{trans|D}}
<
def initialize(length, edges = {}, suffix = 0)
@length = length
Line 1,635:
tree = eertree("eertree")
print subPalindromes(tree), "\n"</
{{out}}
<pre>["ee", "e", "r", "t", "rtr", "ertre", "eertree"]</pre>
Line 1,641:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<
Class Node
Line 1,737:
End Sub
End Module</
{{out}}
<pre>[ee, e, r, t, rtr, ertre, eertree]</pre>
Line 1,743:
=={{header|Wren}}==
{{trans|Kotlin}}
<
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)")</
{{out}}
Line 1,872:
=={{header|zkl}}==
{{trans|Python}}
<
fcn init(length){
var edges=Dictionary(), # edges (or forward links). (char:Node)
Line 1,947:
}
}
}</
<
println("Processing string \"", st,"\"");
eertree:=Eertree(st);
println("Number of sub-palindromes: ", eertree.nodes.len());
println("Sub-palindromes: ", eertree.get_sub_palindromes());</
{{out}}
<pre>
|