Skip to content

Instantly share code, notes, and snippets.

@pjazdzewski1990
Created February 4, 2016 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjazdzewski1990/b495b335a22c527a7ae7 to your computer and use it in GitHub Desktop.
Save pjazdzewski1990/b495b335a22c527a7ae7 to your computer and use it in GitHub Desktop.
def scoreSimilarity(s1: String, s2: String): Double = {
val len = Math.min(s1.length, s2.length)
val sum: Double = (for {
i <- 0 until len
v = if(s1.charAt(i) == s2.charAt(i)) 1.0 else 0.0
} yield v).sum
Math.pow(sum, 2.0)/Math.pow(len, 2.0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment