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.
I noticed several similar solutions with
every
, I preferred to use the fact of pairs explicitly