Skip to content

Instantly share code, notes, and snippets.

@zerosum
Created February 19, 2013 11:32
Show Gist options
  • Select an option

  • Save zerosum/4985049 to your computer and use it in GitHub Desktop.

Select an option

Save zerosum/4985049 to your computer and use it in GitHub Desktop.
Project Euler: Problem 92
package euler.zerosum
import euler.zerosum.Number._
object Euler0092 {
def main(args: Array[String]) {
val n = from(0).take(1000)
println(
n
.par
.map(x => {
from(x*10000 + 1).take(10000).par.filterNot(terminateDigitChain(_) == 1).length
})
.sum)
}
def terminateDigitChain(s: Int): Int = {
val d = sumOfSquareDigit(s)
if (d == 1 || d == 85 || d == 58) d else terminateDigitChain(d)
}
def sumOfSquareDigit(n: Int): Int = {
println(n)
n.toString.toList.map(_.toInt - 48).fold(0)((sum, x) => sum + x * x)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment