MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / selection

Function selection

boolean_algebra/quine_mc_cluskey.py:81–119  ·  view source on GitHub ↗

>>> selection([[1]],['0.00.01.5']) ['0.00.01.5'] >>> selection([[1]],['0.00.01.5']) ['0.00.01.5']

(chart: list[list[int]], prime_implicants: list[str])

Source from the content-addressed store, hash-verified

79
80
81def selection(chart: list[list[int]], prime_implicants: list[str]) -> list[str]:
82 """
83 >>> selection([[1]],['0.00.01.5'])
84 ['0.00.01.5']
85
86 >>> selection([[1]],['0.00.01.5'])
87 ['0.00.01.5']
88 """
89 temp = []
90 select = [0] * len(chart)
91 for i in range(len(chart[0])):
92 count = sum(row[i] == 1 for row in chart)
93 if count == 1:
94 rem = max(j for j, row in enumerate(chart) if row[i] == 1)
95 select[rem] = 1
96 for i, item in enumerate(select):
97 if item != 1:
98 continue
99 for j in range(len(chart[0])):
100 if chart[i][j] != 1:
101 continue
102 for row in chart:
103 row[j] = 0
104 temp.append(prime_implicants[i])
105 while True:
106 counts = [chart[i].count(1) for i in range(len(chart))]
107 max_n = max(counts)
108 rem = counts.index(max_n)
109
110 if max_n == 0:
111 return temp
112
113 temp.append(prime_implicants[rem])
114
115 for j in range(len(chart[0])):
116 if chart[rem][j] != 1:
117 continue
118 for i in range(len(chart)):
119 chart[i][j] = 0
120
121
122def prime_implicant_chart(

Callers 1

mainFunction · 0.85

Calls 2

countMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected