Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Blood distribution by tokiojapan55
def distribute_blood(blood_avail, blood_needs):
BLOOD_TYPES = ["A", "B", "AB", "O"]
result = {t:{tt:0 for tt in BLOOD_TYPES} for t in BLOOD_TYPES}
def supply(from_type, to_type):
volume = min(blood_needs[to_type], blood_avail[from_type])
result[from_type][to_type] += volume
blood_avail[from_type] -= volume
blood_needs[to_type] -= volume
supply("AB", "AB")
supply("O", "O")
supply("A", "A")
supply("O", "A")
supply("B", "B")
supply("O", "B")
supply("O", "AB")
supply("A", "AB")
supply("B", "AB")
return result
June 1, 2023
Comments: