Last list item: Difference between revisions

Content added Content deleted
m (→‎{{header|Julia}}: bang function)
m (→‎{{header|Julia}}: show interim values)
Line 316: Line 316:
while length(lis) > 1
while length(lis) > 1
push!(lis, popat!(lis, last(findmin(lis))) + popat!(lis, last(findmin(lis))))
push!(lis, popat!(lis, last(findmin(lis))) + popat!(lis, last(findmin(lis))))
println("Interim list: $lis")
end
end
return lis
return lis
end
end


@show list, addleastreduce!(copy(list)) # (list, addleastreduce!(copy(list))) = ([6, 81, 243, 14, 25, 49, 123, 69, 11], [621])
@show list, addleastreduce!(copy(list))
</lang>
</lang>{{out}}
<pre>
Interim list: [81, 243, 14, 25, 49, 123, 69, 17]
Interim list: [81, 243, 25, 49, 123, 69, 31]
Interim list: [81, 243, 49, 123, 69, 56]
Interim list: [81, 243, 123, 69, 105]
Interim list: [243, 123, 105, 150]
Interim list: [243, 150, 228]
Interim list: [243, 378]
Interim list: [621]
(list, addleastreduce!(copy(list))) = ([6, 81, 243, 14, 25, 49, 123, 69, 11], [621])
</pre>


=={{header|Perl}}==
=={{header|Perl}}==