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. */ |
||
parse arg high limit . /*obtain optional argument from the CL.*/ |
|||
if high='' | high=="," then high= 10000 /*Not specified? Then use the default.*/ |
|||
if |
if limit='' | limit=="," then limit= 500 /*Not specified? Then use the default.*/ |
||
numeric digits limit % 2 /*ensure enough decimal digits for adds*/ |
|||
T.= 0; @.= T.; #.=@.; w= length(high) |
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 |
do j=1 for high; call Lychrel j /*find the Lychrel numbers. */ |
||
end /*j*/ |
end /*j*/ |
||
p=; |
p=; R= /*P: list of palindromes; R: related #s*/ |
||
do k=1 for high |
do k=1 for high |
||
if #.k then $= $ k |
if #.k then $= $ k /*build a list of Lychrel numbers. */ |
||
if T.k then R= R k |
if T.k then R= R k /* " " " " " related nums.*/ |
||
if T.k & k==reverse(k) then p= p k |
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. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |