Welcome to Project Lovelace! We're still super new so there are still tons of bugs to find and improvements to make. If you have any suggestions, complaints, or any comments at all please let us know on Discourse!

Blood types

You will learn about: blood types and complex branching statements

Each person has different blood depending on which antibodies and antigens bind to the surface of their red blood cells. They can be categorized in many different ways, but the two most important are the ABO group system (with four groups: A, B, AB, O) and the Rh blood group system (with two groups: +, -). The chart below shows how you can determine whether blood is suitable for transfusion.



Hospitals have blood banks that collect blood donations and store them until they're needed by patients. Every time a patient needs a blood transfusion, the hospital needs to check that they have some suitable blood that can be accepted by the patient's body. Given a patient's blood type and a list of available blood types figure out if the patient will survive.


Input: The person's blood type as a string, and a list of strings with available blood types.

Output: True if the person can be saved, and false otherwise.


Example 1

Input blood type: "B+" Input list of available blood types: ["A-", "B+", "AB+", "O+", "B+", "B-"] Output survivability: True

Example 2

Input blood type: "AB-" Input list of available blood types: ["O+", "AB+"] Output survivability: False


 Difficulty  Timesink
 Maximum runtime 60 s  Max. memory usage 250 MiB
 Function signature survive(blood_type, available_blood_types)

Write a function that accepts the input as function parameters and returns the correct output. Make sure to read the description above to produce the correct output in the correct format and use the correct function signature so we can run your code. A good first step is to try reproducing the example(s). Your code must not take longer than the maximum runtime to run and must not use more memory than the allowed limit.




You must be logged in to view your submissions.

Notes

  • The ABO blood group system categorizes blood by the presence or absence of two oligosaccharides. The A oligosaccharide is present in A blood, the B oligosaccharide is present in B blood, both are present in AB blood, and neither is present in O blood.
  • The Rh blood group system categorizes blood by the presence of the Rh(D) antigen. It's present in + blood, and absent in - blood.
  • There are over 200 rare blood types that can complicate blood transfusions.
  • You could die if your body receives blood that is not suitable.

Let us know what you think about this problem! Was it too hard? Difficult to understand? Also feel free to discuss the problem, ask questions, and post cool stuff on Discourse. You should be able see a discussion thread below. Feel free to post your solutions but if you do please organize and document your code well so others can learn from it.