Medication contraindications
You probably know this, but here's some background so we're all on the same page. Some medicines shouldn't be taken in combination. When two medications shouldn't be taken together, it's called a contraindication.
(def patient-medications [{:name "Blythenal"
:rxNorm "blyth"}
{:name "Masbutol"
:rxNorm "masbut"}
{:name "Welbutril"
:rxNorm "welb"}])
(def contraindication-pairs [["nr913ng" "blyth"]
["masbut" "87f2h139049f"]
["nr913ng" "j1j81f0"]
["blyth" "welb"]
["masbut" "welb"]])
Your task is to take the list of medications a patient has and a list of contraindication pairs, and determine what pairs of medications (if any) they are prescribed that don't mix well.
;; complete this function
(defn contraindications [meds pairs]
It should return nil
if there are no contraindications and a collection of the contraindications (pairs) if there are any.
Bonus: Make it a linear algorithm (linear in the number of the patient medications and the number of the contraindication pairs).
Email submissions to eric@purelyfunctional.tv until June 8, 2020. You can discuss the submissions in the comments below.
In case it helps, here are some fixtures and tests for (most?) corner cases and additionally some using generated inputs - I am learning how to use test.check generators (please bear with my hacking). This is far away from properties based testing, but it can be used for benchmarking.
Below are tests using generated fixtures with up to a thousand meds, 10k contraindications and 500 conflicts, but you can create your own by changing the numbers.
Please let me know if I missed corner cases and I will add them...Thanks!