From 753c7f28e67da4ed51a5409700b63041d09094ec Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Thu, 17 Nov 2022 12:08:42 +0000 Subject: [PATCH] Nomenclature fix --- tools/karnaugh-map-builder/README.md | 15 ----- tools/truthtable/README.md | 15 +++++ .../openInTerminal.png | Bin .../karnaugh.py => truthtable/truthtable.py} | 52 +++++++++--------- 4 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 tools/karnaugh-map-builder/README.md create mode 100644 tools/truthtable/README.md rename tools/{karnaugh-map-builder => truthtable}/openInTerminal.png (100%) rename tools/{karnaugh-map-builder/karnaugh.py => truthtable/truthtable.py} (66%) diff --git a/tools/karnaugh-map-builder/README.md b/tools/karnaugh-map-builder/README.md deleted file mode 100644 index 13910e0..0000000 --- a/tools/karnaugh-map-builder/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Karnaugh Map Builder -### Script to build the karnaugh map for a given function. ---- -## Installing -#### 1. Head over to [Release](https://github.com/TiagoRG/uaveiro-leci/releases/tag/kmb-v1) and download the python file. -#### 2. Save it on any directory and then open the directory. -#### 3. Inside the directory, right click and choose "Open in terminal" -![- Unable to load image -](https://github.com/TiagoRG/uaveiro-leci/blob/master/tools/karnaugh-map-builder/openInTerminal.png) -#### 4. Run the following command: -`python3 karnaugh.py bash` -#### 5. Relaunch the terminal and you will have the `karnaugh` command ---- -#### Use `karnaugh usage` to know better how to use this tool. -#### If you want to change the location of the `karnaugh.py` file, move it to another directory, open that directory in terminal and run -`python3 karnaugh.py bash --reset` diff --git a/tools/truthtable/README.md b/tools/truthtable/README.md new file mode 100644 index 0000000..8e5c06d --- /dev/null +++ b/tools/truthtable/README.md @@ -0,0 +1,15 @@ +# Truth Table Builder +### Script to build the truth table for a given function. +--- +## Installing +#### 1. Head over to [Release](https://github.com/TiagoRG/uaveiro-leci/releases/tag/ttb) and download the python file. +#### 2. Save it on any directory and then open the directory. +#### 3. Inside the directory, right click and choose "Open in terminal" +![- Unable to load image -](https://github.com/TiagoRG/uaveiro-leci/blob/master/tools/truthtable/openInTerminal.png) +#### 4. Run the following command: +`python3 truthtable.py bash` +#### 5. Relaunch the terminal and you will have the `truthtable` command +--- +#### Use `truthtable usage` to know better how to use this tool. +#### If you want to change the location of the `truthtable.py` file, move it to another directory, open that directory in terminal and run +`python3 truthtable.py bash --reset` diff --git a/tools/karnaugh-map-builder/openInTerminal.png b/tools/truthtable/openInTerminal.png similarity index 100% rename from tools/karnaugh-map-builder/openInTerminal.png rename to tools/truthtable/openInTerminal.png diff --git a/tools/karnaugh-map-builder/karnaugh.py b/tools/truthtable/truthtable.py similarity index 66% rename from tools/karnaugh-map-builder/karnaugh.py rename to tools/truthtable/truthtable.py index 5d44480..9fde1b4 100644 --- a/tools/karnaugh-map-builder/karnaugh.py +++ b/tools/truthtable/truthtable.py @@ -8,19 +8,19 @@ def main(): if len(sys.argv) == 1 or sys.argv[1] == 'usage': print("""Usage: -karnaugh '': - Prints the karnaugh map of the function. +truthtable '': + Prints the truth table map of the function. Valid characters: > Variables: a-z > Operators: +, *, ~, (, ); You can't use ~ before () -karnaugh bash: - Adds the command karnaugh to bash, so you can use it from anywhere. +truthtable bash: + Adds the command truthtable to bash, so you can use it from anywhere. -karnaugh bash --reset: - Resets the command karnaugh in bash in case it's broken, so you can use it from anywhere. +truthtable bash --reset: + Resets the command truthtable in bash in case it's broken, so you can use it from anywhere. -karnaugh usage: +truthtable usage: Prints this message.""") return if sys.argv[1] == "bash": @@ -28,11 +28,11 @@ karnaugh usage: if len(sys.argv) == 2: with open(f'/home/{username}/.bashrc', 'r') as bashrc: for line in bashrc: - if line.startswith('alias karnaugh='): - print('Command already exists, try using, after opening a new terminal, karnaugh ') + if line.startswith('alias truthtable='): + print('Command already exists, try using, after opening a new terminal, truthtable \'\'') return - os.system(f'echo "\n\nalias karnaugh=\'python3 {pathlib.Path(__file__).parent.absolute()}/karnaugh.py\'\n" >> \'/home/{username}/.bashrc\'') - print('Command added to bash, try using karnaugh .\nIf it doesn\'t work, do karnaugh bash --reset.') + os.system(f'echo "\n\nalias truthtable=\'python3 {pathlib.Path(__file__).parent.absolute()}/truthtable.py\'\n" >> \'/home/{username}/.bashrc\'') + print('Command added to bash, try using truthtable .\nIf it doesn\'t work, do truthtable bash --reset.') elif sys.argv[2] == '--reset': with open(f'/home/{username}/.bashrc', 'r') as bashrc: lines = bashrc.readlines() @@ -42,16 +42,16 @@ karnaugh usage: linesDict[index] = line index += 1 for key in linesDict: - if linesDict[key].startswith('alias karnaugh='): + if linesDict[key].startswith('alias truthtable='): del linesDict[key] break string = '' for key in linesDict: string += linesDict[key] - string += f'\n\nalias karnaugh=\'python3 {pathlib.Path(__file__).parent.absolute()}/karnaugh.py\'\n' + string += f'\n\nalias truthtable=\'python3 {pathlib.Path(__file__).parent.absolute()}/truthtable.py\'\n' with open(f'/home/{username}/.bashrc', 'w') as bashrc: bashrc.write(string) - print('Command readded to bash, try using, after opening a new terminal, karnaugh .') + print('Command readded to bash, try using, after opening a new terminal, truthtable .') else: function = sys.argv[1] @@ -60,19 +60,19 @@ karnaugh usage: for char in function: if not (re.match(validVariables, char) or char in validOperators): - print("Invalid function, use 'karnaugh usage' to see the valid characters.") + print("Invalid function, use 'truthtable usage' to see the valid characters.") return variables = re.findall(validVariables, function) variables = list(dict.fromkeys(variables)) variables.sort() - karnaughMap = getMap(variables, function) - printMap(variables, karnaughMap) + truthTable = getTable(variables, function) + printTable(variables, truthTable) -def getMap(variables, function): - karnaughMap = {} +def getTable(variables, function): + truthTable = {} for n in range(2 ** len(variables)): tempFunction = function binary = bin(n)[2:] @@ -87,17 +87,17 @@ def getMap(variables, function): tempFunction = tempFunction.replace(tempFunction[index], binary[variables.index(var)]) if tempFunction[index - 1] != '~' else tempFunction.replace(f"~{tempFunction[index]}", str(int(not int(binary[variables.index(tempFunction[index])])))+" ") index += 1 try: - karnaughMap[binary] = eval(tempFunction) + truthTable[binary] = eval(tempFunction) except: - print("Invalid function, use 'karnaugh usage' to see the valid characters.") + print("Invalid function, use 'truthtable usage' to see the valid characters.") return - if karnaughMap[binary] > 1: - karnaughMap[binary] = 1 + if truthTable[binary] > 1: + truthTable[binary] = 1 - return karnaughMap + return truthTable -def printMap(variables, karnaughMap): +def printTable(variables, truthTable): for var in variables: print("|---", end='') print('|-----|') @@ -107,7 +107,7 @@ def printMap(variables, karnaughMap): for var in variables: print("|---", end='') print('|-----|') - for key, value in karnaughMap.items(): + for key, value in truthTable.items(): for char in key: print("| " + char, end=' ') print(f"| {value} |")