Created
May 30, 2010 01:57
-
-
Save jamescarr/418700 to your computer and use it in GitHub Desktop.
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
| 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