Largest int from concatenated ints: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) m (→{{header|REXX}}: added Version 4) |
(→{{header|REXX}}: corrected an error that was introduced into1st and 2nd programs that was overlooked 'til W.P. noticed it.) |
||
Line 1,965: | Line 1,965: | ||
/* [↓] examine each number in the list*/ |
/* [↓] examine each number in the list*/ |
||
do while z\==''; index=1 /*keep examining the list until done.*/ |
do while z\==''; index=1 /*keep examining the list until done.*/ |
||
big=isOK( word(z, 1) ) |
big=isOK( word(z, 1) ) /*assume that first integer is biggest.*/ |
||
/* [↓] check the rest of the integers.*/ |
/* [↓] check the rest of the integers.*/ |
||
do k=2 to words(z); #=isOK(word(z,k)) /*obtain an an integer from the list. */ |
do k=2 to words(z); #=isOK(word(z,k)) /*obtain an an integer from the list. */ |
||
L=max( |
L=max(length(big), length(#) ) /*get the maximum length of the integer*/ |
||
if left(#, L, left(#, 1) ) <<= left(big, L, left(big, 1) ) then iterate |
if left(#, L, left(#, 1) ) <<= left(big, L, left(big, 1) ) then iterate |
||
big=#; index=k /*we found a new biggie (and the index)*/ |
big=#; index=k /*we found a new biggie (and the index)*/ |
||
Line 2,008: | Line 2,008: | ||
do while z\==''; p=uPow(1) /*keep examining the list until done.*/ |
do while z\==''; p=uPow(1) /*keep examining the list until done.*/ |
||
if p\==0 then numeric digits p /*# has big exponent? Then adjust digs*/ |
if p\==0 then numeric digits p /*# has big exponent? Then adjust digs*/ |
||
big=isOK(y); index=1 |
big=isOK(y); index=1 /*assume that first integer is biggest.*/ |
||
/* [↓] check the rest of the integers.*/ |
/* [↓] check the rest of the integers.*/ |
||
do k=2 to words(z); p=uPow(k) /*obtain an a number from the list. */ |
do k=2 to words(z); p=uPow(k) /*obtain an a number from the list. */ |
||
if p\==0 then numeric digits p + Lm +3 /*# has big exponent? Then adjust digs*/ |
if p\==0 then numeric digits p + Lm +3 /*# has big exponent? Then adjust digs*/ |
||
#=isOK(y) /*obtain an an integer from the list. */ |
#=isOK(y) /*obtain an an integer from the list. */ |
||
L=max( |
L=max(length(big), length(#) ) /*get the maximum length of the integer*/ |
||
if left(#, L, left(#, 1) ) <<= left(big, L, left(big, 1) ) then iterate |
if left(#, L, left(#, 1) ) <<= left(big, L, left(big, 1) ) then iterate |
||
big=#; index=k /*we found a new biggie (and the index)*/ |
big=#; index=k /*we found a new biggie (and the index)*/ |
||
Line 2,037: | Line 2,037: | ||
{{out|output|text= when using the default (internal) integer lists:}} |
{{out|output|text= when using the default (internal) integer lists:}} |
||
<pre> |
<pre> |
||
998764543431 max for: {1, 34, 3, 98, 9, 76, 45, 4} |
|||
6054854654 max for: {54, 546, 548, 60} |
6054854654 max for: {54, 546, 548, 60} |
||
554454 max for: { 4, 45, 54, 5} |
554454 max for: { 4, 45, 54, 5} |
||
660000000000000000000000000000000000000000000000000000000000000000000000000000554454 max for: { 4, 45, 54, 5, 6.6e77} |
|||
</pre> |
</pre> |
||
===Alternate Version=== |
===Alternate Version=== |
||
Inspired by the previous versions. |
Inspired by the previous versions. |