Skip to content

Instantly share code, notes, and snippets.

@julienfantin
Created June 6, 2014 23:47
Show Gist options
  • Select an option

  • Save julienfantin/6f283d6f59ac1fdc7339 to your computer and use it in GitHub Desktop.

Select an option

Save julienfantin/6f283d6f59ac1fdc7339 to your computer and use it in GitHub Desktop.
Gotta love FP - Hamming distance in Java vs Clojure
(defn distance [a b]
(->> (map not= a b)
(filter true?)
count))
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