Last active
August 29, 2015 14:24
-
-
Save paralax/be207e94c7f2b40f8422 to your computer and use it in GitHub Desktop.
[2015-07-13] Challenge #223 [Easy] Garland words
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
| def garland(word:String): Int = { | |
| def loop(word:String, n:Int, sofar:Int): Int = { | |
| //println(word.slice(0, n)) | |
| if (n+1 == word.length) {return sofar} | |
| word.endsWith(word.slice(0,n)) match { | |
| case false => loop(word, n+1, sofar) | |
| case true => loop(word, n+1, n) | |
| } | |
| } | |
| loop(word, 1, 0) | |
| } | |
| def necklace(word:String, n:Int): String = word + word.slice(n, word.length)*3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment