Eertree: Difference between revisions

m
→‎{{header|REXX}}: simplified the DO loop, added/changed comments and whitespace.
(Undo revision 272773 by Wherrera (talk))
m (→‎{{header|REXX}}: simplified the DO loop, added/changed comments and whitespace.)
Line 809:
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 | @.y\==. then iterate /*Partial string a palindrome? Skip it*/
if @.y\==. y then iterate /*Sub─palindromeindicate alreadya exist?sub─palindrome Skipwas found. it*/
@.y$=y $' ' y /*indicateappend athe sub─palindrome wasto found.the list*/
end $=$' ' y /*k*/ /*append the[↑] an extra blank is inserted. sub─palindrome to the list*/
end /*j*/
end /*k*/ /* [↑] an extra blank is inserted. */
end /*j*/
 
say '──────── The input string being used: ' space(x)
pad=copies('─', 8) /*a fence to be used as an eyecatcher. */
say '──────── The listnumber of sub─palindromes found: ' words($)
say pad 'Using the input string: ' x /*echo the input string being parsed.*/
say '──────── The list of sub─palindromes found: ' strip($)
say
#=words($) /*getstick thea numberfork ofin palindromesit, found we're all done. */</lang>
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: " /*display the list of the palindromes. */
say strip($) /*stick a fork in it, we're all done. */</lang>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
──────── Using theThe input string being used: eertree
 
──────── The number of sub─palindromes found: 7
──────── The list of sub─palindromes found: e ee eertree ertre r rtr t
 
──────── The list of sub─palindromes found:
e ee eertree ertre r rtr t
</pre>