Jump to content

Largest int from concatenated ints: Difference between revisions

m
→‎{{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)., and does some basic error checking to verify that the numbers are integers (and normalizes the integers).
 
This REXX version doesn't do any error checking/verifying that:
::*   the numbers are in fact, numbers
::*   the lists are well formed
::*   the list isn't null
<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. */
zL_=length(space(z,0)) + 1 /*determine the largest possible#*/
if zL_>digits() then numeric digits zL _ /*ensure 'nuff digits for the #. */
/* [↓] examine each num in list.*/
do while z\==''; index=1 /*keep examining list until done.*/
big=absisOK(word(z,1))/1 /*assume first number is biggest.*/
 
do k=2 to words(z); x=absisOK(word(z,k))/1 /*get anotheran intinteger.*/
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*/
 
exit /*stick a fork in it, we're done.*/</lang>
/*───────────────────────────────────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>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.