Minimales en Julia
This commit is contained in:
27
src/Julia/004.jl
Normal file
27
src/Julia/004.jl
Normal file
@@ -0,0 +1,27 @@
|
||||
function minimales(lst)
|
||||
res = Vector{Vector{Int}}()
|
||||
for (index, canditate) in enumerate(lst)
|
||||
canditate_set = Set(canditate)
|
||||
|
||||
is_subset_of_another = any(
|
||||
index != other_index && canditate_set <= Set(other)
|
||||
for (other_index, other) in enumerate(lst)
|
||||
)
|
||||
|
||||
if is_subset_of_another
|
||||
continue
|
||||
end
|
||||
|
||||
if !any(canditate_set == Set(existing) for existing in res)
|
||||
push!(res, canditate)
|
||||
end
|
||||
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
check = [[1, 3], [2, 3, 1], [3, 2, 5]]
|
||||
println(minimales(check)) # [[2, 3, 1], [3, 2, 5]]
|
||||
|
||||
check = [[1, 3], [2, 3, 1], [3, 2, 5], [3, 1]]
|
||||
println(minimales(check)) # [[2, 3, 1], [3, 2, 5]]
|
||||
Reference in New Issue
Block a user