Last active
November 29, 2021 07:50
-
-
Save trevorhobenshield/5976fddd6a21183316ae8f479c7df2cb to your computer and use it in GitHub Desktop.
solve set theory problem given list of conditions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Combinatorics | |
using IterTools | |
function calculate(U, sets) | |
solution_set = Set() | |
Threads.@threads for s in sets | |
A,B,C =Set(s[1]),Set(s[2]),Set(s[3]) | |
conditions = [ | |
(A ∩ setdiff(U,B) ∩ setdiff(U,C)) == (setdiff(U,A) ∩ B ∩ C) | |
Set(1) ⊆ ((A ∪ C) ∩ setdiff(B, C)) | |
symdiff(setdiff(U,A),B) ⊆ (B ∪ C) | |
length(setdiff(B ∪ C,symdiff(setdiff(U,A),B))) == 3 | |
symdiff(setdiff(U, A ∪ B),setdiff(U,A ∪ C)) == Set([2,3]) | |
] | |
if all(conditions) | |
push!(solution_set,Set([A,B,C])) | |
end | |
end | |
solution_set | |
end | |
NUM_SETS = 3 | |
U = Set(1:6) | |
pset = collect(powerset(collect(U)))[:2:end] # ignore empty set | |
sets = collect(chain([permutations(x) for x in subsets(pset, NUM_SETS)]...)) | |
calculate(U,sets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment