Last list item: Difference between revisions

add FreeBASIC
(Added AutoHotkey)
(add FreeBASIC)
Line 348:
Two smallest: 243 + 378 = 621
Last item is 621.
</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>#define HUGE 99999999
 
redim as integer list(0 to 8)
list(0) = 6 :list(1) = 81:list(2) = 243:list(3) = 14:list(4) = 25:list(5) = 49:list(6) = 123:list(7) = 69:list(8) = 11
dim as integer s, si, ss, ssi, i
 
for i = 0 to ubound(list)
print list(i);" ";
next i
print
while ubound(list) > 0
s = HUGE
ss = HUGE
for i = 0 to ubound(list)
if list(i)<s then
ss = s
ssi = si
s = list(i)
si = i
elseif list(i)<ss then
ss = list(i)
ssi = i
end if
next i
if ss<s then swap s, ss
for i = si to ubound(list)-1
list(i) = list(i+1)
next i
for i = ssi to ubound(list)-2
list(i) = list(i+1)
next i
list(ubound(list)-1) = s+ss
redim preserve list(0 to ubound(list)-1)
for i = 0 to ubound(list)
print list(i);" ";
next i
print
wend</lang>
{{out}}<pre>
6 81 243 14 25 49 123 69 11
81 243 14 25 49 123 69 17
81 243 25 49 123 69 31
81 243 49 123 69 56
81 243 123 69 105
243 123 105 150
243 150 228
243 378
621
</pre>
 
Line 448 ⟶ 499:
Last item is 621.
</pre>
 
 
=={{header|Julia}}==
781

edits