Last list item: Difference between revisions

Content added Content deleted
Line 490: Line 490:


=={{header|Ring}}==
=={{header|Ring}}==
===Without sorting===
===With sorting===
<lang ring>
<lang>
see "working..." + nl
see "working..." + nl


Line 499: Line 499:
while true
while true
n++
n++
first = min(List)
List = sort(List)
first = List[1]
second = List[2]
ind1 = find(List,first)
ind1 = find(List,first)
del(List,ind1)
second = min(List)
ind2 = find(List,second)
ind2 = find(List,second)
del(List,ind2)
if ind1 < ind2
del(List,ind2)
del(List,ind1)
else
del(List,ind1)
del(List,ind2)
ok
sum = first + second
sum = first + second
add(List,sum)
add(List,sum)
Line 536: Line 542:
see txt + nl
see txt + nl
</lang>
</lang>
===With sorting===
===Without sorting===
<lang>
<lang ring>
see "working..." + nl
see "working..." + nl


Line 545: Line 551:
while true
while true
n++
n++
List = sort(List)
first = min(List)
first = List[1]
second = List[2]
ind1 = find(List,first)
ind1 = find(List,first)
del(List,ind1)
second = min(List)
ind2 = find(List,second)
ind2 = find(List,second)
if ind1 < ind2
del(List,ind2)
del(List,ind2)
del(List,ind1)
else
del(List,ind1)
del(List,ind2)
ok
sum = first + second
sum = first + second
add(List,sum)
add(List,sum)