Finished Lab 6

This commit is contained in:
RustyRaptor committed 2019-10-17 13:48:00 -06:00
1 parent 84741db0dc
commit 23bf4c7a41
1 file changed
+17 -17
+17 -17
View File
@@ -1,12 +1,11 @@
n = int(input("Please enter the value of n: "))
Y = list(range(1, n + 1))
Y = list(range(1, int(input("Please enter the value of n: ")) + 1))
def function_generator(target):
def function_generator(targ):
num = 0
for anum, a in enumerate(target):
for bnum, b in enumerate(target):
for cnum, c in enumerate(target):
for a in targ:
for b in targ:
for c in targ:
num += 1
yield (a, b, c, num)
@@ -22,42 +21,43 @@ def is_1to1(a, b, c):
return False
def is_onto(a, b, c, target):
def is_onto(a, b, c, targ):
output_set = {a, b, c}
target_set = set(target)
targ_set = set(targ)
if len(target) > 3:
if len(targ) > 3:
return False
if output_set == target_set:
if output_set == targ_set:
return True
else:
return False
def is_biject(a, b, c, target):
if is_onto(a, b, c, target) and is_1to1(a, b, c):
def is_biject(a, b, c, targ):
if is_onto(a, b, c, targ) and is_1to1(a, b, c):
return True
else:
return False
def get_truths(a, b, c, target):
return is_1to1(a, b, c), is_onto(a, b, c, target), is_biject(a, b, c, target)
def get_truths(a, b, c, targ):
return is_1to1(a, b, c), is_onto(a, b, c, targ), is_biject(a, b, c, targ)
def print_funcs(target):
def print_funcs(targ):
count_oto = 0
count_onto = 0
count_bi = 0
for i in function_generator(target):
for i in function_generator(targ):
a, b, c, num = i
oto, onto, bi = get_truths(a, b, c, target)
oto, onto, bi = get_truths(a, b, c, targ)
if oto:
count_oto += 1
if onto:
count_onto += 1
if bi:
count_bi += 1
print("=" * 10, "FUNCTION", num, "=" * 10)
print(
numstr(num, "a") + str(a),
numstr(num, "b") + str(b),