Nomenclature fix
This commit is contained in:
parent
65cfef134a
commit
2747c967e2
|
@ -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`
|
|
|
@ -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`
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 47 KiB |
|
@ -8,19 +8,19 @@ def main():
|
||||||
if len(sys.argv) == 1 or sys.argv[1] == 'usage':
|
if len(sys.argv) == 1 or sys.argv[1] == 'usage':
|
||||||
print("""Usage:
|
print("""Usage:
|
||||||
|
|
||||||
karnaugh '<function>':
|
truthtable '<function>':
|
||||||
Prints the karnaugh map of the function.
|
Prints the truth table map of the function.
|
||||||
Valid characters:
|
Valid characters:
|
||||||
> Variables: a-z
|
> Variables: a-z
|
||||||
> Operators: +, *, ~, (, ); You can't use ~ before ()
|
> Operators: +, *, ~, (, ); You can't use ~ before ()
|
||||||
|
|
||||||
karnaugh bash:
|
truthtable bash:
|
||||||
Adds the command karnaugh to bash, so you can use it from anywhere.
|
Adds the command truthtable to bash, so you can use it from anywhere.
|
||||||
|
|
||||||
karnaugh bash --reset:
|
truthtable bash --reset:
|
||||||
Resets the command karnaugh in bash in case it's broken, so you can use it from anywhere.
|
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.""")
|
Prints this message.""")
|
||||||
return
|
return
|
||||||
if sys.argv[1] == "bash":
|
if sys.argv[1] == "bash":
|
||||||
|
@ -28,11 +28,11 @@ karnaugh usage:
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
with open(f'/home/{username}/.bashrc', 'r') as bashrc:
|
with open(f'/home/{username}/.bashrc', 'r') as bashrc:
|
||||||
for line in bashrc:
|
for line in bashrc:
|
||||||
if line.startswith('alias karnaugh='):
|
if line.startswith('alias truthtable='):
|
||||||
print('Command already exists, try using, after opening a new terminal, karnaugh <function>')
|
print('Command already exists, try using, after opening a new terminal, truthtable \'<function>\'')
|
||||||
return
|
return
|
||||||
os.system(f'echo "\n\nalias karnaugh=\'python3 {pathlib.Path(__file__).parent.absolute()}/karnaugh.py\'\n" >> \'/home/{username}/.bashrc\'')
|
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 karnaugh <function>.\nIf it doesn\'t work, do karnaugh bash --reset.')
|
print('Command added to bash, try using truthtable <function>.\nIf it doesn\'t work, do truthtable bash --reset.')
|
||||||
elif sys.argv[2] == '--reset':
|
elif sys.argv[2] == '--reset':
|
||||||
with open(f'/home/{username}/.bashrc', 'r') as bashrc:
|
with open(f'/home/{username}/.bashrc', 'r') as bashrc:
|
||||||
lines = bashrc.readlines()
|
lines = bashrc.readlines()
|
||||||
|
@ -42,16 +42,16 @@ karnaugh usage:
|
||||||
linesDict[index] = line
|
linesDict[index] = line
|
||||||
index += 1
|
index += 1
|
||||||
for key in linesDict:
|
for key in linesDict:
|
||||||
if linesDict[key].startswith('alias karnaugh='):
|
if linesDict[key].startswith('alias truthtable='):
|
||||||
del linesDict[key]
|
del linesDict[key]
|
||||||
break
|
break
|
||||||
string = ''
|
string = ''
|
||||||
for key in linesDict:
|
for key in linesDict:
|
||||||
string += linesDict[key]
|
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:
|
with open(f'/home/{username}/.bashrc', 'w') as bashrc:
|
||||||
bashrc.write(string)
|
bashrc.write(string)
|
||||||
print('Command readded to bash, try using, after opening a new terminal, karnaugh <function>.')
|
print('Command readded to bash, try using, after opening a new terminal, truthtable <function>.')
|
||||||
else:
|
else:
|
||||||
function = sys.argv[1]
|
function = sys.argv[1]
|
||||||
|
|
||||||
|
@ -60,19 +60,19 @@ karnaugh usage:
|
||||||
|
|
||||||
for char in function:
|
for char in function:
|
||||||
if not (re.match(validVariables, char) or char in validOperators):
|
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
|
return
|
||||||
|
|
||||||
variables = re.findall(validVariables, function)
|
variables = re.findall(validVariables, function)
|
||||||
variables = list(dict.fromkeys(variables))
|
variables = list(dict.fromkeys(variables))
|
||||||
variables.sort()
|
variables.sort()
|
||||||
|
|
||||||
karnaughMap = getMap(variables, function)
|
truthTable = getTable(variables, function)
|
||||||
printMap(variables, karnaughMap)
|
printTable(variables, truthTable)
|
||||||
|
|
||||||
|
|
||||||
def getMap(variables, function):
|
def getTable(variables, function):
|
||||||
karnaughMap = {}
|
truthTable = {}
|
||||||
for n in range(2 ** len(variables)):
|
for n in range(2 ** len(variables)):
|
||||||
tempFunction = function
|
tempFunction = function
|
||||||
binary = bin(n)[2:]
|
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])])))+" ")
|
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
|
index += 1
|
||||||
try:
|
try:
|
||||||
karnaughMap[binary] = eval(tempFunction)
|
truthTable[binary] = eval(tempFunction)
|
||||||
except:
|
except:
|
||||||
print("Invalid function, use 'karnaugh usage' to see the valid characters.")
|
print("Invalid function, use 'truthtable usage' to see the valid characters.")
|
||||||
return
|
return
|
||||||
if karnaughMap[binary] > 1:
|
if truthTable[binary] > 1:
|
||||||
karnaughMap[binary] = 1
|
truthTable[binary] = 1
|
||||||
|
|
||||||
return karnaughMap
|
return truthTable
|
||||||
|
|
||||||
|
|
||||||
def printMap(variables, karnaughMap):
|
def printTable(variables, truthTable):
|
||||||
for var in variables:
|
for var in variables:
|
||||||
print("|---", end='')
|
print("|---", end='')
|
||||||
print('|-----|')
|
print('|-----|')
|
||||||
|
@ -107,7 +107,7 @@ def printMap(variables, karnaughMap):
|
||||||
for var in variables:
|
for var in variables:
|
||||||
print("|---", end='')
|
print("|---", end='')
|
||||||
print('|-----|')
|
print('|-----|')
|
||||||
for key, value in karnaughMap.items():
|
for key, value in truthTable.items():
|
||||||
for char in key:
|
for char in key:
|
||||||
print("| " + char, end=' ')
|
print("| " + char, end=' ')
|
||||||
print(f"| {value} |")
|
print(f"| {value} |")
|
Loading…
Reference in New Issue