-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
36 lines (34 loc) · 866 Bytes
/
Copy pathtest.py
File metadata and controls
36 lines (34 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 从result.out中读取化简后的表达式
with open('result.out', 'r', encoding='utf-8') as f:
exp = f.read().strip()
exp = exp.replace(' ','')
print(exp)
def unit(s: str, input: list[bool]):
i=0
res=1
for c in s:
if c=='-':
pass
elif c=='0':
res = res and (not input[i])
elif c=='1':
res = res and input[i]
i+=1
return res
n = 10
# 一个n位数,每一位为0或1,用程序枚举所有的组合情况
m = 0
minterms = []
for i in range(2**n):
s = bin(i)[2:] # 转化为二进制字符串
s = '0' * (n - len(s)) + s # 前面补0
input = [c == '1' for c in s]
res = 0
for c in exp.split('+'):
res = res or unit(c, input)
print(f'{s} | {str(int(res))}')
if res:
m += 1
minterms.append(i)
print(minterms)
print(m)