# cs235
# Yuxiao Wang
# hw2
# question 3
def quotient(X,R):
return {frozenset({y for y in X if (x,y) in R}) for x in X}
def flight(X,R):
return len(quotient(X,R))
# Test!
C = {'Iceland', 'USA', 'Canada', 'Mexico', 'Australia', 'Norway', 'Sweden', 'Finland'}
D = {('USA', 'Canada'), ('USA', 'Mexico'), ('Norway', 'Sweden'), ('Sweden', 'Finland')}
S1={(x, x) for x in C}
D=D.union(S1)
# reflective
S1={(x, x) for x in C}
#symmetricity:
S2={(y, x) for (x,y) in D}
#and transitivity:
S3={(x, z) for x in C for z in C for y in C if ((x,y) in D and (y,z) in D)}
# equ
D=D.union(S1).union(S2).union(S3)
print("Equivenlence D now is: \n",D,"\n")
print("You can visit all the countries in each of these set in one car ride: \n"
,quotient(C,D),"\n")
print("Minimum number of flights you need to visit all the countries is:\n"
,flight(C,D),"\n")