-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblood_type_compatibility.py
More file actions
60 lines (48 loc) · 1.14 KB
/
blood_type_compatibility.py
File metadata and controls
60 lines (48 loc) · 1.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
import sys
import alice
import bob
import dealer
def __get_blood_type_bits(i):
switcher = {
"AB+": 7,
"AB-": 6,
"A+": 5,
"A-": 4,
"B+": 3,
"B-": 2,
"O+": 1,
"O-": 0,
"111": 7,
"110": 6,
"101": 5,
"100": 4,
"011": 3,
"010": 2,
"001": 1,
"000": 0
}
return switcher.get(i, "Invalid blood type.")
def __blood_type_compatibility(x, y):
dealer.__init()
dealer.init_alice(x)
dealer.init_bob(y)
bob.receive(alice.send())
v, z_b = bob.send()
alice.receive(v, z_b)
return alice.output_z()
def should_return(x, y):
should_be = 0
if (x | y) == x:
should_be = 1
return should_be
def run(*args):
if len(sys.argv) > 1 and sys.argv[1] == "spec":
val1 = input("Enter blood type for recipient: ")
val2 = input("Enter blood type for donor: ")
x = __get_blood_type_bits(val1)
y = __get_blood_type_bits(val2)
print(__blood_type_compatibility(x, y))
else:
x = args[0]
y = args[1]
return __blood_type_compatibility(x, y)