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.
@ericnormand, Thanks for your comment! Indeed, I was assuming that meds being small that would be acceptable - but indeed, quadratic times makes for fast growth even on relatively small meds.
What do you think of the following? This won't exactly cut the linearity down, but could be a good speedup on large contraindications lists: