Created
June 6, 2014 23:47
-
-
Save julienfantin/6f283d6f59ac1fdc7339 to your computer and use it in GitHub Desktop.
Gotta love FP - Hamming distance in Java vs Clojure
This file contains hidden or 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 distance [a b] | |
| (->> (map not= a b) | |
| (filter true?) | |
| count)) |
This file contains hidden or 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
| public int distance(String s1, String s2) { | |
| int counter = 0; | |
| for (int k = 0; k < s1.length();k++) { | |
| if(s1.charAt(k) != s2.charAt(k)) { | |
| counter++; | |
| } | |
| } | |
| return counter; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment