Eertree: Difference between revisions

Content added Content deleted
(Go solution)
m (→‎{{header|REXX}}: elided superfluous blank lines.)
Line 436: Line 436:
This REXX program is modeled after the   '''Ring'''   example.
This REXX program is modeled after the   '''Ring'''   example.
<lang rexx>/*REXX program creates a list of (unique) sub─palindromes that exist in an input string.*/
<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.*/
parse arg x . /*obtain optional input string from CL.*/
if x=='' | x=="," then x= 'eertree' /*Not specified? Then use the default.*/
if x=='' | x=="," then x= 'eertree' /*Not specified? Then use the default.*/
Line 442: Line 441:
@.=. /*@ tree indicates uniqueness of pals. */
@.=. /*@ tree indicates uniqueness of pals. */
$= /*list of unsorted & unique palindromes*/
$= /*list of unsorted & unique palindromes*/

do j=1 for L /*start at the left side of the string.*/
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*/
do k=1 for L /*traverse from left to right of string*/
parse var x =(j) y +(k) /*extract a substring from the string. */
parse var x =(j) y +(k) /*extract a substring from the string. */
Line 452: Line 449:
$=$' ' y /*append the sub─palindrome to the list*/
$=$' ' y /*append the sub─palindrome to the list*/
end /*k*/ /* [↑] an extra blank is inserted. */
end /*k*/ /* [↑] an extra blank is inserted. */

end /*j*/
end /*j*/


Line 460: Line 456:
#=words($) /*get the number of palindromes found. */
#=words($) /*get the number of palindromes found. */
subP= 'sub─palindromes' /*a literal to make SAY texts shorter. */
subP= 'sub─palindromes' /*a literal to make SAY texts shorter. */
say pad 'The number of' subP "found: " #
say pad 'The number of' subP "found: " #
say
say
say pad 'The list of' subP "found: "
say pad 'The list of' subP "found: " /*display the list of the palindromes. */
say strip($) /*display the list of the palindromes. */
say strip($) /*stick a fork in it, we're all done. */</lang>
/*stick a fork in it, we're all done. */</lang>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}
<pre>
<pre>