Skip to content

Instantly share code, notes, and snippets.

@jamescarr
Created May 30, 2010 01:57
Show Gist options
  • Save jamescarr/418700 to your computer and use it in GitHub Desktop.
Save jamescarr/418700 to your computer and use it in GitHub Desktop.
object isTriangleWord extends (String => Boolean){
override def apply(word:String) = {
val wordVal = wordValue(word)
var result = false
var i = 1
while(triangleNumberFor(i) <= wordVal){
if(triangleNumberFor(i) == wordVal){
result = true
}
i += 1
}
result
}
private def triangleNumberFor(n:Int):Int = (n*(n+1))/2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment