-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (54 loc) · 2.14 KB
/
main.py
File metadata and controls
64 lines (54 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# import pydatatable
from table_element import TableElement
from int_as_binary import IntAsBinary
from terms import Terms
def get_terms_for_flipflop(index: int, data: list[TableElement]):
must_js = []
must_ks = []
maybe_js = []
maybe_ks = []
digits = data[-1].value.bit_length()
for i in data:
flipflop = i.flipflops[index]
if flipflop["j"]:
must_js.append(IntAsBinary(i.value, digits=digits))
elif flipflop["j"] is None:
maybe_js.append(IntAsBinary(i.value, digits=digits))
if flipflop["k"]:
must_ks.append(IntAsBinary(i.value, digits=digits))
elif flipflop["k"] is None:
maybe_ks.append(IntAsBinary(i.value, digits=digits))
return {"j": (must_js, maybe_js), "k": (must_ks, maybe_ks)}
def main():
# mod_counter = int(input("Please enter your mod counter: "))
mod_counter = 7
table = [TableElement(i, mod_counter) for i in range(mod_counter)]
# counter = pydatatable.Table(location='counter', title=f'mod {mod_counter} counter')
# data = [i.to_list() for i in table]
# js = [f"J{i}" for i in range((mod_counter - 1).bit_length())]
# ks = [f"K{i}" for i in range((mod_counter - 1).bit_length())]
# title = ["x", "x\'"]
# for i, v in enumerate(js):
# title.append(v)
# title.append(ks[i])
# counter.add_data(data, title)
# counter.open()
terms: Terms = Terms(table, 0, "k")
minimized: [IntAsBinary] = terms.get_minimal_terms()
print(minimized)
# next_terms = []
# must_js, maybe_js = get_terms_for_flipflop(0, table)["j"]
# must_ks, maybe_ks = get_terms_for_flipflop(0, table)["k"]
# combined_js = must_js + maybe_js
# minimized_list = [False] * len(combined_js)
# for i, v in enumerate(combined_js)[:-1]:
# for j in range(i + 1, len(combined_js)):
# buffer = v.minimize(combined_js[j])
# if buffer is not None:
# next_terms.append(buffer)
# minimized_list[i] = True
# minimized_list[j] = True
# if not minimized_list[i]:
# next_terms.append(v)
if __name__ == "__main__":
main()