June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -1,14 +1,17 @@
const A = [-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1]
maxval = 0
maxseq = Int[]
for head=1:length(A), tail=head:length(A)
val = sum(A[head:tail])
if val > maxval
maxval = val
maxseq = A[head:tail]
function gss(arr::Vector{<:Number})
smax = hmax = tmax = 0
for head in eachindex(arr), tail in head:length(arr)
s = sum(arr[head:tail])
if s > smax
smax = s
hmax, tmax = head, tail
end
end
return arr[hmax:tmax]
end
println(maxseq)
println(maxval)
arr = [-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1]
subseq = gss(arr)
s = sum(subseq)
println("Greatest subsequential sum of $arr:\n → $subseq with sum $s")