Largest int from concatenated ints: Difference between revisions
Content added Content deleted
(add RPL) |
imported>Maxima enthusiast No edit summary |
||
Line 1,243: | Line 1,243: | ||
<pre>998764543431 |
<pre>998764543431 |
||
6054854654</pre> |
6054854654</pre> |
||
=={{header|Maxima}}== |
|||
<syntaxhighlight lang="maxima"> |
|||
/* Function that decompose a number into a list of its digits using conversions between numbers and strings */ |
|||
decompose_n_s(n):=block( |
|||
string(n), |
|||
charlist(%%), |
|||
map(eval_string,%%))$ |
|||
/* Function that orders the list obtained by decompose_n_ according to ordergreat and then orders the result to reached what is needed to solve the problem */ |
|||
largest_from_list(lst):=( |
|||
sort(map(decompose_n_s,lst),ordergreatp), |
|||
sort(%%,lambda([a,b],if last(a)>last(b) then rest(b,-1)=a else rest(a,-1)=b)), |
|||
map(string,flatten(%%)), |
|||
simplode(%%), |
|||
eval_string(%%)); |
|||
/* Test cases */ |
|||
test1: [1, 34, 3, 98, 9, 76, 45, 4]$ |
|||
test2: [54, 546, 548, 60]$ |
|||
largest_from_list(test1); |
|||
largest_from_list(test2); |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
998764543431 |
|||
6054854654 |
|||
</pre> |
|||
=={{header|min}}== |
=={{header|min}}== |