Last active
October 30, 2015 06:29
-
-
Save 5hanth/a21258c98c797db74c31 to your computer and use it in GitHub Desktop.
FLAMES
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn _do-flames [n fl] | |
(let [do-split (fn [n fl] | |
(let [[xs ys] (split-at n fl)] | |
(flatten | |
(conj (butlast xs) | |
ys)))) | |
c (count fl)] | |
(cond (= c 1) | |
(first fl) | |
(<= n c) | |
(_do-flames n (do-split n fl)) | |
:else (let [n-n (let [r (rem n c)] | |
(if (= r 0) n r)) | |
n-f (do-split n-n fl)] | |
(_do-flames n n-f))))) | |
(defn find-freq [n1 n2] | |
(let [lns (map clojure.string/lower-case [n1 n2]) | |
sns (map #(remove (fn [c] (= \space c)) %1) lns)] | |
(map frequencies sns))) | |
(defn flames-number [n1 n2] | |
(let [[m1 m2] (find-freq n1 n2)] | |
(reduce + (for [[k v] | |
(merge-with #(Math/abs (- % %2)) | |
m1 m2 ) | |
:when (not= 0 v)] v)))) | |
(defn do-flames [n1 n2] | |
(_do-flames (flames-number n1 n2) (map str "FLAMES"))) | |
; (do-flames "your-name" "your-crush-name") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment