Largest int from concatenated ints: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: fixed typo.)
(→‎{{header|Go}}: Add Fortran.)
Line 409:
Largest 6054854654 from [54,546,548,60]
</pre>
 
=={{header|Fortran}}==
There is often a potential ambiguity when reading numbers. While three definitely names the Platonic number notion, 3 might instead be regarded as being a text that happens to have the glyph of a number but is not a number. This sort of discussion arises when a spreadsheet has read in a text file and behold! numbers are on the display and they look just like what is displayed when numbers are being shown, but, they are not numbers within the spreadsheet, they are parts of some text, and the notion that takes over is of a "blunt, heavy object", not alas close to hand.
 
So, the plan is to regard the numbers as being text sequences aligned to the left, containing only digit characters of course - except for the fact that CHARACTER variables often end up having trailing spaces. F2003 formalised a scheme whereby such variables can be "cut-to-fit" as execution proceeds but with earlier Fortrans the standard method is to pay attention to the number of characters in use. F90 introduced a function LEN_TRIM(text) to return the index of the last non-blank character in a text so the only problem now is to decide on how might the longest number be (and by representing numbers as text strings, there is no difficulty with INTEGER*2 or INTEGER*4 ''etc.'' limits), and what will be the maximum number of numbers. By devising a subroutine to do the work, these issues can be handled by the caller that is providing the data. The subroutine however intends to sort the collection of texts. This could be done by damaging its parameter which might be regarded as impolite or even unwanted so instead the sort is effected via an array XLAT and juggling its values. This has the advantage that the possibly large elements of the text array are not being moved about, but means that the subroutine must be able to have an XLAT array that is "large enough". F90 standardised the ability for a routine to declare such an array at run-time; previously, arrays within a subroutine (or indeed anywhere) had to have a size fixed at compilation time. In the past this might have been handled by the caller supplying such an array as an additional parameter.
 
The sort of the text array was to be by the notorious BubbleSort, taking advantage of the fact that each pass delivers the maximum value of the unsorted portion to its final position: the output could thereby be produced as the sort worked.
 
=={{header|Go}}==