Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@
* [Archimedes Principle](physics/archimedes_principle.py)
* [Casimir Effect](physics/casimir_effect.py)
* [Centripetal Force](physics/centripetal_force.py)
* [Grahams Law](physics/grahams_law.py)
* [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py)
* [Hubble Parameter](physics/hubble_parameter.py)
* [Ideal Gas Law](physics/ideal_gas_law.py)
Expand Down
40 changes: 17 additions & 23 deletions boolean_algebra/quine_mc_cluskey.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,40 +92,34 @@ 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)
select[rem] = 1
for i in range(len(select)):
if select[i] == 1:
for j in range(len(chart[0])):
if chart[i][j] == 1:
for k in range(len(chart)):
chart[k][j] = 0
temp.append(prime_implicants[i])
if select[i] != 1:
continue
for j in range(len(chart[0])):
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

temp.append(prime_implicants[rem])

for i in range(len(chart[0])):
if chart[rem][i] == 1:
for j in range(len(chart)):
chart[j][i] = 0
if chart[rem][i] != 1:
continue
for j in range(len(chart)):
chart[j][i] = 0


def prime_implicant_chart(
Expand Down