Created
September 24, 2012 15:45
-
-
Save ochoto/3776616 to your computer and use it in GitHub Desktop.
Factorion
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
object factorion extends App { | |
lazy val N: Stream[Int] = Stream.cons(1, N.map(_ + 1)) | |
lazy val fact: Stream[Int] = Stream.cons(1, fact.zip(N).map(a => a._1 * a._2)) | |
val factmap = 0 to 9 map { a => a.toString -> fact(a) } toMap | |
def esFactorion(n: Int) = (n.toString.toList map (c => factmap.get(c.toString).get) sum) == n | |
val start = System.nanoTime | |
val factoriones = 1 to 2500000 filter ( esFactorion ) mkString(",") | |
println("Factoriones: " + factoriones) | |
val elapsed_ms = (System.nanoTime - start ) / 1000000 | |
//> elapsed_ms : Long = 1769 | |
println("Elapsed time: " + elapsed_ms + "ms") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment