Last list item: Difference between revisions

From Rosetta Code
Content added Content deleted
No edit summary
No edit summary
Line 4: Line 4:
List = [6, 81, 243, 14, 25, 49, 123, 69, 11]
List = [6, 81, 243, 14, 25, 49, 123, 69, 11]
<br>Find two smallest items, summarize them, add to the end of list and delete them.
<br>Find two smallest items, summarize them, add to the end of list and delete them.
<br>Repeat it until list contains one element.
<br>Show the last item on this page.
<br>Show the last item on this page.
<br><br>
<br><br>

Revision as of 05:46, 23 October 2021

Last list item is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task

List = [6, 81, 243, 14, 25, 49, 123, 69, 11]
Find two smallest items, summarize them, add to the end of list and delete them.
Repeat it until list contains one element.
Show the last item on this page.

Ring

<lang ring> see "working..." + nl see "Last item is:" + nl

List = [6,81,243,14,25,49,123,69,11] Temp = []

while true

     Temp = sort(List)
     first = Temp[1]
     second = Temp[2]
     ind1 = find(List,first)
     ind2 = find(List,second)
     del(List,ind2)
     del(List,ind1)
     sum = first + second 
     add(List,sum)
     if len(List) = 1
        exit
     ok

end

see "" + List[1] + nl see "done..." + nl </lang>

Output:
working...
Last item is:
504
done...