code cleanup

This commit is contained in:
dymik739 2023-04-01 19:29:57 +03:00
parent de5f5a70df
commit 6cda8bcfa0
1 changed files with 3 additions and 29 deletions

View File

@ -11,35 +11,12 @@ al = align_binary_to_right
def multiply(x, y, method): def multiply(x, y, method):
if method == 4: if method == 4:
n = len(bin(x)[2:]) # base registry bit length, usually written as n n = len(bin(x)[2:]) # base registry bit length, usually written as n
# every table line has registers like so: RG1, RG3, RG2 # every table line has registers like so: RG1, RG3, RG2
data_table = [[["0"*(2*n+1), "0" + bin(y)[2:] + "0"*n, bin(x)[2:], "-"]]*2] data_table = [[["0"*(2*n+1), "0" + bin(y)[2:] + "0"*n, bin(x)[2:], "-"]]*2]
print(f"Starting with: {data_table}")
print(data_table[-1][-1][2])
print(int('0b' + data_table[-1][-1][2], 2))
while int('0b' + data_table[-1][-1][2], 2) != 0: while int('0b' + data_table[-1][-1][2], 2) != 0:
data_table.append([]) data_table.append([])
'''
if data_table[-2][-1][2][0] == "1":
data_table[-1].append([
al(bin(int("0b"+data_table[-2][-1][0], 2) + int("0b"+data_table[-2][-1][1], 2))[-(2*n+1):], 2*n+1), # RG1 + RG3
data_table[-2][-1][1],
data_table[-2][-1][2],
])
data_table[-1].append([
data_table[-1][-1][0],
'0' + data_table[-1][-1][1][:-1], # 0.r(RG3)
data_table[-2][-1][2][1:] + '0', # l(RG2).0
])
'''
'''
if data_table[-2][-1][2][0] == "1":
data_table[-1].append([
al(bin(int("0b"+data_table[-2][-1][0], 2) + int("0b"+data_table[-2][-1][1], 2))[-(2*n+1):], 2*n+1), # RG1 + RG3
'0' + data_table[-2][1][:-1],
data_table[-2][2][1:] + '0', # l(RG2).0
'''
if data_table[-2][-1][2][0] == "1": if data_table[-2][-1][2][0] == "1":
data_table[-1].append([ data_table[-1].append([
@ -64,9 +41,6 @@ def multiply(x, y, method):
"0.r(RG3), l(RG2).0" "0.r(RG3), l(RG2).0"
]) ])
print(data_table)
return data_table return data_table
if __name__ == "__main__": if __name__ == "__main__":
@ -78,7 +52,7 @@ if __name__ == "__main__":
from lib.prettytable import PrettyTable from lib.prettytable import PrettyTable
pt = PrettyTable() pt = PrettyTable()
pt.field_names = ["RG1", "RG3", "RG2", "Operations"] pt.field_names = ["RG1", "RG3", "RG2", "Operations"]
for i in dt[1:]: for i in dt[1:]:
for j in range(len(i)): for j in range(len(i)):
if j+1 == len(i): if j+1 == len(i):