From 2fc3a29513bba4b8f455a171496460cc55ec9853 Mon Sep 17 00:00:00 2001 From: Renato771 Date: Sat, 2 Oct 2021 21:43:40 -0300 Subject: [PATCH 1/4] Syntax improvements (I hope) to boolean algebra --- boolean_algebra/quine_mc_cluskey.py | 43 ++++++++++++++--------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/boolean_algebra/quine_mc_cluskey.py b/boolean_algebra/quine_mc_cluskey.py index 9cc99b1eeabb..ad997438fe86 100644 --- a/boolean_algebra/quine_mc_cluskey.py +++ b/boolean_algebra/quine_mc_cluskey.py @@ -9,17 +9,17 @@ def compare_string(string1: str, string2: str) -> str: >>> compare_string('0110','1101') 'X' """ - l1 = list(string1) - l2 = list(string2) + list1 = list(string1) + list2 = list(string2) count = 0 - for i in range(len(l1)): - if l1[i] != l2[i]: + for index in range(len(list1)): + if list1[index] != list2[index]: count += 1 - l1[i] = "_" + list1[index] = "_" if count > 1: return "X" else: - return "".join(l1) + return "".join(list1) def check(binary: list[str]) -> list[str]: @@ -28,7 +28,7 @@ def check(binary: list[str]) -> list[str]: ['0.00.01.5'] """ pi = [] - while 1: + while True: check1 = ["$"] * len(binary) temp = [] for i in range(len(binary)): @@ -52,13 +52,13 @@ def decimal_to_binary(no_of_variable: int, minterms: list[float]) -> list[str]: ['0.00.01.5'] """ temp = [] - s = "" - for m in minterms: - for i in range(no_of_variable): - s = str(m % 2) + s - m //= 2 - temp.append(s) - s = "" + string = "" + for minterm in minterms: + for index in range(no_of_variable): + string = str(minterm % 2) + string + minterm //= 2 + temp.append(string) + string = "" return temp @@ -70,16 +70,13 @@ def is_for_table(string1: str, string2: str, count: int) -> bool: >>> is_for_table('01_','001',1) False """ - l1 = list(string1) - l2 = list(string2) + list1 = list(string1) + list2 = list(string2) count_n = 0 - for i in range(len(l1)): - if l1[i] != l2[i]: + for index in range(len(list1)): + if list1[index] != list2[index]: count_n += 1 - if count_n == count: - return True - else: - return False + return count_n == count def selection(chart: list[list[int]], prime_implicants: list[str]) -> list[str]: @@ -108,7 +105,7 @@ def selection(chart: list[list[int]], prime_implicants: list[str]) -> list[str]: for k in range(len(chart)): chart[k][j] = 0 temp.append(prime_implicants[i]) - while 1: + while True: max_n = 0 rem = -1 count_n = 0 From 7a52f3c92847c7a2e38428974bd149b20afb47be Mon Sep 17 00:00:00 2001 From: Renato771 Date: Mon, 25 Oct 2021 21:26:05 -0300 Subject: [PATCH 2/4] Reverted certain index variables to i --- boolean_algebra/quine_mc_cluskey.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/boolean_algebra/quine_mc_cluskey.py b/boolean_algebra/quine_mc_cluskey.py index ad997438fe86..39ad8df194d1 100644 --- a/boolean_algebra/quine_mc_cluskey.py +++ b/boolean_algebra/quine_mc_cluskey.py @@ -12,10 +12,10 @@ def compare_string(string1: str, string2: str) -> str: list1 = list(string1) list2 = list(string2) count = 0 - for index in range(len(list1)): - if list1[index] != list2[index]: + for i in range(len(list1)): + if list1[i] != list2[i]: count += 1 - list1[index] = "_" + list1[i] = "_" if count > 1: return "X" else: @@ -54,7 +54,7 @@ def decimal_to_binary(no_of_variable: int, minterms: list[float]) -> list[str]: temp = [] string = "" for minterm in minterms: - for index in range(no_of_variable): + for i in range(no_of_variable): string = str(minterm % 2) + string minterm //= 2 temp.append(string) @@ -73,8 +73,8 @@ def is_for_table(string1: str, string2: str, count: int) -> bool: list1 = list(string1) list2 = list(string2) count_n = 0 - for index in range(len(list1)): - if list1[index] != list2[index]: + for i in range(len(list1)): + if list1[i] != list2[i]: count_n += 1 return count_n == count From c49c3579ca02234ae8dc289261a49f7efe60ad65 Mon Sep 17 00:00:00 2001 From: Renato771 Date: Tue, 26 Oct 2021 21:19:07 -0300 Subject: [PATCH 3/4] remove extra line on decimal_to_binary --- boolean_algebra/quine_mc_cluskey.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/boolean_algebra/quine_mc_cluskey.py b/boolean_algebra/quine_mc_cluskey.py index 39ad8df194d1..d5b6fa31b118 100644 --- a/boolean_algebra/quine_mc_cluskey.py +++ b/boolean_algebra/quine_mc_cluskey.py @@ -52,13 +52,12 @@ def decimal_to_binary(no_of_variable: int, minterms: list[float]) -> list[str]: ['0.00.01.5'] """ temp = [] - string = "" for minterm in minterms: + string = "" for i in range(no_of_variable): string = str(minterm % 2) + string minterm //= 2 temp.append(string) - string = "" return temp From c99e70a85814c0c202ef1445800abbcb3c687385 Mon Sep 17 00:00:00 2001 From: John Law Date: Wed, 27 Oct 2021 11:54:37 +0800 Subject: [PATCH 4/4] Update quine_mc_cluskey.py --- boolean_algebra/quine_mc_cluskey.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/boolean_algebra/quine_mc_cluskey.py b/boolean_algebra/quine_mc_cluskey.py index d5b6fa31b118..cb1a872ea57d 100644 --- a/boolean_algebra/quine_mc_cluskey.py +++ b/boolean_algebra/quine_mc_cluskey.py @@ -1,5 +1,7 @@ from __future__ import annotations +from typing import Sequence + def compare_string(string1: str, string2: str) -> str: """ @@ -46,7 +48,7 @@ def check(binary: list[str]) -> list[str]: binary = list(set(temp)) -def decimal_to_binary(no_of_variable: int, minterms: list[float]) -> list[str]: +def decimal_to_binary(no_of_variable: int, minterms: Sequence[float]) -> list[str]: """ >>> decimal_to_binary(3,[1.5]) ['0.00.01.5'] @@ -142,7 +144,7 @@ def prime_implicant_chart( return chart -def main(): +def main() -> None: no_of_variable = int(input("Enter the no. of variables\n")) minterms = [ int(x)