Hi, I need to write this without using recursion. I am learning Dr. Racket, not phyton. I can use local definitions and lambda.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hi, I need to write this without using recursion. I am learning Dr. Racket, not phyton. I can use local definitions and lambda. 

 

Here is the problem specification.
Hospitals rely on donors to provide blood for people who are in accidents or scheduled for surgery. However, people have different blood types, and some blood types are compatible for donation and others
are not. There are eight different blood types: 0-, O+, B-, B+, A-, A+, AB-, AB+
The rules for blood donations are shown in a table from the Canadian Blood Services website.
Here is a summary of that table:
• A recipient can receive blood from anyone with the same blood type.
• A person with O- blood can be a donor for anyone.
• A person with AB+ blood can receive blood from anyone.
• Additonally, a person with AB- blood can receive blood from a donor with B- or A- blood.
• Additonally, a person with A+ blood can receive blood from a donor with O+ or A- blood.
• Additonally, a person with B+ blood can receive blood from a donor with O+ or B- blood.
No other combination of donor and recipient blood types is compatible.
For this question, we will use symbols to represent each blood type. The symbol will match the types described above. So for example, the 0+ blood type will be represented by the symbol '0+. All symbols in
the question will be one of the blood types described above.
Write a function compatible-litres in Racket that consumes a list of symbols, blood-bank, and a symbol, blood-type. Each element in blood-bank represents a 0.5 litre donation of the matching blood
type symbol, and blood-type represents the blood type of a blood transfusion recipient. The function produces the total number of litres available for donation for someone with the given blood-type given
the donations in blood-bank.
For example:
1 > (compatible-litres (list '0- '0+ '0- 'B- 'AB-) 'AB-)
2 2
3 > (compatible-litres (list 'A+ 'B+) 'A-)
4 0
5 > (compatible-litres (list 'A+ 'B+ 'AB+) 'AB+)
6 1.5
Submit your solution in the file a08q1.rkt.
Transcribed Image Text:Here is the problem specification. Hospitals rely on donors to provide blood for people who are in accidents or scheduled for surgery. However, people have different blood types, and some blood types are compatible for donation and others are not. There are eight different blood types: 0-, O+, B-, B+, A-, A+, AB-, AB+ The rules for blood donations are shown in a table from the Canadian Blood Services website. Here is a summary of that table: • A recipient can receive blood from anyone with the same blood type. • A person with O- blood can be a donor for anyone. • A person with AB+ blood can receive blood from anyone. • Additonally, a person with AB- blood can receive blood from a donor with B- or A- blood. • Additonally, a person with A+ blood can receive blood from a donor with O+ or A- blood. • Additonally, a person with B+ blood can receive blood from a donor with O+ or B- blood. No other combination of donor and recipient blood types is compatible. For this question, we will use symbols to represent each blood type. The symbol will match the types described above. So for example, the 0+ blood type will be represented by the symbol '0+. All symbols in the question will be one of the blood types described above. Write a function compatible-litres in Racket that consumes a list of symbols, blood-bank, and a symbol, blood-type. Each element in blood-bank represents a 0.5 litre donation of the matching blood type symbol, and blood-type represents the blood type of a blood transfusion recipient. The function produces the total number of litres available for donation for someone with the given blood-type given the donations in blood-bank. For example: 1 > (compatible-litres (list '0- '0+ '0- 'B- 'AB-) 'AB-) 2 2 3 > (compatible-litres (list 'A+ 'B+) 'A-) 4 0 5 > (compatible-litres (list 'A+ 'B+ 'AB+) 'AB+) 6 1.5 Submit your solution in the file a08q1.rkt.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education