Jump to content

Eertree: Difference between revisions

2,366 bytes added ,  6 years ago
→‎{{header|REXX}}: added the REXX language.
No edit summary
(→‎{{header|REXX}}: added the REXX language.)
Line 341:
{{out}}
<pre>'("t" "rtr" "ertre" "eertree" "r" "e" "ee")</pre>
 
=={{header|REXX}}==
This REXX program is modeled after the &nbsp; '''Ring''' &nbsp; example.
<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.*/
L=length(x) /*the length (in chars) of input string*/
@.=. /*@ tree indicates uniqueness of pals. */
$= /*list of unsorted & unique palindromes*/
 
do j=1 for L /*start at the left side of the string.*/
 
do k=1 for L /*traverse from left to right of string*/
parse var x =(j) y +(k) /*extract a substring from the string. */
if reverse(y)\==y then iterate /*Partial string a palindrome? Skip it*/
if @.y\==. then iterate /*Sub─palindrome already exist? Skip it*/
@.y=y /*indicate a sub─palindrome was found. */
$=$' ' y /*append the sub─palindrome to the list*/
end /*k*/ /* [↑] an extra blank is inserted. */
 
end /*j*/
 
pad=copies('─', 8) /*a fence to be used as an eyecatcher. */
say pad 'Using the input string: ' x /*echo the input string being parsed.*/
say
#=words($) /*get the number of palindromes found. */
subP= 'sub─palindromes' /*a literal to make SAY texts shorter. */
say pad 'The number of' subP "found: " #
say
say pad 'The list of' subP "found: "
say strip($) /*display the list of the palindromes. */
/*stick a fork in it, we're all done. */</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
──────── Using the input string: eertree
 
──────── The number of sub─palindromes found: 7
 
──────── The list of sub─palindromes found:
e ee eertree ertre r rtr t
</pre>
 
=={{header|Ring}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.