Distinct palindromes within decimal numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: allowed the use of numbers/words of any length, not just the width of last entry.)
m (→‎{{header|REXX}}: added the extra strings used by another programming language entry.)
Line 333: Line 333:


=={{header|REXX}}==
=={{header|REXX}}==
This REXX version can handle strings or numbers,   a hexadecimal string is included in the examples.
This REXX version can handle strings or numbers.
<lang>/*REXX program finds distinct palindromes contained in substrings (of decimal numbers). */
<lang>/*REXX program finds distinct palindromes contained in substrings (of decimal numbers). */
parse arg LO HI mL $$ /*obtain optional arguments from the CL*/
parse arg LO HI mL $$ /*obtain optional arguments from the CL*/
Line 341: Line 341:
if $$='' | $$="," then $$= 9 169 12769 1238769 12346098769 1234572098769 123456832098769,
if $$='' | $$="," then $$= 9 169 12769 1238769 12346098769 1234572098769 123456832098769,
12345679432098769 1234567905432098769 123456790165432098769 ,
12345679432098769 1234567905432098769 123456790165432098769 ,
83071934127905179083 'deadbeef' /* (hexadecimal) */ ,
83071934127905179083 1320267947849490361205695,
1320267947849490361205695 /* special numbers.*/
'Do these strings contain a minimum two character palindrome?'
w= length(HI) /*max width of LO ──► HI for alignment.*/
w= length(HI) /*max width of LO ──► HI for alignment.*/


Line 349: Line 349:
end /*j*/
end /*j*/


w= length( word($$, words($$) ) ) /*find the length of the last special #*/
#= words($$); if #==0 then exit 0 /*No special words/numbers? Then exit.*/

if words($$)==0 then exit 0 /*No special words/numbers? Then exit.*/
do m=1 for #; w= max(w, length(word($$, m))) /*find max width string in $$*/
end /*m*/
say
say
do j=1 for words($$); z= word($$, j)
do j=1 for #; z= word($$, j) /*obtain a string in the $$ list. */
#= Dpal(z, mL); w= max(w, length(z) ) /*get # distinct palindromes, minLen=mL*/
#= Dpal(z, mL) /*get # distinct palindromes, minLen=mL*/
_= left(':', #>0); @has= ' has '; @of='of length'
_= left(':', #>0); @has= ' has '; @of='of length'
say right(z, w) @has # " palindrome"s(#,,' ') @of mL "or more"_ space($)
say right(z, w) @has # " palindrome"s(#,,' ') @of mL "or more"_ space($)
Line 410: Line 412:
123456790165432098769 has 0 palindromes of length 2 or more
123456790165432098769 has 0 palindromes of length 2 or more
83071934127905179083 has 0 palindromes of length 2 or more
83071934127905179083 has 0 palindromes of length 2 or more
deadbeef has 1 palindrome of length 2 or more: ee
1320267947849490361205695 has 3 palindromes of length 2 or more: 202 494 949
1320267947849490361205695 has 3 palindromes of length 2 or more: 202 494 949
Do has 0 palindromes of length 2 or more
these has 1 palindrome of length 2 or more: ese
strings has 0 palindromes of length 2 or more
contain has 0 palindromes of length 2 or more
a has 0 palindromes of length 2 or more
minimum has 3 palindromes of length 2 or more: minim ini mum
two has 0 palindromes of length 2 or more
character has 1 palindrome of length 2 or more: ara
palindrome? has 0 palindromes of length 2 or more
</pre>
</pre>