Created
August 22, 2010 17:21
-
-
Save rafaeldff/544019 to your computer and use it in GitHub Desktop.
This file contains 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:Int) = { | |
def sumOfSquares(n:Int) = n.toString.map(_ - '0').map(d=>d*d).sum | |
val numbers = Stream.iterate(i)(sumOfSquares) | |
def contents:Stream[Set[Int]] = Set[Int]() #:: (numbers zip contents).map{case (n, s) => s + n} | |
val stopNumber = (numbers zip contents) find {case (n,s) => n == 1 || s.contains(n)} | |
stopNumber match {case Some((1,_)) => "happy"; case _ => "sad"} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment