The objective of this task is to find the set X that fulfill all of the following requirements:
X = {x | x ∈ Z and x > 0}.
A = {(x mod 2) | x ∈ X}
B = {y |sqrt(y) ∈ X}
C = {sqrt(z) | z ∈ (X ∩ B)}
D = {w^2| w ∈ C}
0 < |X|.
|X| ∈ X.
|A| (not element in) X.
sum(X) ∈ B.
sum(X ∩ B) 6 (not element in) B.
sum(C ∪ D) ∈ X.
So this is the problem I'm trying to solve.
I've tried solving this by hand and found that X = {6, 36, 31, 33, 11, 4} is a set that fits the requirements. I've written a code in Python as well but my code isn't working. I'm not getting any error messages, it just won't output a set that fulfill the requirements. This is the code I've written in Python:
import random
import math
def check(t):
X1 = t
X = set([x for x in X1 if x>0])
A = set([x%2 for x in X]) - set([0])
print "A= ", "\t", A
B = set([math.pow(y,2) for y in X ])
print "B= ", "\t", B
C = set([math.pow(z, 0.5) for z in X.intersection(B)])
print "C= ", "\t", C
D = set([math.pow(w, 2) for w in C])
print "D= ", "\t", D, "\n"
# (iii)
if len(X) >0:
print "iii.\t The cardinality of X bigger than 0."
# (iv)
if len(X) in X:
print "iv.\t\t The cardinality of X is element in X"
# (v)
if len(A) not in X:
print "v.\t\t Cardinality of A is not element in X."
# (vi)
if sum(X) in B:
print "vi.\t\t Sum of X is element in B."
# (vii)
if sum(X) and sum(B) not in X:
print "vii.\t Sum of X and B is not element in B"
# (viii)
if sum(C) in X or sum(D) in X:
print "viii.\t Sum of C exits in X."
if len(X)>0 and len(X) in X and len(A) not in X and sum(X) in B and sum(X) not in B and sum(B) not in B and sum(C) in X or sum(D) in X:
print "Set X is ","\t\t ", X
print "Fits the requirements."
# print "A = ", A
else:
print "Does not fit the requirements."
def guess():
b = 20
genSet = random.sample( range(2,b), 6 )
t = set(genSet)
print "---------------"
print "Generated set is: ", t
return check(t)
counter=1
while not guess():
print "try nr: ", teller
counter+=1
As you may notice I've just assumed the set to be of length=6, but that's just for now as I'm trying to get the code to work. And my range of random number isn't that big either for the same reason.
I've also written some if/else-statements in between to check whether the requirements are fulfillled or not.
Ignore my comments: don't know what I was thinking. Simply set
and make sure you
return
something from your functioncheck
:And you need to get the logic right in your comparison (the long
if
statement):With these edits, one solution appears to be
{1, 3, 4, 6, 9, 13}
.