Fastest approach to returning a vector of elements choose 2

a slightly different wording used in the same post @Dan is probably referring to

v=1:10
n=size(v)[1]
function n_over_2(v,idx)
    j = Int(ceil(sqrt(2 * idx + 0.25) - 0.5))+1
    i = Int(idx - (j-2) * (j-1) / 2)
    (v[i],v[j])
end

n_over_2.([v],1:n*(n-1)/2)

but perhaps it is less suitable for this case

1 Like