diff --git a/handin_1/look_up.py/.idea/encodings.xml b/handin_1/look_up.py/.idea/encodings.xml
deleted file mode 100644
index 15a15b2..0000000
--- a/handin_1/look_up.py/.idea/encodings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/handin_1/look_up.py/.idea/inspectionProfiles/Project_Default.xml b/handin_1/look_up.py/.idea/inspectionProfiles/Project_Default.xml
deleted file mode 100644
index 5dc0e56..0000000
--- a/handin_1/look_up.py/.idea/inspectionProfiles/Project_Default.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/handin_1/look_up.py/.idea/look_up.py.iml b/handin_1/look_up.py/.idea/look_up.py.iml
deleted file mode 100644
index 6711606..0000000
--- a/handin_1/look_up.py/.idea/look_up.py.iml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/handin_1/look_up.py/.idea/misc.xml b/handin_1/look_up.py/.idea/misc.xml
deleted file mode 100644
index 37d8a93..0000000
--- a/handin_1/look_up.py/.idea/misc.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/handin_1/look_up.py/.idea/modules.xml b/handin_1/look_up.py/.idea/modules.xml
deleted file mode 100644
index 41b2a07..0000000
--- a/handin_1/look_up.py/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/handin_1/look_up.py/.idea/workspace.xml b/handin_1/look_up.py/.idea/workspace.xml
deleted file mode 100644
index 7bd7add..0000000
--- a/handin_1/look_up.py/.idea/workspace.xml
+++ /dev/null
@@ -1,169 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1566900410249
-
-
- 1566900410249
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/handin_1/look_up.py/look_up.py b/handin_1/look_up.py/look_up.py
deleted file mode 100644
index 510a910..0000000
--- a/handin_1/look_up.py/look_up.py
+++ /dev/null
@@ -1,90 +0,0 @@
-table =\
- {
- 'O-': {
- 'O-': True,
- 'O+': True,
- 'A-': True,
- 'A+': True,
- 'B-': True,
- 'B+': True,
- 'AB-': True,
- 'AB+': True
- },
- 'O+': {
- 'O-': False,
- 'O+': True,
- 'A-': False,
- 'A+': True,
- 'B-': False,
- 'B+': True,
- 'AB-': False,
- 'AB+': True
- },
- 'A-': {
- 'O-': False,
- 'O+': False,
- 'A-': True,
- 'A+': True,
- 'B-': False,
- 'B+': False,
- 'AB-': True,
- 'AB+': True
- },
- 'A+': {
- 'O-': False,
- 'O+': False,
- 'A-': False,
- 'A+': True,
- 'B-': False,
- 'B+': False,
- 'AB-': False,
- 'AB+': True
- },
- 'B-': {
- 'O-': False,
- 'O+': False,
- 'A-': False,
- 'A+': False,
- 'B-': True,
- 'B+': True,
- 'AB-': True,
- 'AB+': True
- },
- 'B+': {
- 'O-': False,
- 'O+': False,
- 'A-': False,
- 'A+': False,
- 'B-': False,
- 'B+': True,
- 'AB-': False,
- 'AB+': True
- },
- 'AB-': {
- 'O-': False,
- 'O+': False,
- 'A-': False,
- 'A+': False,
- 'B-': False,
- 'B+': False,
- 'AB-': True,
- 'AB+': True
- },
- 'AB+': {
- 'O-': False,
- 'O+': False,
- 'A-': False,
- 'A+': False,
- 'B-': False,
- 'B+': False,
- 'AB-': False,
- 'AB+': True
- }
-}
-
-
-def look_up(donor, rec):
- return table[donor][rec]
-
-
-print(look_up('A-', 'O-'))
diff --git a/week1.py b/week1.py
new file mode 100644
index 0000000..57c0ff0
--- /dev/null
+++ b/week1.py
@@ -0,0 +1,123 @@
+import itertools
+from enum import unique, Enum
+
+
+@unique
+class BloodType(Enum):
+ O_NEGATIVE = (0, 0, 0) # (a, b, sign)
+ O_POSITIVE = (0, 0, 1)
+ A_NEGATIVE = (1, 0, 0)
+ A_POSITIVE = (1, 0, 1)
+ B_NEGATIVE = (0, 1, 0)
+ B_POSITIVE = (0, 1, 1)
+ AB_NEGATIVE = (1, 1, 0)
+ AB_POSITIVE = (1, 1, 1)
+
+
+def blood_cell_compatibility_lookup(recipient: BloodType, donor: BloodType) -> bool:
+ """
+ https://en.wikipedia.org/wiki/Blood_type#Red_blood_cell_compatibility
+ """
+ return {
+ BloodType.O_NEGATIVE: {
+ BloodType.O_NEGATIVE: True,
+ BloodType.O_POSITIVE: False,
+ BloodType.A_NEGATIVE: False,
+ BloodType.A_POSITIVE: False,
+ BloodType.B_NEGATIVE: False,
+ BloodType.B_POSITIVE: False,
+ BloodType.AB_NEGATIVE: False,
+ BloodType.AB_POSITIVE: False
+ },
+ BloodType.O_POSITIVE: {
+ BloodType.O_NEGATIVE: True,
+ BloodType.O_POSITIVE: True,
+ BloodType.A_NEGATIVE: False,
+ BloodType.A_POSITIVE: False,
+ BloodType.B_NEGATIVE: False,
+ BloodType.B_POSITIVE: False,
+ BloodType.AB_NEGATIVE: False,
+ BloodType.AB_POSITIVE: False
+ },
+ BloodType.A_NEGATIVE: {
+ BloodType.O_NEGATIVE: True,
+ BloodType.O_POSITIVE: False,
+ BloodType.A_NEGATIVE: True,
+ BloodType.A_POSITIVE: False,
+ BloodType.B_NEGATIVE: False,
+ BloodType.B_POSITIVE: False,
+ BloodType.AB_NEGATIVE: False,
+ BloodType.AB_POSITIVE: False
+ },
+ BloodType.A_POSITIVE: {
+ BloodType.O_NEGATIVE: True,
+ BloodType.O_POSITIVE: True,
+ BloodType.A_NEGATIVE: True,
+ BloodType.A_POSITIVE: True,
+ BloodType.B_NEGATIVE: False,
+ BloodType.B_POSITIVE: False,
+ BloodType.AB_NEGATIVE: False,
+ BloodType.AB_POSITIVE: False
+ },
+ BloodType.B_NEGATIVE: {
+ BloodType.O_NEGATIVE: True,
+ BloodType.O_POSITIVE: False,
+ BloodType.A_NEGATIVE: False,
+ BloodType.A_POSITIVE: False,
+ BloodType.B_NEGATIVE: True,
+ BloodType.B_POSITIVE: False,
+ BloodType.AB_NEGATIVE: False,
+ BloodType.AB_POSITIVE: False
+ },
+ BloodType.B_POSITIVE: {
+ BloodType.O_NEGATIVE: True,
+ BloodType.O_POSITIVE: True,
+ BloodType.A_NEGATIVE: False,
+ BloodType.A_POSITIVE: False,
+ BloodType.B_NEGATIVE: True,
+ BloodType.B_POSITIVE: True,
+ BloodType.AB_NEGATIVE: False,
+ BloodType.AB_POSITIVE: False
+ },
+ BloodType.AB_NEGATIVE: {
+ BloodType.O_NEGATIVE: True,
+ BloodType.O_POSITIVE: False,
+ BloodType.A_NEGATIVE: True,
+ BloodType.A_POSITIVE: False,
+ BloodType.B_NEGATIVE: True,
+ BloodType.B_POSITIVE: False,
+ BloodType.AB_NEGATIVE: True,
+ BloodType.AB_POSITIVE: False
+ },
+ BloodType.AB_POSITIVE: {
+ BloodType.O_NEGATIVE: True,
+ BloodType.O_POSITIVE: True,
+ BloodType.A_NEGATIVE: True,
+ BloodType.A_POSITIVE: True,
+ BloodType.B_NEGATIVE: True,
+ BloodType.B_POSITIVE: True,
+ BloodType.AB_NEGATIVE: True,
+ BloodType.AB_POSITIVE: True
+ },
+ }[recipient][donor]
+
+
+def blood_cell_compatibility_boolean(recipient: BloodType, donor: BloodType) -> bool:
+ (ra, rb, rs), (da, db, ds) = recipient.value, donor.value
+
+ return (ra or not da) and (rb or not db) and (rs or not ds)
+
+
+if __name__ == '__main__':
+ green = 0
+ red = 0
+ for recipient, donor in itertools.product(BloodType, repeat=2):
+ lookup = blood_cell_compatibility_lookup(recipient, donor)
+ boolean = blood_cell_compatibility_boolean(recipient, donor)
+ if lookup == boolean:
+ green += 1
+ else:
+ print(f"'{BloodType(donor).name} -> {BloodType(recipient).name}' should be {lookup}.")
+ red += 1
+ print("Green:", green)
+ print("Red :", red)