Largest int from concatenated ints: Difference between revisions

m
Added Easylang
m (Added Easylang)
 
(4 intermediate revisions by 4 users not shown)
Line 529:
=={{header|Delphi}}==
See [https://www.rosettacode.org/wiki/Largest_int_from_concatenated_ints#Pascal Pascal].
 
=={{header|EasyLang}}==
<syntaxhighlight>
func con a b .
t = 10
while b >= t
t *= 10
.
return a * t + b
.
func$ max a[] .
n = len a[]
for i to n - 1
for j = i + 1 to n
if con a[i] a[j] < con a[j] a[i]
swap a[i] a[j]
.
.
.
for v in a[]
r$ &= v
.
return r$
.
print max [ 1 34 3 98 9 76 45 4 ]
print max [ 54 546 548 60 ]
</syntaxhighlight>
{{out}}
<pre>
998764543431
6054854654
</pre>
 
=={{header|Elixir}}==
Line 1,243 ⟶ 1,275:
<pre>998764543431
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}}==
Line 2,436 ⟶ 2,496:
998764543431
6054854654
</pre>
 
=={{header|RPL}}==
We use here the second algorithm, easily derived from the SORT program given in [[Sorting algorithms/Bubble sort#RPL|Sorting algorithms/Bubble sort]].
{{works with|HP|28}}
≪ LIST→ → len
≪ 1 len '''START'''
→STR len ROLL '''END'''
len 1 '''FOR''' n
1 n 1 - '''START'''
'''IF''' DUP2 + LAST SWAP + < '''THEN''' SWAP '''END'''
n ROLLD
'''NEXT''' n ROLLD
-1 '''STEP'''
2 len '''START''' + '''END''' STR→
≫ ≫ ‘<span style="color:blue">MKBIG</span>’ STO
 
{212 21221} <span style="color:blue">MKBIG</span>
{1 34 3 98 9 76 45 4} <span style="color:blue">MKBIG</span>
{54 546 548 60} <span style="color:blue">MKBIG</span>
{{out}}
<pre>
3: 21221221
2: 998764543431
1: 6054854654
</pre>
 
Line 2,679 ⟶ 2,764:
[1 34 3 98 9 76 45 4] => [9 98 76 45 4 34 3 1] (concatenated: 998764543431)
[54 546 548 60] => [60 548 546 54] (concatenated: 6054854654)
</pre>
 
=={{header|Transd}}==
<syntaxhighlight lang="Scheme">#lang transd
 
MainModule: {
_start: (lambda
(for ar in [[98, 76, 45, 34, 9, 4, 3, 1], [54, 546, 548, 60]] do
(sort ar (λ l Int() r Int() (ret (> Int(String(l r)) Int(String(r l))))))
(lout (join ar "")))
)
}</syntaxhighlight>
{{out}}
<pre>
998764543431
6054854654
</pre>
 
Line 2,733 ⟶ 2,834:
{{trans|Kotlin}}
{{libheader|Wren-sort}}
<syntaxhighlight lang="ecmascriptwren">import "./sort" for Sort
 
var cmp = Fn.new { |x, y|
1,995

edits