using Printf
function choose_best_sum(t, k, ls)
ran = range(1, length(ls), step = 1)
choices = unique!([sort([ls[i], ls[j], ls[m]]) for i in ran for j in ran for m in ran if( i != j && j != m && m != i)])
println(choices[1])
distances = sort([sum(i) for i in choices if ( sum(i) <= t)])
return distances[end]
end
# ls:
towns = [50, 55, 57, 56, 58, 60]
# t:
max_dist = 174
# k - number of towns
num = 3
println(choose_best_sum(max_dist, num, towns))

it prints out the value of choices[1] and distances[end]. However when I delete the println(choices[1]) line nothing gets printed out. Does anyone know why? I am pretty new to Julia, so sorry in advance if that’s something I should know

using Printf
function choose_best_sum(t, k, ls)
ran = range(1, length(ls), step = 1)
choices = unique!([sort([ls[i], ls[j], ls[m]]) for i in ran for j in ran for m in ran if( i != j != m != i)])
distances = sort([sum(i) for i in choices if ( sum(i) <= t)])
return distances[end]
end
# ls:
towns = [50, 55, 57, 56, 58, 60]
# t:
max_dist = 174
# k - number of towns
num = 3
println(choose_best_sum(max_dist, num, towns))

Hey, I’m sorry I think I’m slightly mentally challenged . While running the script still doesn’t work the way I would like it to running the function in the REPL itself seems to resolve that issue. Thanks everyone for your help and useful suggestions!