Largest int from concatenated ints: Difference between revisions
Content added Content deleted
(→Haskell: Add implementation) |
|||
Line 192: | Line 192: | ||
[1, 34, 3, 98, 9, 76, 45, 4] |
[1, 34, 3, 98, 9, 76, 45, 4] |
||
998764543431</pre> |
998764543431</pre> |
||
=={{header|Run BASIC}}== |
|||
<lang runbasic>a1$ = "1, 34, 3, 98, 9, 76, 45, 4" |
|||
a2$ = "54,546,548,60" |
|||
print "Max Num ";a1$;" = ";maxNum$(a1$) |
|||
print "Max Num ";a2$;" = ";maxNum$(a2$) |
|||
function maxNum$(a1$) |
|||
while word$(a1$,i+1,",") <> "" |
|||
i = i + 1 |
|||
a$(i) = trim$(word$(a1$,i,",")) |
|||
wend |
|||
s = 1 |
|||
while s = 1 |
|||
s = 0 |
|||
for j = 1 to i -1 |
|||
if a$(j)+a$(j+1) < a$(j+1)+a$(j) then |
|||
h$ = a$(j) |
|||
a$(j) = a$(j+1) |
|||
a$(j+1) = h$ |
|||
s = 1 |
|||
end if |
|||
next j |
|||
wend |
|||
for j = 1 to i |
|||
maxNum$ = maxNum$ ; a$(j) |
|||
next j |
|||
end function</lang>Output<pre>Max Num 1, 34, 3, 98, 9, 76, 45, 4 = 998764543431 |
|||
Max Num 54,546,548,60 = 6054854654</pre> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |