Last list item: Difference between revisions
→{{header|ALGOL 68}}: Updated to revised task requirements
Walterpachl (talk | contribs) m (add REXX) |
(→{{header|ALGOL 68}}: Updated to revised task requirements) |
||
Line 10:
=={{header|ALGOL 68}}==
Was a translation of the sorted Wren version but the sorting has been removed as per the revised task requirements.
<lang algol68>BEGIN # find the last element after repeatedely adding the sum #
# of the two smallest elements and removing them #
IF ub > lb THEN▼
INT left := lb;▼
WHILE▼
left <= right▼
DO▼
INT t := a[ left ];▼
a[ left ] := a[ right ];▼
[ 1 : 9 ]INT a := ( 6, 81, 243, 14, 25, 49, 123, 69, 11 );
INT a count := UPB a;
WHILE a count > 1 DO
print( ( "Sorted list:" ) );FOR i TO a count DO print( ( " ", whole( a[ i ], 0 ) ) ) OD;▼
, " + ", whole( a[ 2 ], 0 )▼
FOR i FROM 3 TO a count
IF a[ i ] < a[ s1pos ] THEN s2pos := s1pos; s1pos := i
▲ print( ( "
, newline
)
);
a[
a count -:= 1
OD;
Line 57 ⟶ 42:
{{out}}
<pre>
List: 81 243 31 25 49 123 69; two smallest: 25 @ 4 and 31 @ 3; sum = 56
List: 81 243 105 123 69; two smallest: 69 @ 5 and 81 @ 1; sum = 150
List: 243 228 150; two smallest: 150 @ 3 and 228 @ 2; sum = 378
Last item is 621.
</pre>
|