28
1
A little known fact about vampires is that they must drink the blood of victim that has a compatible donor blood type. The compatibility matrix for vampires is the same as the regular red blood cell donor/recipient matrix. This can be summarized by the following American Red Cross table
Type You Can Give Blood To You Can Receive Blood From
A+ A+, AB+ A+, A-, O+, O-
O+ O+, A+, B+,AB+ O+, O-
B+ B+, AB+ B+, B-, O+, O-
AB+ AB+ everyone
A- A+, A-, AB+, AB- A-, O-
O- everyone O-
B- B+, B-, AB+, AB- B- O-
AB- AB+, AB- AB-, A-, B-, O-
Challenge
Write a function or program that takes a blood type as input and outputs two lists:
- the unordered list of types that may receive donation of the input type
- the unordered list of types that may give donation to the input type
If you write a function, then please also provide a test program to call that function with a few examples, so I can easily test it. In this case, the test program would not count towards your score.
Input
Input must be a string representing exactly one of the 8 possible red blood cell types O−
O+
A−
A+
B−
B+
AB−
AB+
. Input may be given via the normal methods (STDIN, command-line args, function args, etc).
If any other input is given then the program/function must return empty output or throw an error. Normally strict input-checking is not great in code-golf questions, but I felt given the life-death implications of getting blood types wrong that I should add this rule.
Output
Output will be two human-readable lists of blood types in whatever format is suitable for your language. In the special cases where one of the output list contains all 8 types, this list may optionally be replaced with a single item list containing everyone
.
Normal output will go to one of the normal places (STDOUT, function return, etc).
Other rules
- Standard loopholes are banned
- You may use whatever pre-existing 3rd party libraries you need, so long as they are not designed explicitly for this purpose.
Examples
- For input
AB-
, the two output lists would be:{AB+, AB-}, {AB-, A-, B-, O-}
- For input
AB+
, the two output lists would be:{AB+}, {O−, O+, A−, A+, B−, B+, AB−, AB+}
or{AB+}, {everyone}
Personal note: Please consider donating blood if you are able to. Without the transfusion I received a few years ago, I might not be here today, so I feel very grateful towards those who are able to donate!
@MartinBüttner Actually I will accept both. Most likely the 2nd form will yield shorter code in most languages, but perhaps there will be some special case where using the first form could be shorter. – Digital Trauma – 2015-03-19T19:14:07.943
3
Tangentially related - this brilliant answer http://worldbuilding.stackexchange.com/a/11203/2094
– Digital Trauma – 2015-03-19T19:19:26.727Half the answers so far are function-only answers. Please also consider this meta question: http://meta.codegolf.stackexchange.com/questions/4909/function-only-answers-to-function-or-program-questions-should-provide-a-test-pro
– Digital Trauma – 2015-03-19T21:30:09.3371That fact is not so little-known. – ceased to turn counterclockwis – 2015-03-21T09:28:00.837
1@leftaroundabout Thanks - A Bit of Fry and Laurie has always been a favourite of mine! – Digital Trauma – 2015-03-23T00:09:36.197
Does anyone know if this array
c=[9,15,12,8,153,255,204,136]
can be encoded as a unicode string? Such that I could iterate withord(c[i])
? – mbomb007 – 2015-04-01T17:00:00.487@mbomb007 See what the shell can give you
printf %02x 9 15 12 8 153 255 204 136 | xxd -p -r
. Also consider the hex representations of these numbers? Can you multiply by 17? – Digital Trauma – 2015-04-01T17:28:30.4501A picky vampire, eh? Dracula is turning in his casket. Also, the title sounds like the name of a retired goth-rock-band. – Renae Lider – 2015-06-19T20:11:28.790