Compare commits

..

4 Commits

Author SHA1 Message Date
0a5969b2e0 Minimales en Go 2026-05-17 17:10:31 +02:00
c1a5ce4494 Minimales en Rust 2026-05-17 17:10:17 +02:00
55705a796a Minimales en Julia 2026-05-17 17:10:02 +02:00
aa176f7038 Minimales en Python 2026-05-17 17:09:45 +02:00
4 changed files with 176 additions and 0 deletions

70
src/Go/004.go Normal file
View File

@@ -0,0 +1,70 @@
package main
import "fmt"
func toSet(values []int) map[int]struct{} {
set := make(map[int]struct{}, len(values))
for _, value := range values {
set[value] = struct{}{}
}
return set
}
func isSubset(left map[int]struct{}, right map[int]struct{}) bool {
for value := range left {
if _, ok := right[value]; !ok {
return false
}
}
return true
}
func minimales(values [][]int) [][]int {
res := [][]int{}
for index, candidate := range values {
candidateSet := toSet(candidate)
isSubsetOfAnother := false
for otherIndex, other := range values {
if index == otherIndex {
continue
}
otherSet := toSet(other)
if isSubset(candidateSet, otherSet) {
isSubsetOfAnother = true
break
}
}
if isSubsetOfAnother {
continue
}
alreadyPresent := false
for _, existing := range res {
existingSet := toSet(existing)
if len(candidateSet) == len(existingSet) &&
isSubset(candidateSet, existingSet) {
alreadyPresent = true
break
}
}
if !alreadyPresent {
res = append(res, candidate)
}
}
return res
}
func main() {
check := [][]int{[]int{1, 3}, []int{2, 3, 1}, []int{3, 2, 5}}
fmt.Println(minimales(check)) // [[2, 3, 1], [3, 2, 5]]
check = [][]int{[]int{1, 3}, []int{2, 3, 1}, []int{3, 2, 5}, []int{3, 1}}
fmt.Println(minimales(check)) // [[2, 3, 1], [3, 2, 5]]
}

27
src/Julia/004.jl Normal file
View 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]]

22
src/Python/004.py Normal file
View File

@@ -0,0 +1,22 @@
def minimales(lst: list[list[int]]) -> list[list[int]]:
res = []
for index, candidate in enumerate(lst):
candidate_set = set(candidate)
is_subset_of_another = any(
index != other_index and candidate_set <= set(other)
for other_index, other in enumerate(lst)
)
if is_subset_of_another:
continue
if not any(candidate_set == set(existing) for existing in res):
res.append(candidate)
return res
check = [[1, 3], [2, 3, 1], [3, 2, 5]]
print(minimales(check)) # [[2, 3, 1], [3, 2, 5]]
check = [[1, 3], [2, 3, 1], [3, 2, 5], [3, 1]]
print(minimales(check)) # [[2, 3, 1], [3, 2, 5]]

57
src/Rust/004.rs Normal file
View File

@@ -0,0 +1,57 @@
use std::collections::HashSet;
fn minimales(values: &[Vec<i32>]) -> Vec<Vec<i32>> {
let mut res: Vec<Vec<i32>> = Vec::new();
for (index, candidate) in values.iter().enumerate() {
let candidate_set: HashSet<i32> = candidate.iter().copied().collect();
// let mut is_subset_of_another = false;
// for (other_index, other) in values.iter().enumerate() {
// let result = if index == other_index {
// false
// } else {
// let other_set: HashSet<i32> = other.iter().copied().collect();
// candidate_set.is_subset(&other_set)
// };
// if result {
// is_subset_of_another = true;
// break;
// }
// }
let is_subset_of_another = values.iter().enumerate().any(|(other_index, other)| {
if index == other_index {
return false;
}
let other_set: HashSet<i32> = other.iter().copied().collect();
candidate_set.is_subset(&other_set)
});
if is_subset_of_another {
continue;
}
let already_present = res.iter().any(|existing| {
let existing_set: HashSet<i32> = existing.iter().copied().collect();
candidate_set == existing_set
});
if !already_present {
res.push(candidate.clone());
}
}
res
}
fn main() {
let check = vec![vec![1, 3], vec![2, 3, 1], vec![3, 2, 5]];
println!("{:?}", minimales(&check)); // [[2, 3, 1], [3, 2, 5]]
let check = vec![vec![1, 3], vec![2, 3, 1], vec![3, 2, 5], vec![3, 1]];
println!("{:?}", minimales(&check)); // [[2, 3, 1], [3, 2, 5]]
}