Hi everybody, this is an algorithmic problem:
i have a set of pairs of elements, from the same group,the members of the group are integers, the first member of a pair is an element of the group, and the second one is a group of elements of the same mother group. distinct from the first member of the pair
group = 1:9 #this element contains all possible unique elements
pairs = ((1,[2,3,4]),
(2,[5,7,8]),
(5,[8]),
(6,[8])
I’m looking for a function to reorder and filter the first element of the group and the second members of the pairs, an example:
subgroup= [8,5,1,2]
pairs = ((1,[2,3,4]),
(2,[5,7,8]),
(5,[8]),
(6,[8])
julia>reorder!(pairs,subgroup)
pairs = ((5,[8])
(1,[2])
(2,[8,5]))
there is a function that can do that in julia? or the solution is a loop of loops? there is no need for optimizations, as the number of elements is low. there is a function that does something similar, but just for a vector:
group = 1:21
pairs= 1:3
subgroup = [3,1,5]
julia> intersect(subgroup,pairs)
2-element Array{Int64,1}:
3
1