mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 18:38:39 +00:00
Reduce the complexity of boolean_algebra/quine_mc_cluskey.py
This commit is contained in:
parent
56a40eb3ee
commit
e622141a76
@ -92,30 +92,23 @@ def selection(chart: list[list[int]], prime_implicants: list[str]) -> list[str]:
|
||||
temp = []
|
||||
select = [0] * len(chart)
|
||||
for i in range(len(chart[0])):
|
||||
count = 0
|
||||
rem = -1
|
||||
for j in range(len(chart)):
|
||||
if chart[j][i] == 1:
|
||||
count += 1
|
||||
rem = j
|
||||
count = sum(chart[j][i] == 1 for j in range(len(chart)))
|
||||
if count == 1:
|
||||
rem = max(j for j in range(len(chart)) if chart[j][i] == 1, default=-1)
|
||||
select[rem] = 1
|
||||
for i in range(len(select)):
|
||||
if select[i] == 1:
|
||||
if select[i] != 1:
|
||||
continue
|
||||
for j in range(len(chart[0])):
|
||||
if chart[i][j] == 1:
|
||||
if chart[i][j] != 1:
|
||||
continue
|
||||
for k in range(len(chart)):
|
||||
chart[k][j] = 0
|
||||
temp.append(prime_implicants[i])
|
||||
while True:
|
||||
max_n = 0
|
||||
rem = -1
|
||||
count_n = 0
|
||||
for i in range(len(chart)):
|
||||
count_n = chart[i].count(1)
|
||||
if count_n > max_n:
|
||||
max_n = count_n
|
||||
rem = i
|
||||
counts = [chart[i].count(1) for i in range(len(chart))]
|
||||
max_n = max(counts)
|
||||
rem = counts.index(max_n)
|
||||
|
||||
if max_n == 0:
|
||||
return temp
|
||||
@ -123,7 +116,8 @@ def selection(chart: list[list[int]], prime_implicants: list[str]) -> list[str]:
|
||||
temp.append(prime_implicants[rem])
|
||||
|
||||
for i in range(len(chart[0])):
|
||||
if chart[rem][i] == 1:
|
||||
if chart[rem][i] != 1:
|
||||
continue
|
||||
for j in range(len(chart)):
|
||||
chart[j][i] = 0
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user