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 [email protected] until June 8, 2020. You can discuss the submissions in the comments below.
@miner, I submitted an almost identical solution, slightly shorter without the let, and using seq and set instead of intos. On the other hand I used "not-any? nil?" for the filter; your way is better. Combining best of both yields:
NB: I'd like to make a plea that we go back to waiting for Eric to publish submitted solutions, which is what he's asked for. IMO, solution synthesis and golf should wait until after we've seen the variety of approaches. (If I'm an outlier on this, I'll be quiet and accept the new norm..)