Anonymous user
Largest int from concatenated ints: Difference between revisions
Largest int from concatenated ints (view source)
Revision as of 01:26, 24 December 2014
, 9 years ago→{{header|REXX}}: eliminated verbage about what isn't checked (as the REXX program now checks for the numbers being integers).
m (→{{header|REXX}}: alligned output with minimalist leading blanks.) |
m (→{{header|REXX}}: eliminated verbage about what isn't checked (as the REXX program now checks for the numbers being integers).) |
||
Line 1,271:
The algorithm used is based on exact comparisons (left to right) with right digit fill of the left digit. This allows the integers to be of any size.
This REXX version works with any integer (negative, zero, positive)
<lang rexx>/*REXX pgm constructs largest integer from a list using concatenation.*/
@. = /*used to signify end-of-lists. */
Line 1,285 ⟶ 1,280:
do j=1 while @.j\==''; $= /*keep truckin' until exhausted. */
z=space(translate(@.j, , '])},{([')) /*perform scrubbing on the list. */
if
/* [↓] examine each num in list.*/
do while z\==''; index=1 /*keep examining list until done.*/
big=
do k=2 to words(z);
x1=left(x,1); L=max(length(big), length(x)) /*get max length.
if left(x, L, x1) <<= left(big, L, left(big,1)) then iterate
big=x; index=k /*we found a new biggie (& index)*/
Line 1,303 ⟶ 1,298:
say right($,digits()) ' max for: ' @.j /*show max integer & list.*/
end /*j*/ /* [↑] process each list of nums*/
/*───────────────────────────────────ISOK subroutine────────────────────*/
isOK: parse arg ?; if datatype(?,'W') then return abs(?)/1 /*normalize*/
say; say '***error!*** number ' ? "isn't an integer."; say; exit 13</lang>
{{out}}
<pre>
|