Largest int from concatenated ints: Difference between revisions

m (→‎{{header|REXX}}: remove the prototype text from the OUTPUT statement. -- ~~~~)
Line 107:
 
<pre>[998764543431,6054854654]</pre>
 
Since repeating numerical string "1234" is the same as taking all the digits of 1234/9999 after the decimal point, the following does essentially the same as above:
<lang haskell>import Data.List (sortBy)
 
nines = 9:map ((+9).(*10)) nines
 
maxcat = foldl (\a (n,d)->a * (1 + d) + n) 0 .
sortBy (\(n1,d1) (n2,d2)->compare (n2*d1) (n1*d2)) .
map (\a->(a, head $ dropWhile (<a) nines))
 
main = mapM_ (print.maxcat) [[1,34,3,98,9,76,45,4], [54,546,548,60]]</lang>
 
===Sort on comparison of concatenated ints method===
Anonymous user