Skip to content

Instantly share code, notes, and snippets.

@paralax
Last active August 29, 2015 14:24
Show Gist options
  • Save paralax/be207e94c7f2b40f8422 to your computer and use it in GitHub Desktop.
Save paralax/be207e94c7f2b40f8422 to your computer and use it in GitHub Desktop.
[2015-07-13] Challenge #223 [Easy] Garland words
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