Lychrel numbers: Difference between revisions

Content added Content deleted
(→‎{{header|Haskell}}: make it infinite list)
m (→‎{{Header|REXX}}: allowed the specification for the LIMIT, added/changed whitespace and comments.)
Line 2,953: Line 2,953:
=={{Header|REXX}}==
=={{Header|REXX}}==
<lang rexx>/*REXX program finds and displays Lychrel numbers, related numbers, and palindromes. */
<lang rexx>/*REXX program finds and displays Lychrel numbers, related numbers, and palindromes. */
numeric digits 250 /*ensure enough decimal digits for adds*/
parse arg high limit . /*obtain optional argument from the CL.*/
parse arg high . /*obtain optional argument from the CL.*/
if high='' | high=="," then high= 10000 /*Not specified? Then use the default.*/
if high='' | high=="," then high= 10000 /*Not specified? Then use the default.*/
if limit='' | limit=="," then limit= 500 /*Not specified? Then use the default.*/
limit= 500 /*limit: number of Lychrel iterations.*/
numeric digits limit % 2 /*ensure enough decimal digits for adds*/
T.= 0; @.= T.; #.=@.; w= length(high) /*W: is used for formatting numbers. */
T.= 0; @.= T.; #.=@.; w= length(high) /*W: is used for formatting numbers. */
$= /*the list of Lychrel numbers. */
$= /*the list of Lychrel numbers. */
do j=1 for high; call Lychrel j /*find the Lychrel numbers. */
do j=1 for high; call Lychrel j /*find the Lychrel numbers. */
end /*j*/
end /*j*/
p=; R= /*P: list of palindromes; R: related #s*/
p=; R= /*P: list of palindromes; R: related #s*/
do k=1 for high
do k=1 for high
if #.k then $= $ k /*build a list of Lychrel numbers. */
if #.k then $= $ k /*build a list of Lychrel numbers. */
if T.k then R= R k /* " " " " " related nums.*/
if T.k then R= R k /* " " " " " related nums.*/
if T.k & k==reverse(k) then p= p k /* " " " " " palindromes. */
if T.k & k==reverse(k) then p= p k /* " " " " " palindromes. */
end /*k*/
end /*k*/


say 'Found in the range 1 to ' high " (limiting searches to " limit ' steps):'
say 'Found in the range 1 to ' high " (limiting searches to " limit ' steps):'
say
say
say right(words($) , w) 'Lychrel numbers:' $
say right( words($) , w) 'Lychrel numbers:' $
say right(words(R) - words($), w) 'Lychrel related numbers.'
say right( words(R) - words($), w) 'Lychrel related numbers.'
say right(words(p) , w) 'Lychrel palindromes:' p
say right( words(p) , w) 'Lychrel palindromes:' p
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/