Skip to content

Instantly share code, notes, and snippets.

@alex0112
Created April 29, 2024 16:31
Show Gist options
  • Save alex0112/2556a3565bc039d794ba0e50c762a16d to your computer and use it in GitHub Desktop.
Save alex0112/2556a3565bc039d794ba0e50c762a16d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
##########################
# Initial Blood Type Set #
##########################
#types = set([ ('O+', 'O+'), ('O-', 'O-'), ('O-', 'O+'), ('O-', 'A+'), ('O-', 'B+'), ('O-', 'AB+'), ('A-', 'A-'), ('A+', 'A+'), ('A-', 'AB+'), ('A+', 'AB+'), ('B-', 'B-'), ('B+', 'B+'), ('B-', 'AB+'), ('AB+', 'AB+'), ('AB-', 'AB-'), ('AB-', 'AB+') ])
types = set([
('O+', 'O+'),
('O+', 'A+'),
('O+', 'B+'),
('O+', 'AB+'),
('O-', 'O-'),
('O-', 'O+'),
('O-', 'A-'),
('O-', 'A+'),
('O-', 'B+'),
('O-', 'B-'),
('O-', 'AB+'),
('O-', 'AB-'),
('A-', 'A+'),
('A-', 'A-'),
('A-', 'AB+'),
('A-', 'AB-'),
('A-', 'AB+'),
('A+', 'A+'),
('A+', 'AB+'),
('B-', 'B-'),
('B-', 'B+'),
('B-', 'AB-'),
('B-', 'AB+'),
('B+', 'B+'),
('B+', 'AB+'),
('AB-', 'AB-'),
('AB-', 'AB+'),
('AB+', 'AB+'),
])
print("""
## Blood Types Assignment
Alex Larsen - 10845158
0. blood types = {O+, O-, A+, A-, B+, B-, AB+, AB-}
1.
- V is the set of *vertices*
- E is the set of *edges*
""")
############
# Vertices #
############
print("\t- V = { ", end='')
vertices = set()
for k, _v in types:
vertices.add(k)
for v in vertices:
print(f"{v}, ", end='')
print("}")
#########
# Edges #
#########
print("\t- E = { ", end='')
edges = set()
for k, v in types:
edges.add((k, v))
print(f"({k}, {v}), ", end='')
print("}")
print("""
2.
```
""")
###########
# Arrowed #
###########
print("Donor => Recepient")
for k, v in types:
print(f"{k} => {v}")
print("```")
###################
# Adjacency Chart #
###################
from collections import defaultdict as dd
results = dd(set)
for k, v in types:
results[k].add(v)
results = dict(results)
print("""
3.
```
""")
print("Adjacency List:\n")
print("Donor => Recepient")
for bt in results.keys():
v = results[bt]
v = ', '.join(v)
print(f"{bt} => {v}")
print("```")
print("\n\n")
print("4. ")
print("""
```
A+ A- B+ B- AB+ AB- O+ O-
A+ 1 0 0 0 1 0 0 0
A- 1 1 0 0 1 1 0 0
B+ 0 0 1 0 1 0 0 0
B- 0 0 1 1 1 1 0 0
AB+ 0 0 0 0 1 0 0 0
AB- 0 0 0 0 1 1 0 0
O+ 1 0 1 0 1 0 1 0
O- 1 1 1 1 1 1 1 1
```
""")
###########
# Digraph #
###########
import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
G.add_edges_from(list(types))
pos = nx.spring_layout(G) ## TODO: revise
nx.draw_networkx_nodes(G, pos, node_color='red')
nx.draw_networkx_edges(G, pos, edgelist=G.edges(), edge_color='black')
nx.draw_networkx_labels(G, pos)
plt.savefig('digraph.png')#, bbox_inches='tight')
print("5. <img src='./digraph.png'>\n")
print("""
6. Is D reflexive? **Yes**
7. Is D anti-reflexive? **No**
8. Is D symmetric? **No**
9. Is D anti-symmetric? **Yes**
10. Is D transitive? **Yes**
""");
print("""
11. For the chart below, add rows for every blood type, and fill in the numbers for the in and out degrees.
```
Blood Type in-degrees out-degrees
O+ 2 4
O- 1 8
A+ 3 2
A- 2 5
B+ 4 2
B- 2 4
AB+ 8 1
AB- 3 2
```
""")
print("12. **O-**")
print("""
13.Based on your chart in #11, which single blood type can receive from the most blood types?
**AB+**
14. Is D a partial order? **Yes** (1 pt)
15 Is D a total order? **No** (1 pt)
16. Which blood type(s) is minimal? **O-** (1 pt)
17. Which blood type(s) is maximal? **AB+** (1 pt)
18. Is D a strict order? **No** (1 pt)
19. Is D a DAG?
**No. All nodes refer to themselves making a cycle of 1.**
20. Is D an equivalence relation? **No** (1 pt)
21. Is D the transitive closure of D? In other words, does D = D+?
**Yes**
### Short Answer Thought Question
22. Why doesn't it make sense to talk about D2? (2 pts)
Because you wouldn't take blood out of one person put it into another person, and then take it out of that person and put it into a third person. Unless you were some kind of sick scientist.
""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment