Largest int from concatenated ints: Difference between revisions
Content deleted Content added
Walterpachl (talk | contribs) →{{header|REXX}}: added another version |
Walterpachl (talk | contribs) m →{{header|REXX}}: added Version 4 |
||
Line 2,106: | Line 2,106: | ||
4 45 54 5 6.6e77 -> 660000000000000000000000000000000000000000000000000000000000000000000000000000554454 |
4 45 54 5 6.6e77 -> 660000000000000000000000000000000000000000000000000000000000000000000000000000554454 |
||
3 3 .2 -> ** invalid ** bad integer .2</pre> |
3 3 .2 -> ** invalid ** bad integer .2</pre> |
||
===Version 4=== |
|||
{{trans|NetRexx}} |
|||
<lang rexx>/*REXX program constructs the largest integer from an integer list using concatenation.*/ |
|||
l.=''; l.1 = '1 34 3 98 9 76 45 4' /*the 1st integer list to be used. */ |
|||
l.2 = '54 546 548 60' /* " 2nd " " " " " */ |
|||
l.3 = ' 4 45 54 5' /* " 3rd " " " " " */ |
|||
l.4 = ' 4 45 54 5 6.6e77' /* " 4th " " " " " */ |
|||
l.5 = ' 3 3 .2' /* " 5th " " " " " */ |
|||
l.6 = ' 4 45 54 5 6.6e1001' /* " 4th " " " " " */ |
|||
l_length=0 |
|||
Do li=1 By 1 While l.li<>'' |
|||
l_length=max(l_length,length(space(l.li))) |
|||
End |
|||
Do li=1 By 1 While l.li<>'' |
|||
z='' |
|||
Do j=1 To words(l.li) |
|||
int=integer(word(l.li,j)) |
|||
If int='?' Then Do |
|||
Say left(space(l.li),l_length) '-> ** invalid ** bad integer' word(l.li,j) |
|||
Iterate li |
|||
End |
|||
Else |
|||
z=z int |
|||
End |
|||
/*Say copies(' ',l_length) ' ' soll.li */ |
|||
Say left(space(l.li),l_length) '->' largeint(z) |
|||
End |
|||
Exit |
|||
integer: Procedure |
|||
Numeric Digits 1000 |
|||
Parse Arg z |
|||
If Datatype(z,'W') Then |
|||
Return z+0 |
|||
Else |
|||
Return '?' |
|||
largeint: Procedure |
|||
Parse Arg list |
|||
w.0=words(list) |
|||
Do i=1 To w.0 |
|||
w.i=word(list,i) |
|||
End |
|||
Do wx=1 To w.0-1 |
|||
Do wy=wx+1 To w.0 |
|||
xx=w.wx |
|||
yy=w.wy |
|||
xy=xx||yy |
|||
yx=yy||xx |
|||
if xy < yx then do |
|||
/* swap xx and yy */ |
|||
w.wx = yy |
|||
w.wy = xx |
|||
end |
|||
End |
|||
End |
|||
list='' |
|||
Do ww=1 To w.0 |
|||
list=list w.ww |
|||
End |
|||
Return space(list,0)</lang> |
|||
{{out}} |
|||
<pre>1 34 3 98 9 76 45 4 -> 998764543431 |
|||
54 546 548 60 -> 6054854654 |
|||
4 45 54 5 -> 554454 |
|||
4 45 54 5 6.6e77 -> 660000000000000000000000000000000000000000000000000000000000000000000000000000554454 |
|||
3 3 .2 -> ** invalid ** bad integer .2 |
|||
4 45 54 5 6.6e1001 -> ** invalid ** bad integer 6.6e1001</pre> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |