Largest int from concatenated ints: Difference between revisions

Added PicoLisp
(Added Java 8 example)
(Added PicoLisp)
Line 628:
echo maxnum(array(54, 546, 548, 60)), "\n";</lang>
{{out}}
<pre>998764543431
6054854654</pre>
 
=={{header|PicoLisp}}==
Here are solutions for all three algorithms.
 
The third solution actually avoids padding the numbers, by converting them into
circular lists and comparing these. As a drawback, however, this works only for
unique lists (as the comparison of identical numbers would not terminate), so a
better solution might involve additional checks.
<lang PicoLisp>(load "@lib/simul.l") # For 'permute'</lang>
===Algorithm 1===
<lang PicoLisp>(for L '((1 34 3 98 9 76 45 4) (54 546 548 60))
(prinl (maxi format (permute L))) )</lang>
===Algorithm 2===
<lang PicoLisp>(for L '((1 34 3 98 9 76 45 4) (54 546 548 60))
(prinl
(sort L
'((A B)
(>
(format (pack A B))
(format (pack B A)) ) ) ) ) )</lang>
===Algorithm 3===
<lang PicoLisp>(for L '((1 34 3 98 9 76 45 4) (54 546 548 60))
(prinl
(flip
(by '((N) (apply circ (chop N))) sort L) ) ) )</lang>
Output in all three cases:
<pre>998764543431
6054854654</pre>
Anonymous user