function finding_minimum_sum(list_of_distance, list_of_projected_load, show_list = true)
x = list_of_distance
y = list_of_projected_load
l1 = length(x)
l2 = length(y)
xy = []
for i in 1:l2
xy1a = []
xy2a = []
for j in 1:l1
if (i ≤ j) && (i != l2)
push!(xy1a, sum(x[i:j])*y[j+1])
end
if (i != 1 && i > j)
push!(xy2a, sum(x[j:(i-1)])*y[j])
end
end
if !isempty(xy1a) && !isempty(xy2a)
an = collect(Iterators.flatten([xy2a, xy1a]))
push!(xy, sum(insert!(an, i, y[i])))
else
if i == 1
push!(xy, sum(collect(Iterators.flatten([y[1], xy1a]))))
else
push!(xy, sum(collect(Iterators.flatten([xy2a, y[l2]]))))
end
end
end
min_sum = extrema(xy)[1]
ls = findall(x->x==min_sum, xy)
if show_list
return xy, ls
else
return ls
end
end
given with the following:
lst1 = [2, 4]
lst2 = [1, 2, 3]
finding_minimum_sum(lst1, lst2)
if the above code run in Julia 1.9.2 the output will be:
([23, 16, 17], [2]
while running the code in Julia 1.9.3 the output will be:
([23], [1])
Yeah, I couldn’t spot any difference from the screenshots. Just to double check (I’m not trying to be annoying ), can you also show the values of list_of_distance and list_of_projected_load in both notebooks, right before you call the function?
Here’s some other things that might cause the issue, if both the function code and the input variables are exactly identical:
There might be other code that, e.g., redefines some functions or sets some global variables which interfere with the code. It’s impossible to know that without seeing the both notebooks.
If the code is running on different machines there might be something different in both startup.jl files.
… black magic?
If you start a new REPL and just paste this code in it, do you still get different results? (that’s what I tried)
function finding_minimum_sum(list_of_distance, list_of_projected_load, show_list = true)
x = list_of_distance
y = list_of_projected_load
l1 = length(x)
l2 = length(y)
xy = []
for i in 1:l2
xy1a = []
xy2a = []
for j in 1:l1
if (i ≤ j) && (i != l2)
push!(xy1a, sum(x[i:j])*y[j+1])
end
if (i != 1 && i > j)
push!(xy2a, sum(x[j:(i-1)])*y[j])
end
end
if !isempty(xy1a) && !isempty(xy2a)
an = collect(Iterators.flatten([xy2a, xy1a]))
push!(xy, sum(insert!(an, i, y[i])))
else
if i == 1
push!(xy, sum(collect(Iterators.flatten([y[1], xy1a]))))
else
push!(xy, sum(collect(Iterators.flatten([xy2a, y[l2]]))))
end
end
end
min_sum = extrema(xy)[1]
ls = findall(x->x==min_sum, xy)
if show_list
return xy, ls
else
return ls
end
end
lst1 = [2, 4]
lst2 = [1, 2, 3]
finding_minimum_sum(lst1, lst2)
Also your code is just a series of fairly basic functions shipped with the base Julia install, so it’s exceedingly unlikely that there’s such a change in the output returned between Julia patch versions (indeed this would likely be a serious bug in the language).
Thank you again…
Here I take a screen shot of the code with variables, and also I did delete all the variables and function other than the code you see in the pictures.
I suspected that in portable of Julia 1.9.3 might got the problem, I remember that when add packages it always not finished( It hangs - I don’t know what exact terms), so what i did is to close the Julia REPL when it happens, then I will open it again then add package then it hangs again… many times i did that… but when I check the status it shows that the package is installed. so i continue adding packages even though it always hangs.
I used portable julia(not julia installer) because our company restricted in installation of software…
Also to narrow down the possible sources of the issue it would be good to forget about Pluto and even opening REPLs for a moment. Can you just create a file test.jl your find_maximum_sum function in and then at the bottom add
println(find_maximum_sum([2,4], [1,2,3]))
Then call Julia from the terminal without startup file and run this file, which will now print the result to the terminal:
I would add a few @show into the code and look where the two executions start to diverge and then try to pin down what the problem might be. Since the code is short and test data is small, that should be quite simple to do.
Your code in your Julia 1.9.3 is different than your Julia 1.9.2 notebook.
The code you pasted above and are using for Julia 1.9.2 is as follows.
function finding_minimum_sum(list_of_distance, list_of_projected_load, show_list = true)
# ...
for i in 1:l2
# ...
end
if show_list
return xy, ls
else
return ls
end
end
The code you have in your Julia 1.9.3 notebook is as follows with the if statement inside the for loop.
function finding_minimum_sum(list_of_distance, list_of_projected_load, show_list = true)
# ...
for i in 1:l2
# ...
if show_list
return xy, ls
else
return ls
end
end
end