fork download
  1. def implication(a, b):
  2. return not a or b
  3.  
  4. # полная таблица истинности (как в вашем коде)
  5. table = []
  6. for x in (0, 1):
  7. for y in (0, 1):
  8. for z in (0, 1):
  9. for w in (0, 1):
  10. f1 = int(implication(w, y) == implication(z, x))
  11. f2 = int(implication(w, y) and (not x) == z)
  12. table.append({'x': x, 'y': y, 'z': z, 'w': w, 'f1': f1, 'f2': f2})
  13.  
  14. # фрагмент из задания ('?' - пусто)
  15. rows = [
  16. [0, '?', 0, 0, 0, 1],
  17. [0, 0, 0, '?', 0, '?'],
  18. [0, 1, 1, '?', '?', 0],
  19. ]
  20.  
  21. # перебираем, какая переменная в каком столбце
  22. for a in 'xyzw':
  23. for b in 'xyzw':
  24. for c in 'xyzw':
  25. for d in 'xyzw':
  26. if len({a, b, c, d}) < 4:
  27. continue
  28. cols = [a, b, c, d, 'f1', 'f2']
  29. ok = True
  30. for row in rows:
  31. found = False
  32. for t in table:
  33. match = True
  34. for i in range(6):
  35. if row[i] != '?' and row[i] != t[cols[i]]:
  36. match = False
  37. if match:
  38. found = True
  39. if not found:
  40. ok = False
  41. if ok:
  42. print(a + b + c + d)
Success #stdin #stdout 0.09s 14212KB
stdin
Standard input is empty
stdout
yzxw