Created
May 4, 2015 12:15
-
-
Save kalexander/d1c997e10a8141f1da53 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
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