-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogicops.py
56 lines (40 loc) · 839 Bytes
/
logicops.py
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
def safety_check(gate: str) -> bool:
if gate in operations:
return True
else:
return False
def NOT(a: str) -> str:
if a == "1":
return "0"
else:
return "1"
def AND(a: str, b: str) -> str:
if a == "1" and b == "1":
return "1"
else:
return "0"
def OR(a: str, b: str) -> str:
if a == "1" or b == "1":
return "1"
else:
return "0"
def XOR(a: str, b: str) -> str:
if a != b:
return "1"
else:
return "0"
def NAND(a: str, b: str) -> str:
return NOT(AND(a, b))
def NOR(a: str, b: str) -> str:
return NOT(OR(a, b))
def XNOR(a: str, b: str) -> str:
return NOT(XOR(a, b))
operations = {
"NOT": NOT,
"AND": AND,
"OR": OR,
"XOR": XOR,
"NAND": NAND,
"NOR": NOR,
"XNOR": XNOR,
}