예제 #1
0
from kit103_assign2 import q4_acme_letter_detector
from truthtable import TruthTable


def q4_original(a, b, c, d):
    return \
     (not a and not b and not c and d) or \
     (not a and not b and c and d) or \
     (not a and b and not c and not d) or \
     (not a and b and c and d) or \
     (a and not b and c and d) or \
     (a and b and c and d)


original = TruthTable(4, q4_original)
answer = TruthTable(4, q4_acme_letter_detector)

original.print(answer, labels=('original', 'optimised'))

if original == answer:
    print('Success! The answer matches the original predicate.')
else:
    print('Whoops! The answer does not match the original predicate.')
예제 #2
0
import kit103_assign2 as assign2
from truthtable import TruthTable

questions = {'a': 2, 'b': 4, 'c': 3, 'd': 1}

for q, var_count in questions.items():
    print()

    predicate1 = getattr(assign2, 'q2_' + q)
    predicate2 = getattr(assign2, 'q3_' + q)

    result1 = TruthTable(var_count, predicate1)
    result2 = TruthTable(var_count, predicate2)

    result1.print(result2, labels=('2.' + q, '3.' + q))

    out1, out2 = ('Pass', 'identical') if result1 == result2 else ('Fail',
                                                                   'different')
    print(
        f'{out1}ed: Question {q.upper()} has {out2} results for the two predicates.'
    )
    print()