src/hamming.clj

1
2
3
4
5
6
7
8
9
10
11
12
(ns hamming)

(defn distance [dna1 dna2]
  (cond
    ; Undefined for unequal length strings
    (not= (count dna1) (count dna2)) nil
    ; Both strings empty (Must be equal length to pass previous condition)
    (empty? dna1) 0
    :else (let
            [[nuc1 & rest1] dna1
             [nuc2 & rest2] dna2]
            (+ (if (= nuc1 nuc2) 0 1) (distance rest1 rest2)))))

Comments


You're not logged in right now. Please login via GitHub to comment