Permalink
Browse files

update

  • Loading branch information...
1 parent 0c16287 commit c2ad27ffaad8ad8a471d94133a285bf26ccba60c @manicmaniac committed Aug 13, 2012
Showing with 4 additions and 7 deletions.
  1. +4 −7 scala/Problem74.scala
View
@@ -27,18 +27,15 @@ sixty non-repeating terms?
*/
object Problem74 {
- def factorial(n:Int) = 2 to n product
-
def digitFactorial(n:Int) = {
- n.toString.map(_.asDigit).map(factorial) sum
+ n.toString.map(_.asDigit).map(2 to _ product) sum
}
- def chain(n:Int, res:List[Int]=Nil):List[Int] = res.contains(n) match {
- case true => res
- case false => chain(digitFactorial(n), n :: res)
+ def chain(n:Int, res:List[Int]=Nil):List[Int] = {
+ if(res.contains(n)) res else chain(digitFactorial(n), n :: res)
}
def main(args:Array[String]) {
- print((1 to 1000000).map(chain(_, Nil).length).count(60==))
+ print((1 to 1000000).par.map(chain(_, Nil).length).count(60==))
}
}

0 comments on commit c2ad27f

Please sign in to comment.