Skip to content

Instantly share code, notes, and snippets.

@kalexander
Created May 4, 2015 12:15
Show Gist options
  • Save kalexander/d1c997e10a8141f1da53 to your computer and use it in GitHub Desktop.
Save kalexander/d1c997e10a8141f1da53 to your computer and use it in GitHub Desktop.
def happy(i: Long): Boolean = {
def lilHappy(ii: Long, count: Long = 0): Boolean = {
val num = ii.toString.map(_.asDigit).map(x => (x*x).toLong).sum
if(num == 1) true
else if( count == 30) false
else lilHappy(num, count + 1)
}
lilHappy(i)
}
(1 to 100).foreach{ x => println(x + " " + happy(x)) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment